X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=00b7ead85bde0ac4d6b5c104d33c3752c971904f;hb=96f41aa46d3e568f8734834ab36fdc9ad8e54ac1;hp=0095aefab7cf8267e5a746a2eec74e742140adcb;hpb=16342ec2ab61d371ee70f61ac0294f2716fab638;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 0095aef..00b7ead 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -72,10 +72,18 @@ public class AnnotationFile this.hiddenRepSeqs = hiddenRepSeqs; } } - + /** + * Prepare an annotation file given a set of annotations, groups, alignment properties and views. + * @param annotations + * @param groups + * @param properties + * @param views + * @return annotation file + */ 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. if (annotations != null) { boolean oneColour = true; @@ -85,7 +93,7 @@ public class AnnotationFile StringBuffer colours = new StringBuffer(); StringBuffer graphLine = new StringBuffer(); - + StringBuffer rowprops = new StringBuffer(); Hashtable graphGroup = new Hashtable(); java.awt.Color color; @@ -224,7 +232,6 @@ public class AnnotationFile if (hasLabels) { // TODO: labels are emitted after values for bar graphs. - text.append(comma); if // empty labels are allowed, so (row.annotations[j].displayCharacter != null && row.annotations[j].displayCharacter.length() > 0 @@ -276,7 +283,14 @@ public class AnnotationFile colours.append("COLOUR\t" + row.label + "\t" + jalview.util.Format.getHexString(color) + "\n"); } - + 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("\n"); + } } text.append("\n"); @@ -292,6 +306,7 @@ public class AnnotationFile text.append(en.nextElement() + "\n"); } } + text.append(rowprops.toString()); } if (groups != null) @@ -498,7 +513,11 @@ public class AnnotationFile combineAnnotations(al, st); continue; } - + else if (token.equalsIgnoreCase("ROWPROPERTIES")) + { + addRowProperties(al, st); + continue; + } else if (token.equalsIgnoreCase("GRAPHLINE")) { addLine(al, st); @@ -615,7 +634,7 @@ public class AnnotationFile } else { - annotations[index++] = parseAnnotation(token); + annotations[index++] = parseAnnotation(token, graphStyle); emptyColumn = false; } } @@ -670,8 +689,9 @@ public class AnnotationFile return true; } - Annotation parseAnnotation(String string) + 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 String desc = null, displayChar = null; char ss = ' '; // secondaryStructure float value = 0; @@ -686,31 +706,40 @@ public class AnnotationFile UserColourScheme ucs = new UserColourScheme(); colour = ucs.getColourFromString(string.substring(i + 1, j)); - + if ( i>0 && string.charAt(i-1)==',') + { + // clip the preceding comma as well + i--; + } string = string.substring(0, i) + string.substring(j + 1); } - StringTokenizer st = new StringTokenizer(string, ","); + StringTokenizer st = new StringTokenizer(string, ",", true); String token; + boolean seenContent=false; while (st.hasMoreTokens()) { token = st.nextToken().trim(); - if (token.length() == 0) + if (token.equals(",")) { - if (parsedValue && !dcset) + if (!seenContent && parsedValue && !dcset) { // allow the value below the bar/line to be empty dcset = true; displayChar = " "; } + seenContent = false; continue; + } else { + seenContent = true; } if (!parsedValue) { try { - displayChar = token; + displayChar = token; + // foo value = new Float(token).floatValue(); parsedValue = true; continue; @@ -719,7 +748,7 @@ public class AnnotationFile } } - if (token.equals("H") || token.equals("E")) + if (hasSymbols && (token.equals("H") || token.equals("E"))) { // Either this character represents a helix or sheet // or an integer which can be displayed @@ -735,10 +764,10 @@ public class AnnotationFile } } - if (!dcset && string.charAt(string.length() - 1) == ',') - { - displayChar = " "; // empty display char symbol. - } +// if (!dcset && string.charAt(string.length() - 1) == ',') +// { +// displayChar = " "; // empty display char symbol. +// } if (displayChar != null && displayChar.length() > 1 && desc != null && desc.length() == 1) { @@ -933,6 +962,35 @@ 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(); + key = keyValue.substring(0, keyValue.indexOf("=")); + value = keyValue.substring(keyValue.indexOf("=") + 1); + 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 (alr[i].label.equalsIgnoreCase(label)) + { + alr[i].centreColLabels = centerlab; + alr[i].scaleColLabel = scaletofit; + alr[i].showAllColLabels = showalllabs; + } + } + } + } void addProperties(AlignmentI al, StringTokenizer st) {