Returns number of columns deleted
authoramwaterhouse <Andrew Waterhouse>
Thu, 26 Oct 2006 13:09:20 +0000 (13:09 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 26 Oct 2006 13:09:20 +0000 (13:09 +0000)
src/jalview/commands/RemoveGapColCommand.java
src/jalview/commands/TrimRegionCommand.java

index 5bf5b61..2c3aced 100644 (file)
@@ -22,6 +22,7 @@ import jalview.datamodel.*;
 \r
 public class RemoveGapColCommand  extends EditCommand\r
 {\r
+  int columnsDeleted;\r
   public RemoveGapColCommand(String description,\r
                              SequenceI[] seqs,\r
                              int start, int end, char gapChar)\r
@@ -31,12 +32,12 @@ public class RemoveGapColCommand  extends EditCommand
     int j, jSize = seqs.length;\r
 \r
     int startCol = -1, endCol = -1;\r
-    int deletedCols = 0;\r
+    columnsDeleted=0;\r
 \r
     edits = new Edit[0];\r
 \r
     boolean delete = true;\r
-    for (int i = start; i < end; i++)\r
+    for (int i = start; i <= end; i++)\r
     {\r
       delete = true;\r
 \r
@@ -63,12 +64,12 @@ public class RemoveGapColCommand  extends EditCommand
       if (!delete && startCol > -1)\r
       {\r
         this.appendEdit(DELETE_GAP, seqs,\r
-                        startCol - deletedCols,\r
+                        startCol - columnsDeleted,\r
                         endCol - startCol,\r
                         gapChar,\r
                         false);\r
 \r
-        deletedCols += (endCol - startCol);\r
+        columnsDeleted += (endCol - startCol);\r
         startCol = -1;\r
         endCol = -1;\r
       }\r
@@ -78,14 +79,25 @@ public class RemoveGapColCommand  extends EditCommand
     {\r
        //This is for empty columns at the\r
        //end of the alignment\r
+\r
       this.appendEdit(DELETE_GAP, seqs,\r
-                        startCol - deletedCols,\r
-                        end-startCol+1,\r
+                        startCol - columnsDeleted,\r
+                        end - startCol +1,\r
                         gapChar,\r
                         false);\r
+\r
+      columnsDeleted += (end - startCol +1);\r
     }\r
 \r
+\r
     performEdit(0);\r
   }\r
 \r
+  public int getSize()\r
+  {\r
+    //We're interested in the number of columns deleted,\r
+    //Not the number of sequence edits.\r
+    return columnsDeleted;\r
+  }\r
+\r
 }\r
index 5a5dcd1..8166ed6 100644 (file)
@@ -38,6 +38,8 @@ public class TrimRegionCommand
 \r
   Vector deletedHiddenColumns;\r
 \r
+  int columnsDeleted;\r
+\r
   public TrimRegionCommand(String description,\r
                      String command,\r
                      SequenceI[] seqs,\r
@@ -51,12 +53,25 @@ public class TrimRegionCommand
     this.colSel = colSel;\r
     if (command.equalsIgnoreCase(TRIM_LEFT))\r
     {\r
+      if(column==0)\r
+        return;\r
+\r
+      columnsDeleted = column;\r
+\r
       edits = new Edit[] { new Edit(CUT, seqs, 0, column, al)};\r
     }\r
     else if (command.equalsIgnoreCase(TRIM_RIGHT))\r
     {\r
+      int width = al.getWidth()-column;\r
+      if(width<2)\r
+      {\r
+        return;\r
+      }\r
+\r
+      columnsDeleted = width-1;\r
+\r
       edits = new Edit[]\r
-          { new Edit(CUT, seqs, column+1, al.getWidth() - column, al)};\r
+          { new Edit(CUT, seqs, column+1, width, al)};\r
     }\r
 \r
     //We need to keep a record of the sequence start\r
@@ -138,8 +153,11 @@ public class TrimRegionCommand
         colSel.hideColumns(region[0], region[1]);\r
       }\r
     }\r
+  }\r
 \r
-\r
+  public int getSize()\r
+  {\r
+    return columnsDeleted;\r
   }\r
 \r
 }\r