From: amwaterhouse Date: Tue, 4 Apr 2006 09:37:12 +0000 (+0000) Subject: Pad gaps removes excess gaps X-Git-Tag: Release_2_08~76 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=50be9a6af05e540b996aa6de433fd0edfe9155d5;p=jalview.git Pad gaps removes excess gaps --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 00d1be8..b0b04ca 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -810,18 +810,41 @@ public class Alignment implements AlignmentI public boolean padGaps() { boolean modified=false; - int Width = getWidth(); + + //Remove excess gaps from the end of alignment + int maxLength = -1; + SequenceI current; + for (int i = 0; i < sequences.size(); i++) + { + current = getSequenceAt(i); + for (int j = current.getLength(); j > maxLength; j--) + { + if (j > maxLength && !jalview.util.Comparison.isGap( + current.getCharAt(j))) + { + maxLength = j; + break; + } + } + } + + maxLength++; + for (int i = 0; i < sequences.size(); i++) { current = getSequenceAt(i); - if (current.getLength() < Width) + if (current.getLength() < maxLength) { - current.insertCharAt(Width - 1, gapCharacter); + current.insertCharAt(maxLength - 1, gapCharacter); modified=true; } + else if(current.getLength() > maxLength) + { + current.deleteChars(maxLength, current.getLength()); + } } return modified; }