Pad gaps removes excess gaps
authoramwaterhouse <Andrew Waterhouse>
Tue, 4 Apr 2006 09:37:12 +0000 (09:37 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 4 Apr 2006 09:37:12 +0000 (09:37 +0000)
src/jalview/datamodel/Alignment.java

index 00d1be8..b0b04ca 100755 (executable)
@@ -810,18 +810,41 @@ public class Alignment implements AlignmentI
 \r
     public boolean padGaps() {\r
       boolean modified=false;\r
-      int Width = getWidth();\r
+\r
+      //Remove excess gaps from the end of alignment\r
+      int maxLength = -1;\r
+\r
       SequenceI current;\r
+      for (int i = 0; i < sequences.size(); i++)\r
+      {\r
+        current = getSequenceAt(i);\r
+        for (int j = current.getLength(); j > maxLength; j--)\r
+        {\r
+          if (j > maxLength && !jalview.util.Comparison.isGap(\r
+              current.getCharAt(j)))\r
+          {\r
+            maxLength = j;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+\r
+      maxLength++;\r
+\r
       for (int i = 0; i < sequences.size();\r
            i++)\r
       {\r
         current = getSequenceAt(i);\r
 \r
-        if (current.getLength() < Width)\r
+        if (current.getLength() < maxLength)\r
         {\r
-          current.insertCharAt(Width - 1, gapCharacter);\r
+          current.insertCharAt(maxLength - 1, gapCharacter);\r
           modified=true;\r
         }\r
+        else if(current.getLength() > maxLength)\r
+        {\r
+          current.deleteChars(maxLength, current.getLength());\r
+        }\r
       }\r
       return modified;\r
     }\r