From b5fdf35e68eea0a0710cae2178020645ac17e6af Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 25 Apr 2007 14:16:21 +0000 Subject: [PATCH] properties + colours --- src/jalview/io/AnnotationFile.java | 190 ++++++++++++++++++++++++++++-------- 1 file changed, 150 insertions(+), 40 deletions(-) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index ef95458..a936dac 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -35,13 +35,14 @@ public class AnnotationFile + new java.util.Date() + "\n\n"); public String printAnnotations(AlignmentAnnotation[] annotations, - Vector groups) + Vector groups, + Hashtable properties) { if (annotations != null) { AlignmentAnnotation row; String comma; - SequenceI seqref = null; + SequenceI refSeq = null; StringBuffer colours = new StringBuffer(); StringBuffer graphLine = new StringBuffer(); @@ -54,7 +55,7 @@ public class AnnotationFile { row = annotations[i]; - if (!row.visible && row.annotations!=null) + if (!row.visible) { continue; } @@ -63,18 +64,18 @@ public class AnnotationFile if (row.sequenceRef == null) { - if (seqref != null) + if (refSeq != null) { text.append("\nSEQUENCE_REF\tALIGNMENT\n"); } - seqref = null; + refSeq = null; } - else if (seqref == null || seqref != row.sequenceRef) + else if (refSeq == null || refSeq != row.sequenceRef) { - seqref = row.sequenceRef; - text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n"); + refSeq = row.sequenceRef; + text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n"); } if (row.graph == AlignmentAnnotation.NO_GRAPH) @@ -126,8 +127,8 @@ public class AnnotationFile for (int j = 0; j < row.annotations.length; j++) { - if (seqref != null && - jalview.util.Comparison.isGap(seqref.getCharAt(j))) + if (refSeq != null && + jalview.util.Comparison.isGap(refSeq.getCharAt(j))) { continue; } @@ -156,10 +157,21 @@ public class AnnotationFile text.append(comma + row.annotations[j].value); } } + + if(row.annotations[j].colour!=null + && row.annotations[j].colour!=java.awt.Color.black) + { + text.append(comma+"["+ + jalview.util.Format.getHexString( + row.annotations[j].colour)+"]"); + } } text.append("|"); } + if(!Float.isNaN(row.score)) + text.append("\t"+row.score); + text.append("\n"); if (color != null && color != java.awt.Color.black) @@ -191,6 +203,18 @@ public class AnnotationFile printGroups(groups); } + if(properties!=null) + { + text.append("\n\nALIGNMENT"); + Enumeration en = properties.keys(); + while(en.hasMoreElements()) + { + String key = en.nextElement().toString(); + text.append("\t"+key+"="+properties.get(key)); + } + + } + return text.toString(); } @@ -385,43 +409,79 @@ public class AnnotationFile continue; } - graphStyle = AlignmentAnnotation.getGraphValueFromString(token); - label = st.nextToken(); - - if (st.countTokens() > 1) + else if( token.equalsIgnoreCase("BELOW_ALIGNMENT")) { - description = st.nextToken(); + setBelowAlignment(al, st); + continue; } - else + else if( token.equalsIgnoreCase("ALIGNMENT")) { - description = null; + addAlignmentDetails(al, st); + continue; } - line = st.nextToken(); + graphStyle = AlignmentAnnotation.getGraphValueFromString(token); + label = st.nextToken(); - st = new StringTokenizer(line, "|", true); - annotations = new Annotation[alWidth]; index = 0; - boolean emptyColumn = true; + annotations = new Annotation[alWidth]; + description = null; + float score = Float.NaN; - while (st.hasMoreElements() && index < alWidth) + if(st.hasMoreTokens()) { - token = st.nextToken().trim(); - if (token.equals("|")) + line = st.nextToken(); + + if (line.indexOf("|") ==-1) { - if (emptyColumn) - { - index++; - } + description = line; + if (st.hasMoreTokens()) + line = st.nextToken(); + } - emptyColumn = true; + if(st.hasMoreTokens()) + { + //This must be the score + score = Float.valueOf(st.nextToken()).floatValue(); } - else + + st = new StringTokenizer(line, "|", true); + + + boolean emptyColumn = true; + boolean onlyOneElement = (st.countTokens()==1); + + while (st.hasMoreElements() && index < alWidth) { - annotations[index++] = parseAnnotation(token); - emptyColumn = false; + token = st.nextToken().trim(); + + if(onlyOneElement) + { + try + { + score = Float.valueOf(token).floatValue(); + break; + } + catch(NumberFormatException ex){} + } + + if (token.equals("|")) + { + if (emptyColumn) + { + index++; + } + + emptyColumn = true; + } + else + { + annotations[index++] = parseAnnotation(token); + emptyColumn = false; + } } + } annotation = new AlignmentAnnotation(label, @@ -431,8 +491,11 @@ public class AnnotationFile 0, graphStyle); + annotation.score = score; + if (refSeq != null) { + annotation.belowAlignment=false; annotation.createSequenceMapping(refSeq, refSeqIndex, false); annotation.adjustForAlignment(); refSeq.addAlignmentAnnotation(annotation); @@ -457,10 +520,24 @@ public class AnnotationFile Annotation parseAnnotation(String string) { - String desc = null, displayChar = ""; + String desc = null, displayChar = null; char ss = ' '; // secondaryStructure float value = 0; boolean parsedValue = false; + + //find colour here + java.awt.Color colour = null; + int i=string.indexOf("["); + int j=string.indexOf("]"); + if(i>-1 && j>-1) + { + UserColourScheme ucs = new UserColourScheme(); + + colour = ucs.getColourFromString(string.substring(i+1,j)); + + string = string.substring(0,i)+string.substring(j+1); + } + StringTokenizer st = new StringTokenizer(string, ","); String token; while (st.hasMoreTokens()) @@ -501,19 +578,20 @@ public class AnnotationFile } - if (desc == null) - { - desc = value + ""; - } - - if (displayChar.length() > 1 && desc.length() == 1) + if (displayChar.length() > 1 + && desc!=null + && desc.length() == 1) { String tmp = displayChar; displayChar = desc; desc = tmp; } - return new Annotation(displayChar, desc, ss, value); + Annotation anot = new Annotation(displayChar, desc, ss, value); + + anot.colour = colour; + + return anot; } void colourAnnotations(AlignmentI al, String label, String colour) @@ -647,6 +725,8 @@ public class AnnotationFile } } + + if (refSeq != null) { sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1); @@ -757,4 +837,34 @@ public class AnnotationFile } } } + + void setBelowAlignment(AlignmentI al, StringTokenizer st) + { + String token; + AlignmentAnnotation aa; + while(st.hasMoreTokens()) + { + token = st.nextToken(); + for(int i=0; i