From: jprocter Date: Thu, 28 Jan 2010 12:27:25 +0000 (+0000) Subject: more rigorous annotation row content check to limit fields output in annotation file... X-Git-Tag: Release_2_5~151 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=314788fcda6e80edb566feaaf0c6ce5a2bcd2dad;p=jalview.git more rigorous annotation row content check to limit fields output in annotation file. Needs testing further. See Mantis bug #55537 --- diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 4c38bd2..50b477c 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -60,8 +60,9 @@ public class AnnotationFile public ColumnSelection hiddencols; public Vector visibleGroups; + public Hashtable hiddenRepSeqs; - + public ViewDef(String viewname, HiddenSequences hidseqs, ColumnSelection hiddencols, Hashtable hiddenRepSeqs) { @@ -116,19 +117,43 @@ public class AnnotationFile refSeq = row.sequenceRef; text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n"); } + boolean hasGlyphs = false, hasLabels = false, hasValues = false, hasText = false; + // lookahead to check what the annotation row object actually contains. + for (int j = 0; row.annotations != null + && j < row.annotations.length + && (!hasGlyphs || !hasLabels || !hasValues); j++) + { + if (row.annotations[j] != null) + { + hasLabels |= (row.annotations[j].displayCharacter != null + && row.annotations[j].displayCharacter.length() > 0 && !row.annotations[j].displayCharacter + .equals(" ")); + hasGlyphs |= (row.annotations[j].secondaryStructure != 0 && row.annotations[j].secondaryStructure != ' '); + hasValues |= (row.annotations[j].value != Float.NaN); // NaNs can't + // be + // rendered.. + hasText |= (row.annotations[j].description != null && row.annotations[j].description + .length() > 0); + } + } if (row.graph == AlignmentAnnotation.NO_GRAPH) { text.append("NO_GRAPH\t"); + hasValues = false; // only secondary structure + hasLabels = false; // and annotation description string. } else { if (row.graph == AlignmentAnnotation.BAR_GRAPH) { text.append("BAR_GRAPH\t"); + hasGlyphs = false; // no secondary structure + } else if (row.graph == AlignmentAnnotation.LINE_GRAPH) { + hasGlyphs = false; // no secondary structure text.append("LINE_GRAPH\t"); } @@ -165,7 +190,6 @@ public class AnnotationFile { text.append(row.description + "\t"); } - for (int j = 0; row.annotations != null && j < row.annotations.length; j++) { @@ -178,33 +202,55 @@ public class AnnotationFile if (row.annotations[j] != null) { comma = ""; - if (row.annotations[j].secondaryStructure != ' ') + if (hasGlyphs && row.annotations[j].secondaryStructure != ' ') { + text.append(comma + row.annotations[j].secondaryStructure); comma = ","; } - if (row.annotations[j].displayCharacter != null - && row.annotations[j].displayCharacter.length() > 0 - && !row.annotations[j].displayCharacter.equals(" ")) + if (hasValues) { - text.append(comma + row.annotations[j].displayCharacter); + if (row.annotations[j].value != Float.NaN) + { + text.append(comma + row.annotations[j].value); + } + else + { + System.err.println("Skipping NaN - not valid value."); + text.append(comma + 0f);// row.annotations[j].value); + } comma = ","; } - - if (row.annotations[j] != null) + if (hasLabels) { - if (color != null && !color.equals(row.annotations[j].colour)) + // 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 + && !row.annotations[j].displayCharacter.equals(" ")) { - oneColour = false; + text.append(comma + row.annotations[j].displayCharacter); + comma = ","; } - - color = row.annotations[j].colour; - if (row.annotations[j].value != 0f - && row.annotations[j].value != Float.NaN) + } + if (hasText) + { + if (row.annotations[j].description != null + && row.annotations[j].description.length() > 0 + && !row.annotations[j].description + .equals(row.annotations[j].displayCharacter)) { - text.append(comma + row.annotations[j].value); + text.append(comma + row.annotations[j].description); + comma = ","; } } + if (color != null && !color.equals(row.annotations[j].colour)) + { + oneColour = false; + } + + color = row.annotations[j].colour; if (row.annotations[j].colour != null && row.annotations[j].colour != java.awt.Color.black) @@ -214,6 +260,7 @@ public class AnnotationFile + jalview.util.Format .getHexString(row.annotations[j].colour) + "]"); + comma = ","; } } text.append("|"); @@ -271,22 +318,24 @@ public class AnnotationFile public void printGroups(Vector sequenceGroups) { SequenceGroup sg; - SequenceI seqrep=null; + SequenceI seqrep = null; for (int i = 0; i < sequenceGroups.size(); i++) { sg = (SequenceGroup) sequenceGroups.elementAt(i); if (!sg.hasSeqrep()) { text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t" - + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1) + "\t" - + "-1\t"); + + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1) + + "\t" + "-1\t"); seqrep = null; - } else { + } + else + { seqrep = sg.getSeqrep(); - text.append("SEQUENCE_REF\t"+seqrep.getName()+"\n"); + text.append("SEQUENCE_REF\t" + seqrep.getName() + "\n"); text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t" - + (seqrep.findPosition(sg.getStartRes())) + "\t" + (seqrep.findPosition(sg.getEndRes())) + "\t" - + "-1\t"); + + (seqrep.findPosition(sg.getStartRes())) + "\t" + + (seqrep.findPosition(sg.getEndRes())) + "\t" + "-1\t"); } for (int s = 0; s < sg.getSize(); s++) { @@ -319,7 +368,7 @@ public class AnnotationFile text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t"); text.append("displayText=" + sg.getDisplayText() + "\t"); text.append("colourText=" + sg.getColourText() + "\t"); - text.append("showUnconserved="+sg.getShowunconserved()+"\t"); + text.append("showUnconserved=" + sg.getShowunconserved() + "\t"); if (sg.textColour != java.awt.Color.black) { text.append("textCol1=" @@ -332,7 +381,7 @@ public class AnnotationFile } if (sg.thresholdTextColour != 0) { - text.append("textColThreshold=" + sg.thresholdTextColour+"\t"); + text.append("textColThreshold=" + sg.thresholdTextColour + "\t"); } if (sg.idColour != null) { @@ -347,7 +396,7 @@ public class AnnotationFile { text.append("hidecols=true\t"); } - if (seqrep!=null) + if (seqrep != null) { // terminate the last line and clear the sequence ref for the group text.append("\nSEQUENCE_REF"); @@ -589,7 +638,8 @@ public class AnnotationFile // TODO: verify that undo/redo with 1:many sequence associated // annotations can be undone correctly AlignmentAnnotation ann = new AlignmentAnnotation(annotation); - annotation.createSequenceMapping(referedSeq, refSeqIndex, false); + annotation + .createSequenceMapping(referedSeq, refSeqIndex, false); annotation.adjustForAlignment(); referedSeq.addAlignmentAnnotation(annotation); al.addAnnotation(annotation); @@ -625,7 +675,7 @@ public class AnnotationFile String desc = null, displayChar = null; char ss = ' '; // secondaryStructure float value = 0; - boolean parsedValue = false,dcset=false; + boolean parsedValue = false, dcset = false; // find colour here java.awt.Color colour = null; @@ -650,8 +700,8 @@ public class AnnotationFile if (parsedValue && !dcset) { // allow the value below the bar/line to be empty - dcset=true; - displayChar = ""; + dcset = true; + displayChar = " "; } continue; } @@ -685,7 +735,10 @@ public class AnnotationFile } } - + if (!dcset && string.charAt(string.length() - 1) == ',') + { + displayChar = " "; // empty display char symbol. + } if (displayChar != null && displayChar.length() > 1 && desc != null && desc.length() == 1) { @@ -785,32 +838,40 @@ public class AnnotationFile annotation.setThreshold(new GraphLine(value, label, colour)); } + void addGroup(AlignmentI al, StringTokenizer st) { SequenceGroup sg = new SequenceGroup(); sg.setName(st.nextToken()); - String rng =""; - try { + String rng = ""; + try + { rng = st.nextToken(); - if (rng.length()>0 && !rng.startsWith("*")) + if (rng.length() > 0 && !rng.startsWith("*")) { sg.setStartRes(Integer.parseInt(rng) - 1); - } else { + } + else + { sg.setStartRes(0); } rng = st.nextToken(); - if (rng.length()>0 && !rng.startsWith("*")) + if (rng.length() > 0 && !rng.startsWith("*")) { sg.setEndRes(Integer.parseInt(rng) - 1); - } else { - sg.setEndRes(al.getWidth()-1); + } + else + { + sg.setEndRes(al.getWidth() - 1); } } catch (Exception e) { - System.err.println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"+rng+"' - assuming alignment width for group."); + System.err + .println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '" + + rng + "' - assuming alignment width for group."); // assume group is full width sg.setStartRes(0); - sg.setEndRes(al.getWidth()-1); + sg.setEndRes(al.getWidth() - 1); } String index = st.nextToken();