X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=01daf39a9f50ce55262a77af351c0ad1d352bc70;hb=12b928f827972f429471a5bf7a832fa634259a16;hp=aac48eb0fe46c6366a736ecd868f8df285ce1ca4;hpb=520cc5fe77f3f625c9a58cb6b8b83bbca68084b6;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index aac48eb..01daf39 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -72,8 +72,11 @@ public class AnnotationFile this.hiddenRepSeqs = hiddenRepSeqs; } } + /** - * Prepare an annotation file given a set of annotations, groups, alignment properties and views. + * Prepare an annotation file given a set of annotations, groups, alignment + * properties and views. + * * @param annotations * @param groups * @param properties @@ -83,13 +86,15 @@ public class AnnotationFile public String printAnnotations(AlignmentAnnotation[] annotations, Vector groups, Hashtable properties, ViewDef[] views) { - // TODO: resolve views issue : annotationFile could contain visible region, or full data + hidden region specifications for a view. + // TODO: resolve views issue : annotationFile could contain visible region, + // or full data + hidden region specifications for a view. if (annotations != null) { boolean oneColour = true; AlignmentAnnotation row; String comma; SequenceI refSeq = null; + SequenceGroup refGroup = null; StringBuffer colours = new StringBuffer(); StringBuffer graphLine = new StringBuffer(); @@ -120,11 +125,34 @@ public class AnnotationFile refSeq = null; } - else if (refSeq == null || refSeq != row.sequenceRef) + else + { + if (refSeq == null || refSeq != row.sequenceRef) + { + refSeq = row.sequenceRef; + text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n"); + } + } + // mark any group references for the row + if (row.groupRef == null) + { + + if (refGroup != null) + { + text.append("\nGROUP_REF\tALIGNMENT\n"); + } + + refGroup = null; + } + else { - refSeq = row.sequenceRef; - text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n"); + if (refGroup == null || refGroup != row.groupRef) + { + refGroup = row.groupRef; + text.append("\nGROUP_REF\t" + refGroup.getName() + "\n"); + } } + boolean hasGlyphs = row.hasIcons, hasLabels = row.hasText, hasValues = row.hasScore, hasText = false; // lookahead to check what the annotation row object actually contains. for (int j = 0; row.annotations != null @@ -138,8 +166,8 @@ public class AnnotationFile .equals(" ")); hasGlyphs |= (row.annotations[j].secondaryStructure != 0 && row.annotations[j].secondaryStructure != ' '); hasValues |= (row.annotations[j].value != Float.NaN); // NaNs can't - // be - // rendered.. + // be + // rendered.. hasText |= (row.annotations[j].description != null && row.annotations[j].description .length() > 0); } @@ -210,7 +238,7 @@ public class AnnotationFile if (row.annotations[j] != null) { comma = ""; - if (hasGlyphs) // could be also hasGlyphs || ... + if (hasGlyphs) // could be also hasGlyphs || ... { text.append(comma); @@ -288,12 +316,13 @@ public class AnnotationFile colours.append("COLOUR\t" + row.label + "\t" + jalview.util.Format.getHexString(color) + "\n"); } - if (row.scaleColLabel || row.showAllColLabels || row.centreColLabels) + if (row.scaleColLabel || row.showAllColLabels + || row.centreColLabels) { - rowprops.append("ROWPROPERTIES\t"+row.label); - rowprops.append("\tscaletofit="+row.scaleColLabel); - rowprops.append("\tshowalllabs="+row.showAllColLabels); - rowprops.append("\tcentrelabs="+row.centreColLabels); + rowprops.append("ROWPROPERTIES\t" + row.label); + rowprops.append("\tscaletofit=" + row.scaleColLabel); + rowprops.append("\tshowalllabs=" + row.showAllColLabels); + rowprops.append("\tcentrelabs=" + row.centreColLabels); rowprops.append("\n"); } } @@ -433,7 +462,10 @@ public class AnnotationFile public boolean readAnnotationFile(AlignmentI al, String file, String protocol) { - Hashtable autoAnnots=new Hashtable(); + String groupRef = null; + Hashtable groupRefRows = new Hashtable(); + + Hashtable autoAnnots = new Hashtable(); try { BufferedReader in = null; @@ -463,21 +495,28 @@ public class AnnotationFile int graphStyle, index; int refSeqIndex = 1; int existingAnnotations = 0; - // when true - will add new rows regardless of whether they are duplicate auto-annotation like consensus or conservation graphs - boolean overrideAutoAnnot=false; + // when true - will add new rows regardless of whether they are duplicate + // auto-annotation like consensus or conservation graphs + boolean overrideAutoAnnot = false; if (al.getAlignmentAnnotation() != null) { existingAnnotations = al.getAlignmentAnnotation().length; - if (existingAnnotations>0) + if (existingAnnotations > 0) { AlignmentAnnotation[] aa = al.getAlignmentAnnotation(); - for (int aai=0;aai 0) + { + AlignmentAnnotation alan = null; + for (int elm = 0, elmSize = rowset.size(); elm < elmSize; elm++) + { + alan = (AlignmentAnnotation) rowset.elementAt(elm); + alan.groupRef = theGroup; + } + } + } + } + } + ((Vector) groupRefRows.get(groupRef)).removeAllElements(); + } } catch (Exception ex) { ex.printStackTrace(); @@ -718,7 +835,15 @@ public class AnnotationFile Annotation parseAnnotation(String string, int graphStyle) { - boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't do the glyph test if we don't want secondary structure + boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't + // do the + // glyph + // test + // if we + // don't + // want + // secondary + // structure String desc = null, displayChar = null; char ss = ' '; // secondaryStructure float value = 0; @@ -733,7 +858,7 @@ public class AnnotationFile UserColourScheme ucs = new UserColourScheme(); colour = ucs.getColourFromString(string.substring(i + 1, j)); - if ( i>0 && string.charAt(i-1)==',') + if (i > 0 && string.charAt(i - 1) == ',') { // clip the preceding comma as well i--; @@ -743,8 +868,8 @@ public class AnnotationFile StringTokenizer st = new StringTokenizer(string, ",", true); String token; - boolean seenContent=false; - int pass=0; + boolean seenContent = false; + int pass = 0; while (st.hasMoreTokens()) { pass++; @@ -759,7 +884,9 @@ public class AnnotationFile } seenContent = false; continue; - } else { + } + else + { seenContent = true; } @@ -767,7 +894,7 @@ public class AnnotationFile { try { - displayChar = token; + displayChar = token; // foo value = new Float(token).floatValue(); parsedValue = true; @@ -775,13 +902,17 @@ public class AnnotationFile } catch (NumberFormatException ex) { } - } else { - if (token.length()==1) + } + else + { + if (token.length() == 1) { displayChar = token; } } - if (hasSymbols && (token.equals("H") || token.equals("E") || token.equals(" "))) + if (hasSymbols + && (token.equals("H") || token.equals("E") || token + .equals(" "))) { // Either this character represents a helix or sheet // or an integer which can be displayed @@ -791,26 +922,29 @@ public class AnnotationFile displayChar = ""; } } - else if (desc == null || (parsedValue && pass>2)) + else if (desc == null || (parsedValue && pass > 2)) { desc = token; } } -// if (!dcset && string.charAt(string.length() - 1) == ',') -// { -// displayChar = " "; // empty display char symbol. -// } - if (displayChar != null && desc!=null && desc.length()==1) + // if (!dcset && string.charAt(string.length() - 1) == ',') + // { + // displayChar = " "; // empty display char symbol. + // } + if (displayChar != null && desc != null && desc.length() == 1) { if (displayChar.length() > 1) { - // switch desc and displayChar - legacy support + // switch desc and displayChar - legacy support String tmp = displayChar; displayChar = desc; desc = tmp; - } else { - if (displayChar.equals(desc)) { + } + else + { + if (displayChar.equals(desc)) + { // duplicate label - hangover from the 'robust parser' above desc = null; } @@ -999,33 +1133,38 @@ public class AnnotationFile void addRowProperties(AlignmentI al, StringTokenizer st) { - String label = st.nextToken(),keyValue,key,value; - boolean scaletofit=false,centerlab=false,showalllabs=false; - while (st.hasMoreTokens()) { - keyValue=st.nextToken(); + String label = st.nextToken(), keyValue, key, value; + boolean scaletofit = false, centerlab = false, showalllabs = false; + while (st.hasMoreTokens()) + { + keyValue = st.nextToken(); key = keyValue.substring(0, keyValue.indexOf("=")); value = keyValue.substring(keyValue.indexOf("=") + 1); - if (key.equalsIgnoreCase("scaletofit")) { + if (key.equalsIgnoreCase("scaletofit")) + { scaletofit = Boolean.valueOf(value).booleanValue(); } - if (key.equalsIgnoreCase("showalllabs")) { - showalllabs = Boolean.valueOf(value).booleanValue(); - } - if (key.equalsIgnoreCase("centrelabs")) { - centerlab = Boolean.valueOf(value).booleanValue(); - } - AlignmentAnnotation[] alr = al.getAlignmentAnnotation(); - for (int i = 0; i < alr.length; i++) + if (key.equalsIgnoreCase("showalllabs")) + { + showalllabs = Boolean.valueOf(value).booleanValue(); + } + if (key.equalsIgnoreCase("centrelabs")) + { + centerlab = Boolean.valueOf(value).booleanValue(); + } + AlignmentAnnotation[] alr = al.getAlignmentAnnotation(); + for (int i = 0; i < alr.length; i++) + { + if (alr[i].label.equalsIgnoreCase(label)) { - if (alr[i].label.equalsIgnoreCase(label)) - { - alr[i].centreColLabels = centerlab; - alr[i].scaleColLabel = scaletofit; - alr[i].showAllColLabels = showalllabs; - } + alr[i].centreColLabels = centerlab; + alr[i].scaleColLabel = scaletofit; + alr[i].showAllColLabels = showalllabs; } + } } } + void addProperties(AlignmentI al, StringTokenizer st) {