updated version to 2.6.1
[jalview.git] / src / jalview / io / AnnotationFile.java
index 01daf39..a96ff67 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.6.1)\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
@@ -417,7 +416,7 @@ public class AnnotationFile
       text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");\r
       text.append("displayText=" + sg.getDisplayText() + "\t");\r
       text.append("colourText=" + sg.getColourText() + "\t");\r
-      text.append("showUnconserved=" + sg.getShowunconserved() + "\t");\r
+      text.append("showUnconserved=" + sg.getShowNonconserved() + "\t");\r
       if (sg.textColour != java.awt.Color.black)\r
       {\r
         text.append("textCol1="\r
@@ -509,14 +508,16 @@ public class AnnotationFile
             if (aa[aai].autoCalculated)\r
             {\r
               // make a note of the name and description\r
-              autoAnnots.put(aa[aai].graph\r
-                      + "\t"\r
-                      + aa[aai].label\r
-                      + "\t"\r
-                      + aa[aai].description\r
-                      + "\t"\r
-                      + (aa[aai].sequenceRef != null ? aa[aai].sequenceRef\r
-                              .getDisplayId(true) : ""), new Integer(1));\r
+              autoAnnots\r
+                      .put(aa[aai].graph\r
+                              + "\t"\r
+                              + aa[aai].label\r
+                              + "\t"\r
+                              + aa[aai].description\r
+                              + "\t"\r
+                              + (aa[aai].sequenceRef != null ? aa[aai].sequenceRef\r
+                                      .getDisplayId(true) : ""),\r
+                              new Integer(1));\r
             }\r
           }\r
         }\r
@@ -801,10 +802,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 +838,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 +984,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
@@ -1111,9 +1123,7 @@ public class AnnotationFile
         }\r
         else\r
         {\r
-          sg\r
-                  .addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1),\r
-                          false);\r
+          sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1), false);\r
         }\r
       }\r
     }\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
@@ -1221,8 +1234,8 @@ public class AnnotationFile
         {\r
           sg.cs.setConservationInc(Integer.parseInt(value));\r
           Conservation c = new Conservation("Group",\r
-                  ResidueProperties.propHash, 3, sg.getSequences(null), sg\r
-                          .getStartRes(), sg.getEndRes() + 1);\r
+                  ResidueProperties.propHash, 3, sg.getSequences(null),\r
+                  sg.getStartRes(), sg.getEndRes() + 1);\r
 \r
           c.calculate();\r
           c.verdict(false, 25);\r
@@ -1240,7 +1253,7 @@ public class AnnotationFile
         }\r
         else if (key.equalsIgnoreCase("showUnconserved"))\r
         {\r
-          sg.setShowunconserved(Boolean.valueOf(value).booleanValue());\r
+          sg.setShowNonconserved(Boolean.valueOf(value).booleanValue());\r
         }\r
         else if (key.equalsIgnoreCase("displayText"))\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