From db7a726e4cf2c7d5f650085bd07b7f19254688e9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 23 May 2013 10:15:59 +0100 Subject: [PATCH] JAL-1299 fix: ensure a new graphGroup is created if first row identified in COMBINE statement doesn't have existing graphGroup assignment --- src/jalview/io/AnnotationFile.java | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index d15e7c5..3d42475 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -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; } } -- 1.7.10.2