X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=6285cf10011eb94bc3ad9d2154d7b9a262be44a6;hb=9d8d94660cfba31f6dd39cd6a8a25e3e88284277;hp=a936dac86b2fc4245f3c10a297a406600a4c4ed4;hpb=b5fdf35e68eea0a0710cae2178020645ac17e6af;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index a936dac..6285cf1 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -33,13 +33,45 @@ public class AnnotationFile "JALVIEW_ANNOTATION\n" + "# Created: " + new java.util.Date() + "\n\n"); - + /** + * convenience method for pre-2.4 feature files which have no view, hidden columns or hidden row keywords. + * @param annotations + * @param groups + * @param properties + * @return feature file as a string. + */ public String printAnnotations(AlignmentAnnotation[] annotations, Vector groups, Hashtable properties) { + return printAnnotations(annotations, groups, + properties, null); + + } + /** + * hold all the information about a particular view definition + * read from or written out in an annotations file. + */ + public class ViewDef { + public String viewname; + public HiddenSequences hidseqs; + public ColumnSelection hiddencols; + public Vector visibleGroups; + public ViewDef(String viewname, HiddenSequences hidseqs, + ColumnSelection hiddencols) + { + this.viewname = viewname; + this.hidseqs = hidseqs; + this.hiddencols = hiddencols; + } + } + public String printAnnotations(AlignmentAnnotation[] annotations, + Vector groups, + Hashtable properties, ViewDef[] views) + { if (annotations != null) { + boolean oneColour = true; AlignmentAnnotation row; String comma; SequenceI refSeq = null; @@ -55,12 +87,13 @@ public class AnnotationFile { row = annotations[i]; - if (!row.visible) + if (!row.visible && !row.hasScore()) { continue; } color = null; + oneColour = true; if (row.sequenceRef == null) { @@ -125,7 +158,7 @@ public class AnnotationFile text.append(row.description + "\t"); } - for (int j = 0; j < row.annotations.length; j++) + for (int j = 0; row.annotations!=null && j < row.annotations.length; j++) { if (refSeq != null && jalview.util.Comparison.isGap(refSeq.getCharAt(j))) @@ -151,6 +184,11 @@ public class AnnotationFile if (row.annotations[j] != null) { + if(color!=null && !color.equals(row.annotations[j].colour)) + { + oneColour = false; + } + color = row.annotations[j].colour; if (row.annotations[j].value != 0f) { @@ -169,12 +207,12 @@ public class AnnotationFile text.append("|"); } - if(!Float.isNaN(row.score)) + if(row.hasScore()) text.append("\t"+row.score); text.append("\n"); - if (color != null && color != java.awt.Color.black) + if (color != null && color != java.awt.Color.black && oneColour) { colours.append("COLOUR\t" + row.label + "\t" @@ -214,7 +252,7 @@ public class AnnotationFile } } - + return text.toString(); } @@ -486,7 +524,7 @@ public class AnnotationFile annotation = new AlignmentAnnotation(label, description, - annotations, + (index==0) ? null : annotations, 0, 0, graphStyle); @@ -578,7 +616,8 @@ public class AnnotationFile } - if (displayChar.length() > 1 + if (displayChar!=null + && displayChar.length() > 1 && desc!=null && desc.length() == 1) { @@ -586,7 +625,14 @@ public class AnnotationFile displayChar = desc; desc = tmp; } - + /* + * 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; @@ -867,4 +913,33 @@ public class AnnotationFile al.setProperty(key,value); } } + + /** + * Write annotations as a CSV file of the form 'label, value, value, ...' for each row. + * @param annotations + * @return CSV file as a string. + */ + public String printCSVAnnotations(AlignmentAnnotation[] annotations) + { + StringBuffer sp = new StringBuffer(); + for (int i=0; ip) + { + sp.append(atos.substring(p, cp+1)); + } else { + sp.append(atos.substring(p)); + sp.append("\n"); + } + p = cp+1; + } while (p>0); + } + return sp.toString(); + } }