use OOMwarning to warn user when out of Memory occurs
[jalview.git] / src / jalview / io / AnnotationFile.java
index d5039de..ddf4348 100755 (executable)
@@ -1,22 +1,21 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
+ * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * \r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
  * as published by the Free Software Foundation; either version 2\r
  * of the License, or (at your option) any later version.\r
- *\r
+ * \r
  * This program is distributed in the hope that it will be useful,\r
  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
  * GNU General Public License for more details.\r
- *\r
+ * \r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
  */\r
-\r
 package jalview.io;\r
 \r
 import java.io.*;\r
@@ -190,7 +189,7 @@ public class AnnotationFile
               }\r
 \r
               color = row.annotations[j].colour;\r
-              if (row.annotations[j].value != 0f)\r
+              if (row.annotations[j].value != 0f && row.annotations[j].value!=Float.NaN) \r
               {\r
                 text.append(comma + row.annotations[j].value);\r
               }\r
@@ -323,6 +322,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 +420,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 +441,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 +547,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
@@ -886,6 +906,7 @@ public class AnnotationFile
         }\r
         else if (key.equalsIgnoreCase("idColour"))\r
         {\r
+          // consider warning if colour doesn't resolve to a real colour\r
           sg.setIdColour((def = new UserColourScheme(value)).findColour('A'));\r
         }\r
         sg.recalcConservation();\r