Adjusts annotations for sequence edits
authoramwaterhouse <Andrew Waterhouse>
Fri, 26 Jan 2007 17:30:23 +0000 (17:30 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 26 Jan 2007 17:30:23 +0000 (17:30 +0000)
src/jalview/commands/EditCommand.java

index ed356dc..0c833d0 100644 (file)
@@ -179,10 +179,7 @@ public class EditCommand implements CommandI
                                      command.gapChar);\r
     }\r
 \r
                                      command.gapChar);\r
     }\r
 \r
-    if (command.fullAlignmentHeight)\r
-    {\r
-      adjustAnnotations(command, true);\r
-    }\r
+    adjustAnnotations(command, true);\r
   }\r
 \r
   void deleteGap(Edit command)\r
   }\r
 \r
   void deleteGap(Edit command)\r
@@ -192,10 +189,7 @@ public class EditCommand implements CommandI
       command.seqs[s].deleteChars(command.position, command.position+command.number);\r
     }\r
 \r
       command.seqs[s].deleteChars(command.position, command.position+command.number);\r
     }\r
 \r
-    if (command.fullAlignmentHeight)\r
-    {\r
-      adjustAnnotations(command, false);\r
-    }\r
+    adjustAnnotations(command, false);\r
   }\r
 \r
   void cut(Edit command)\r
   }\r
 \r
   void cut(Edit command)\r
@@ -219,11 +213,7 @@ public class EditCommand implements CommandI
       }\r
     }\r
 \r
       }\r
     }\r
 \r
-    if (command.fullAlignmentHeight)\r
-    {\r
-      adjustAnnotations(command, false);\r
-    }\r
-\r
+    adjustAnnotations(command, false);\r
   }\r
 \r
   void paste(Edit command)\r
   }\r
 \r
   void paste(Edit command)\r
@@ -263,10 +253,8 @@ public class EditCommand implements CommandI
       command.seqs[i].setSequence(tmp.toString());\r
     }\r
 \r
       command.seqs[i].setSequence(tmp.toString());\r
     }\r
 \r
-    if (command.fullAlignmentHeight)\r
-    {\r
-      adjustAnnotations(command, true);\r
-    }\r
+\r
+    adjustAnnotations(command, true);\r
 \r
     command.string = null;\r
   }\r
 \r
     command.string = null;\r
   }\r
@@ -274,9 +262,46 @@ public class EditCommand implements CommandI
 \r
   void adjustAnnotations(Edit command, boolean insert)\r
   {\r
 \r
   void adjustAnnotations(Edit command, boolean insert)\r
   {\r
-    AlignmentAnnotation [] annotations = command.al.getAlignmentAnnotation();\r
-    if(annotations!=null)\r
+\r
+    AlignmentAnnotation [] annotations = null;\r
+\r
+    if (command.fullAlignmentHeight)\r
+    {\r
+      annotations = command.al.getAlignmentAnnotation();\r
+    }\r
+    else\r
     {\r
     {\r
+      int aSize = 0;\r
+      AlignmentAnnotation [] tmp;\r
+      for(int s=0; s<command.seqs.length; s++)\r
+      {\r
+        if(command.seqs[s].getAnnotation()==null)\r
+          continue;\r
+\r
+        if (aSize == 0)\r
+            annotations = command.seqs[s].getAnnotation();\r
+        else\r
+        {\r
+          tmp = new AlignmentAnnotation\r
+              [aSize + command.seqs[s].getAnnotation().length];\r
+\r
+          System.arraycopy(annotations,0,tmp,0,aSize);\r
+\r
+          System.arraycopy(command.seqs[s].getAnnotation(),\r
+              0,tmp,aSize,command.seqs[s].getAnnotation().length);\r
+\r
+          annotations = tmp;\r
+        }\r
+\r
+\r
+        aSize = annotations.length;\r
+      }\r
+    }\r
+\r
+    if(annotations==null)\r
+      return;\r
+\r
+\r
       if(!insert)\r
         command.deletedAnnotations = new Hashtable();\r
 \r
       if(!insert)\r
         command.deletedAnnotations = new Hashtable();\r
 \r
@@ -299,27 +324,33 @@ public class EditCommand implements CommandI
 \r
         if(insert)\r
         {\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
+          if(command.position < annotations[a].annotations.length)\r
           {\r
           {\r
-            Annotation [] restore = (Annotation [])\r
-                command.deletedAnnotations.get(annotations[a].annotationId);\r
+            System.arraycopy(annotations[a].annotations,\r
+                             0, temp, 0, command.position);\r
 \r
 \r
-            System.arraycopy(restore,\r
-                             0,\r
-                             temp,\r
-                             command.position,\r
-                             command.number);\r
+            if (command.deletedAnnotations != null\r
+                &&\r
+                command.deletedAnnotations.containsKey(annotations[a].annotationId))\r
+            {\r
+              Annotation[] restore = (Annotation[])\r
+                  command.deletedAnnotations.get(annotations[a].annotationId);\r
 \r
 \r
-          }\r
+              System.arraycopy(restore,\r
+                               0,\r
+                               temp,\r
+                               command.position,\r
+                               command.number);\r
 \r
 \r
-          System.arraycopy(annotations[a].annotations,\r
-              command.position, temp,\r
-              command.position+command.number,\r
-              aSize - command.position);\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
+            temp = annotations[a].annotations;\r
         }\r
         else\r
         {\r
         }\r
         else\r
         {\r
@@ -346,7 +377,6 @@ public class EditCommand implements CommandI
 \r
         annotations[a].annotations = temp;\r
      }\r
 \r
         annotations[a].annotations = temp;\r
      }\r
-    }\r
   }\r
 \r
 \r
   }\r
 \r
 \r
@@ -391,12 +421,12 @@ public class EditCommand implements CommandI
 \r
       alIndex = new int[seqs.length];\r
       for(int i=0; i<seqs.length; i++)\r
 \r
       alIndex = new int[seqs.length];\r
       for(int i=0; i<seqs.length; i++)\r
+      {\r
         alIndex[i] = al.findIndex(seqs[i]);\r
         alIndex[i] = al.findIndex(seqs[i]);\r
+      }\r
 \r
       fullAlignmentHeight = (al.getHeight()==seqs.length);\r
 \r
       fullAlignmentHeight = (al.getHeight()==seqs.length);\r
-\r
     }\r
     }\r
-\r
   }\r
 \r
 }\r
   }\r
 \r
 }\r