Annotation adjustment moved to EditCommand
authoramwaterhouse <Andrew Waterhouse>
Thu, 25 Jan 2007 18:45:46 +0000 (18:45 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 25 Jan 2007 18:45:46 +0000 (18:45 +0000)
src/jalview/commands/EditCommand.java
src/jalview/commands/RemoveGapColCommand.java
src/jalview/commands/RemoveGapsCommand.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/datamodel/AlignmentI.java

index c1b4daf..ed356dc 100644 (file)
@@ -20,6 +20,8 @@ package jalview.commands;
 \r
 import jalview.datamodel.*;\r
 \r
+import java.util.Hashtable;\r
+\r
 /**\r
  *\r
  * <p>Title: EditCommmand</p>\r
@@ -91,10 +93,15 @@ public class EditCommand implements CommandI
                          SequenceI[] seqs,\r
                          int position,\r
                          int number,\r
-                         char gapChar,\r
+                         AlignmentI al,\r
                          boolean performEdit)\r
   {\r
-    Edit edit = new Edit(command, seqs, position, number, gapChar);\r
+    Edit edit = new Edit(command, seqs, position, number, al.getGapCharacter());\r
+    if(al.getHeight()==seqs.length)\r
+    {\r
+      edit.al = al;\r
+      edit.fullAlignmentHeight = true;\r
+    }\r
 \r
     if (edits != null)\r
     {\r
@@ -171,6 +178,11 @@ public class EditCommand implements CommandI
                                      command.number,\r
                                      command.gapChar);\r
     }\r
+\r
+    if (command.fullAlignmentHeight)\r
+    {\r
+      adjustAnnotations(command, true);\r
+    }\r
   }\r
 \r
   void deleteGap(Edit command)\r
@@ -179,6 +191,11 @@ public class EditCommand implements CommandI
     {\r
       command.seqs[s].deleteChars(command.position, command.position+command.number);\r
     }\r
+\r
+    if (command.fullAlignmentHeight)\r
+    {\r
+      adjustAnnotations(command, false);\r
+    }\r
   }\r
 \r
   void cut(Edit command)\r
@@ -200,9 +217,13 @@ public class EditCommand implements CommandI
       {\r
         command.al.deleteSequence(command.seqs[i]);\r
       }\r
+    }\r
 \r
-\r
+    if (command.fullAlignmentHeight)\r
+    {\r
+      adjustAnnotations(command, false);\r
     }\r
+\r
   }\r
 \r
   void paste(Edit command)\r
@@ -240,16 +261,99 @@ public class EditCommand implements CommandI
         command.string[i] = null;\r
       }\r
       command.seqs[i].setSequence(tmp.toString());\r
+    }\r
 \r
-\r
-\r
+    if (command.fullAlignmentHeight)\r
+    {\r
+      adjustAnnotations(command, true);\r
     }\r
 \r
     command.string = null;\r
   }\r
 \r
+\r
+  void adjustAnnotations(Edit command, boolean insert)\r
+  {\r
+    AlignmentAnnotation [] annotations = command.al.getAlignmentAnnotation();\r
+    if(annotations!=null)\r
+    {\r
+      if(!insert)\r
+        command.deletedAnnotations = new Hashtable();\r
+\r
+      int aSize, tSize;\r
+      Annotation [] temp;\r
+      for (int a = 0; a < annotations.length; a++)\r
+      {\r
+        if(annotations[a].autoCalculated)\r
+        {\r
+          continue;\r
+        }\r
+\r
+        aSize = annotations[a].annotations.length;\r
+        if(insert)\r
+          tSize = aSize + command.number;\r
+        else\r
+          tSize = aSize - command.number;\r
+\r
+        temp = new Annotation[tSize];\r
+\r
+        if(insert)\r
+        {\r
+          System.arraycopy(annotations[a].annotations,\r
+              0, temp, 0, command.position);\r
+\r
+          if(command.deletedAnnotations!=null\r
+             && command.deletedAnnotations.containsKey(annotations[a].annotationId))\r
+          {\r
+            Annotation [] restore = (Annotation [])\r
+                command.deletedAnnotations.get(annotations[a].annotationId);\r
+\r
+            System.arraycopy(restore,\r
+                             0,\r
+                             temp,\r
+                             command.position,\r
+                             command.number);\r
+\r
+          }\r
+\r
+          System.arraycopy(annotations[a].annotations,\r
+              command.position, temp,\r
+              command.position+command.number,\r
+              aSize - command.position);\r
+        }\r
+        else\r
+        {\r
+          if(command.position < annotations[a].annotations.length)\r
+          {\r
+            System.arraycopy(annotations[a].annotations,\r
+                             0, temp, 0, command.position);\r
+\r
+            Annotation[] deleted = new Annotation[command.number];\r
+            System.arraycopy(annotations[a].annotations,\r
+                             command.position, deleted, 0, command.number);\r
+\r
+            command.deletedAnnotations.put(annotations[a].annotationId,\r
+                                           deleted);\r
+\r
+            System.arraycopy(annotations[a].annotations,\r
+                             command.position + command.number,\r
+                             temp, command.position,\r
+                             aSize - command.position - command.number);\r
+          }\r
+          else\r
+            temp = annotations[a].annotations;\r
+        }\r
+\r
+        annotations[a].annotations = temp;\r
+     }\r
+    }\r
+  }\r
+\r
+\r
   class Edit\r
   {\r
+    boolean fullAlignmentHeight = false;\r
+    Hashtable deletedAnnotations;\r
     AlignmentI al;\r
     int command;\r
     char [][] string;\r
@@ -288,6 +392,9 @@ public class EditCommand implements CommandI
       alIndex = new int[seqs.length];\r
       for(int i=0; i<seqs.length; i++)\r
         alIndex[i] = al.findIndex(seqs[i]);\r
+\r
+      fullAlignmentHeight = (al.getHeight()==seqs.length);\r
+\r
     }\r
 \r
   }\r
index 2c3aced..d3aebdb 100644 (file)
@@ -25,7 +25,7 @@ public class RemoveGapColCommand  extends EditCommand
   int columnsDeleted;\r
   public RemoveGapColCommand(String description,\r
                              SequenceI[] seqs,\r
-                             int start, int end, char gapChar)\r
+                             int start, int end, AlignmentI al)\r
   {\r
     this.description = description;\r
 \r
@@ -66,7 +66,7 @@ public class RemoveGapColCommand  extends EditCommand
         this.appendEdit(DELETE_GAP, seqs,\r
                         startCol - columnsDeleted,\r
                         endCol - startCol,\r
-                        gapChar,\r
+                        al,\r
                         false);\r
 \r
         columnsDeleted += (endCol - startCol);\r
@@ -83,7 +83,7 @@ public class RemoveGapColCommand  extends EditCommand
       this.appendEdit(DELETE_GAP, seqs,\r
                         startCol - columnsDeleted,\r
                         end - startCol +1,\r
-                        gapChar,\r
+                        al,\r
                         false);\r
 \r
       columnsDeleted += (end - startCol +1);\r
index ba39381..f6413a7 100644 (file)
@@ -23,7 +23,7 @@ import jalview.datamodel.*;
 public class RemoveGapsCommand  extends EditCommand\r
 {\r
   public RemoveGapsCommand(  String description,\r
-                             SequenceI[] seqs, char gapChar)\r
+                             SequenceI[] seqs, AlignmentI al)\r
   {\r
     this.description = description;\r
     int width = 0;\r
@@ -31,18 +31,18 @@ public class RemoveGapsCommand  extends EditCommand
       if(seqs[i].getLength()>width)\r
         width = seqs[i].getLength();\r
 \r
-    findGaps(seqs, 0, width, gapChar);\r
+    findGaps(seqs, 0, width, al);\r
   }\r
 \r
   public RemoveGapsCommand(  String description,\r
                              SequenceI[] seqs,\r
-                             int start, int end, char gapChar)\r
+                             int start, int end, AlignmentI al)\r
   {\r
     this.description = description;\r
-    findGaps(seqs, start, end, gapChar);\r
+    findGaps(seqs, start, end, al);\r
   }\r
 \r
-  void findGaps(SequenceI [] seqs, int start, int end, char gapChar)\r
+  void findGaps(SequenceI [] seqs, int start, int end, AlignmentI al)\r
   {\r
 \r
     int startCol = -1, endCol = -1;\r
@@ -87,7 +87,7 @@ public class RemoveGapsCommand  extends EditCommand
           this.appendEdit(DELETE_GAP, new SequenceI[]{seqs[s]},\r
                           start + startCol - deletedCols,\r
                           endCol - startCol,\r
-                          gapChar,\r
+                          al,\r
                           false);\r
 \r
           deletedCols += (endCol - startCol);\r
@@ -100,7 +100,7 @@ public class RemoveGapsCommand  extends EditCommand
         this.appendEdit(DELETE_GAP, new SequenceI[]{seqs[s]},\r
                         start + startCol - deletedCols,\r
                         jSize - startCol,\r
-                        gapChar,\r
+                        al,\r
                         false);\r
       }\r
 \r
index f255ab5..2ad0588 100755 (executable)
@@ -470,58 +470,6 @@ public class Alignment implements AlignmentI
     }
 
 
-    public void adjustSequenceAnnotations(int position,
-                                          int number,
-                                          boolean insert)
-    {
-      if(annotations!=null)
-      {
-        int aSize, tSize;
-        Annotation [] temp;
-        for (int a = 0; a < annotations.length; a++)
-        {
-          if(annotations[a].autoCalculated)
-          {
-            System.out.println("ignore "+annotations[a].label);
-            continue;
-          }
-          aSize = annotations[a].annotations.length;
-          if(insert)
-            tSize = aSize + number;
-          else
-            tSize = aSize - number;
-
-          temp = new Annotation[tSize];
-
-          if(insert)
-          {
-            System.arraycopy(annotations[a].annotations,
-                0, temp, 0, position);
-
-            System.arraycopy(annotations[a].annotations,
-                position, temp, position+number, aSize - position);
-          }
-          else
-          {
-              System.arraycopy(annotations[a].annotations,
-                               0, temp, 0, position);
-
-              System.arraycopy(annotations[a].annotations,
-                               position + number, temp, position,
-                               aSize - position - number);
-          }
-
-          annotations[a].annotations = temp;
-
-
-        //  if (annotations[a].sequenceRef != null)
-          {
-        //    annotations[a].adjustForAlignment();
-          }
-        }
-      }
-    }
-
     /**
      * DOCUMENT ME!
      *
index 4a3cad6..6803e9f 100755 (executable)
@@ -31,6 +31,8 @@ public class AlignmentAnnotation
    * eg consensus, quality or conservation graphs */
   public boolean autoCalculated = false;
 
+  public String annotationId = Math.random() +"";
+
     public SequenceI sequenceRef;
 
     /** DOCUMENT ME!! */
index bf1614b..baaebc2 100755 (executable)
@@ -228,10 +228,6 @@ public interface AlignmentI
      */
     public boolean padGaps();
 
-    public void adjustSequenceAnnotations(int position,
-                                          int number,
-                                          boolean insert);
-
 
     public HiddenSequences getHiddenSequences();
     /**