X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=aac48eb0fe46c6366a736ecd868f8df285ce1ca4;hb=a9108fa3538ddb2ef02aa231e233dc978654d6f6;hp=0095aefab7cf8267e5a746a2eec74e742140adcb;hpb=16342ec2ab61d371ee70f61ac0294f2716fab638;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 0095aef..aac48eb 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; @@ -117,7 +125,7 @@ public class AnnotationFile refSeq = row.sequenceRef; text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n"); } - boolean hasGlyphs = false, hasLabels = false, hasValues = false, hasText = false; + 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 && j < row.annotations.length @@ -202,10 +210,15 @@ public class AnnotationFile if (row.annotations[j] != null) { comma = ""; - if (hasGlyphs && row.annotations[j].secondaryStructure != ' ') + if (hasGlyphs) // could be also hasGlyphs || ... { - text.append(comma + row.annotations[j].secondaryStructure); + text.append(comma); + if (row.annotations[j].secondaryStructure != ' ') + { + // only write out the field if its not whitespace. + text.append(row.annotations[j].secondaryStructure); + } comma = ","; } if (hasValues) @@ -224,7 +237,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 +288,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 +311,7 @@ public class AnnotationFile text.append(en.nextElement() + "\n"); } } + text.append(rowprops.toString()); } if (groups != null) @@ -413,6 +433,7 @@ public class AnnotationFile public boolean readAnnotationFile(AlignmentI al, String file, String protocol) { + Hashtable autoAnnots=new Hashtable(); try { BufferedReader in = null; @@ -442,9 +463,24 @@ 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; if (al.getAlignmentAnnotation() != null) { existingAnnotations = al.getAlignmentAnnotation().length; + if (existingAnnotations>0) + { + AlignmentAnnotation[] aa = al.getAlignmentAnnotation(); + for (int aai=0;aai0 && 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; + int pass=0; while (st.hasMoreTokens()) { + pass++; 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; } catch (NumberFormatException ex) { } + } else { + if (token.length()==1) + { + displayChar = token; + } } - - if (token.equals("H") || token.equals("E")) + 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 @@ -729,29 +791,31 @@ public class AnnotationFile displayChar = ""; } } - else if (desc == null) + else if (desc == null || (parsedValue && pass>2)) { desc = token; } } - if (!dcset && string.charAt(string.length() - 1) == ',') +// if (!dcset && string.charAt(string.length() - 1) == ',') +// { +// displayChar = " "; // empty display char symbol. +// } + if (displayChar != null && desc!=null && desc.length()==1) { - displayChar = " "; // empty display char symbol. - } - if (displayChar != null && displayChar.length() > 1 && desc != null - && desc.length() == 1) - { - String tmp = displayChar; - displayChar = desc; - desc = tmp; + if (displayChar.length() > 1) + { + // switch desc and displayChar - legacy support + String tmp = displayChar; + displayChar = desc; + desc = tmp; + } else { + if (displayChar.equals(desc)) { + // duplicate label - hangover from the 'robust parser' above + desc = null; + } + } } - /* - * In principle, this code will ensure that the Annotation element generated - * is renderable by any of the applet or application rendering code but - * instead we check for null strings when the display character is rendered. - * if (displayChar==null) { displayChar=""; } - */ Annotation anot = new Annotation(displayChar, desc, ss, value); anot.colour = colour; @@ -933,6 +997,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) {