patch and error reports re JAL-554
[jalview.git] / src / jalview / io / AnnotationFile.java
index 01daf39..2721fb2 100755 (executable)
@@ -1,20 +1,19 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)\r
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)\r
+ * Copyright (C) 2010 J Procter, AM Waterhouse, 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
+ * This file is part of Jalview.\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
+ * Jalview 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 3 of the License, or (at your option) any later version.\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
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 package jalview.io;\r
 \r
@@ -801,10 +800,11 @@ public class AnnotationFile
           {\r
             if (matched)\r
             {\r
-              // TODO: specify and implement duplication of alignment annotation for multiple group references.\r
+              // TODO: specify and implement duplication of alignment annotation\r
+              // for multiple group references.\r
               System.err\r
                       .println("Ignoring 1:many group reference mappings for group name '"\r
-                              + groupRef+"'");\r
+                              + groupRef + "'");\r
             }\r
             else\r
             {\r
@@ -836,14 +836,14 @@ public class AnnotationFile
   Annotation parseAnnotation(String string, int graphStyle)\r
   {\r
     boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't\r
-                                                                       // do the\r
-                                                                       // glyph\r
-                                                                       // test\r
-                                                                       // if we\r
-                                                                       // don't\r
-                                                                       // want\r
-                                                                       // secondary\r
-                                                                       // structure\r
+    // do the\r
+    // glyph\r
+    // test\r
+    // if we\r
+    // don't\r
+    // want\r
+    // secondary\r
+    // structure\r
     String desc = null, displayChar = null;\r
     char ss = ' '; // secondaryStructure\r
     float value = 0;\r
@@ -982,45 +982,55 @@ public class AnnotationFile
     int graphGroup = -1;\r
     String group = st.nextToken();\r
     // First make sure we are not overwriting the graphIndex\r
-    for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
+    if (al.getAlignmentAnnotation() != null)\r
     {\r
-      if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
-      {\r
-        graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;\r
-        al.getAlignmentAnnotation()[i].graphGroup = graphGroup;\r
-        break;\r
-      }\r
-    }\r
-\r
-    // Now update groups\r
-    while (st.hasMoreTokens())\r
-    {\r
-      group = st.nextToken();\r
       for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
       {\r
         if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
         {\r
+          graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;\r
           al.getAlignmentAnnotation()[i].graphGroup = graphGroup;\r
           break;\r
         }\r
       }\r
+\r
+      // Now update groups\r
+      while (st.hasMoreTokens())\r
+      {\r
+        group = st.nextToken();\r
+        for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
+        {\r
+          if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
+          {\r
+            al.getAlignmentAnnotation()[i].graphGroup = graphGroup;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+    }\r
+    else\r
+    {\r
+      System.err\r
+              .println("Couldn't combine annotations. None are added to alignment yet!");\r
     }\r
   }\r
 \r
   void addLine(AlignmentI al, StringTokenizer st)\r
   {\r
     String group = st.nextToken();\r
-    AlignmentAnnotation annotation = null;\r
-\r
-    for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
+    AlignmentAnnotation annotation = null, alannot[] = al\r
+            .getAlignmentAnnotation();\r
+    if (alannot != null)\r
     {\r
-      if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
+      for (int i = 0; i < alannot.length; i++)\r
       {\r
-        annotation = al.getAlignmentAnnotation()[i];\r
-        break;\r
+        if (alannot[i].label.equalsIgnoreCase(group))\r
+        {\r
+          annotation = alannot[i];\r
+          break;\r
+        }\r
       }\r
     }\r
-\r
     if (annotation == null)\r
     {\r
       return;\r
@@ -1153,13 +1163,16 @@ public class AnnotationFile
         centerlab = Boolean.valueOf(value).booleanValue();\r
       }\r
       AlignmentAnnotation[] alr = al.getAlignmentAnnotation();\r
-      for (int i = 0; i < alr.length; i++)\r
+      if (alr != null)\r
       {\r
-        if (alr[i].label.equalsIgnoreCase(label))\r
+        for (int i = 0; i < alr.length; i++)\r
         {\r
-          alr[i].centreColLabels = centerlab;\r
-          alr[i].scaleColLabel = scaletofit;\r
-          alr[i].showAllColLabels = showalllabs;\r
+          if (alr[i].label.equalsIgnoreCase(label))\r
+          {\r
+            alr[i].centreColLabels = centerlab;\r
+            alr[i].scaleColLabel = scaletofit;\r
+            alr[i].showAllColLabels = showalllabs;\r
+          }\r
         }\r
       }\r
     }\r
@@ -1290,19 +1303,35 @@ public class AnnotationFile
   void setBelowAlignment(AlignmentI al, StringTokenizer st)\r
   {\r
     String token;\r
-    AlignmentAnnotation aa;\r
+    AlignmentAnnotation aa, ala[] = al.getAlignmentAnnotation();\r
+    if (ala == null)\r
+    {\r
+      System.err\r
+              .print("Warning - no annotation to set below for sequence associated annotation:");\r
+    }\r
     while (st.hasMoreTokens())\r
     {\r
       token = st.nextToken();\r
-      for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
+      if (ala == null)\r
+      {\r
+        System.err.print(" "+token);\r
+      }\r
+      else\r
       {\r
-        aa = al.getAlignmentAnnotation()[i];\r
-        if (aa.sequenceRef == refSeq && aa.label.equals(token))\r
+        for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
         {\r
-          aa.belowAlignment = true;\r
+          aa = al.getAlignmentAnnotation()[i];\r
+          if (aa.sequenceRef == refSeq && aa.label.equals(token))\r
+          {\r
+            aa.belowAlignment = true;\r
+          }\r
         }\r
       }\r
     }\r
+    if (ala==null)\r
+    {\r
+      System.err.print("\n");\r
+    }\r
   }\r
 \r
   void addAlignmentDetails(AlignmentI al, StringTokenizer st)\r