JAL-1299 fix: ensure a new graphGroup is created if first row identified in COMBINE...
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Thu, 23 May 2013 09:15:59 +0000 (10:15 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Fri, 24 May 2013 14:10:55 +0000 (15:10 +0100)
src/jalview/io/AnnotationFile.java

index d15e7c5..3d42475 100755 (executable)
@@ -594,6 +594,10 @@ public class AnnotationFile
           throws Exception
   {
     nlinesread = 0;
+    /**
+     * number of combine statements in this annotation file. Used to create new groups for combined annotation graphs without disturbing existing ones
+     */
+    int combinecount = 0;
     boolean modified = false;
     String groupRef = null;
     Hashtable groupRefRows = new Hashtable();
@@ -679,7 +683,7 @@ public class AnnotationFile
 
         else if (token.equalsIgnoreCase("COMBINE"))
         {
-          combineAnnotations(al, st);
+          combineAnnotations(al, combinecount++, st);
           modified = true;
           continue;
         }
@@ -1088,19 +1092,33 @@ public class AnnotationFile
     }
   }
 
-  void combineAnnotations(AlignmentI al, StringTokenizer st)
+  void combineAnnotations(AlignmentI al, int combineCount, StringTokenizer st)
   {
-    int graphGroup = -1;
     String group = st.nextToken();
     // First make sure we are not overwriting the graphIndex
+    int graphGroup=0;
     if (al.getAlignmentAnnotation() != null)
     {
       for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
       {
-        if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
+        AlignmentAnnotation aa = al.getAlignmentAnnotation()[i];
+        if (aa.graphGroup>graphGroup)
         {
-          graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;
-          al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
+          // try to number graphGroups in order of occurence.
+          graphGroup=aa.graphGroup;
+        }
+        if (aa.label.equalsIgnoreCase(group))
+        {
+          if (aa.graphGroup>-1)
+          {
+            graphGroup = aa.graphGroup;
+          } else {
+            if (graphGroup >= combineCount)
+            {
+              graphGroup++;
+            }
+            aa.graphGroup = graphGroup;
+          }
           break;
         }
       }