resolve 1:many mappings for sequence associated annotation to all alignment sequence...
authorjprocter <Jim Procter>
Fri, 18 Jul 2008 15:10:29 +0000 (15:10 +0000)
committerjprocter <Jim Procter>
Fri, 18 Jul 2008 15:10:29 +0000 (15:10 +0000)
src/jalview/io/AnnotationFile.java

index 016ee8f..13cfc38 100755 (executable)
@@ -323,6 +323,7 @@ public class AnnotationFile
   }\r
 \r
   SequenceI refSeq = null;\r
+  String refSeqId = null;\r
   public boolean readAnnotationFile(AlignmentI al,\r
                                     String file,\r
                                     String protocol)\r
@@ -420,7 +421,13 @@ public class AnnotationFile
 \r
         else if (token.equalsIgnoreCase("SEQUENCE_REF"))\r
         {\r
-          refSeq = al.findName(st.nextToken());\r
+          if (st.hasMoreTokens())\r
+          {\r
+            refSeq = al.findName(refSeqId=st.nextToken());\r
+          if (refSeq==null)\r
+          {\r
+            refSeqId=null;\r
+          }\r
           try\r
           {\r
             refSeqIndex = Integer.parseInt(st.nextToken());\r
@@ -435,7 +442,10 @@ public class AnnotationFile
           {\r
             refSeqIndex = 1;\r
           }\r
-\r
+          } else {\r
+            refSeq = null;\r
+            refSeqId = null;\r
+          }\r
           continue ;\r
         }\r
 \r
@@ -538,16 +548,27 @@ public class AnnotationFile
         if (refSeq != null)\r
         {\r
           annotation.belowAlignment=false;\r
-          annotation.createSequenceMapping(refSeq, refSeqIndex, false);\r
-          annotation.adjustForAlignment();\r
-          refSeq.addAlignmentAnnotation(annotation);\r
-        }\r
-\r
-        al.addAnnotation(annotation);\r
-\r
-        al.setAnnotationIndex(annotation,\r
+          do {\r
+            // copy before we do any mapping business.\r
+            // TODO: verify that undo/redo with 1:many sequence associated annotations can be undone correctly\r
+            AlignmentAnnotation ann = new AlignmentAnnotation(annotation);\r
+            annotation.createSequenceMapping(refSeq, refSeqIndex, false);\r
+            annotation.adjustForAlignment();\r
+            refSeq.addAlignmentAnnotation(annotation);\r
+            al.addAnnotation(annotation);\r
+            al.setAnnotationIndex(annotation,\r
+                                al.getAlignmentAnnotation().length - existingAnnotations -\r
+                                1);\r
+            // and recover our virgin copy to use again if necessary.\r
+            annotation = ann;\r
+            \r
+          } while (refSeqId!=null && (refSeq=al.findName(refSeq, refSeqId, true))!=null);\r
+        } else {\r
+          al.addAnnotation(annotation);\r
+          al.setAnnotationIndex(annotation,\r
                               al.getAlignmentAnnotation().length - existingAnnotations -\r
                               1);\r
+        }\r
       }\r
 \r
     }\r