From 812faf2c9f5974e29d27292946fd9e427dcae023 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 21 Jun 2013 13:59:35 +0100 Subject: [PATCH 1/1] JAL-1325 JAL-1294 resolve SEQUENCE_REF and GROUP_REF for GRAPHLINE statements --- src/jalview/io/AnnotationFile.java | 50 +++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index bd536f3..4abd768 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -624,11 +624,13 @@ public class AnnotationFile } long nlinesread=0; String lastread=""; + private static String GRAPHLINE="GRAPHLINE", COMBINE="COMBINE"; public boolean parseAnnotationFrom(AlignmentI al, BufferedReader in) throws Exception { nlinesread = 0; ArrayList combineAnnotation_calls = new ArrayList(); + ArrayList deferredAnnotation_calls = new ArrayList(); boolean modified = false; String groupRef = null; Hashtable groupRefRows = new Hashtable(); @@ -712,7 +714,7 @@ public class AnnotationFile continue; } - else if (token.equalsIgnoreCase("COMBINE")) + else if (token.equalsIgnoreCase(COMBINE)) { // keep a record of current state and resolve groupRef at end combineAnnotation_calls.add(new Object[] { st, refSeq, groupRef}); @@ -725,9 +727,10 @@ public class AnnotationFile modified = true; continue; } - else if (token.equalsIgnoreCase("GRAPHLINE")) + else if (token.equalsIgnoreCase(GRAPHLINE)) { - addLine(al, st); + // resolve at end + deferredAnnotation_calls.add(new Object[] { GRAPHLINE, st, refSeq, groupRef}); modified = true; continue; } @@ -970,6 +973,21 @@ public class AnnotationFile } ((Vector) groupRefRows.get(groupRef)).removeAllElements(); } + // process any deferred attribute settings for each context + for (Object[] _deferred_args : deferredAnnotation_calls) + { + if (_deferred_args[0] == GRAPHLINE) + { + addLine(al, + (StringTokenizer) _deferred_args[1], // st + (SequenceI) _deferred_args[2], // refSeq + (_deferred_args[3] == null) ? null : groupRefLookup + .get((String) _deferred_args[3]) // the reference + // group, or null + ); + } + } + // finally, combine all the annotation rows within each context. /** * number of combine statements in this annotation file. Used to create new groups for combined annotation graphs without disturbing existing ones @@ -983,7 +1001,6 @@ public class AnnotationFile (_combine_args[2]==null) ? null : groupRefLookup.get((String)_combine_args[2]) // the reference group, or null ); } - } return modified; } @@ -1194,19 +1211,26 @@ public class AnnotationFile } } - void addLine(AlignmentI al, StringTokenizer st) + void addLine(AlignmentI al, StringTokenizer st, SequenceI seqRef, SequenceGroup groupRef) { String group = st.nextToken(); AlignmentAnnotation annotation = null, alannot[] = al .getAlignmentAnnotation(); + float value = new Float(st.nextToken()).floatValue(); + String label = st.hasMoreTokens() ? st.nextToken() : null; + java.awt.Color colour = null; + if (st.hasMoreTokens()) + { + UserColourScheme ucs = new UserColourScheme(st.nextToken()); + colour = ucs.findColour('A'); + } if (alannot != null) { for (int i = 0; i < alannot.length; i++) { - if (alannot[i].label.equalsIgnoreCase(group)) + if (alannot[i].label.equalsIgnoreCase(group) && (seqRef==null || alannot[i].sequenceRef==seqRef) && (groupRef==null || alannot[i].groupRef==groupRef)) { - annotation = alannot[i]; - break; + alannot[i].setThreshold(new GraphLine(value, label, colour)); } } } @@ -1214,16 +1238,6 @@ public class AnnotationFile { return; } - float value = new Float(st.nextToken()).floatValue(); - String label = st.hasMoreTokens() ? st.nextToken() : null; - java.awt.Color colour = null; - if (st.hasMoreTokens()) - { - UserColourScheme ucs = new UserColourScheme(st.nextToken()); - colour = ucs.findColour('A'); - } - - annotation.setThreshold(new GraphLine(value, label, colour)); } void addGroup(AlignmentI al, StringTokenizer st) -- 1.7.10.2