X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=e54ae71ad2fd01d38324ad1487f66bbf84ce16a7;hb=97d6516fd717d0daddcbc8154c4de29a812982e5;hp=2ce076ac7a650458084b108d7dd0463ebd6cf091;hpb=ac5e49397d04c63fd42c5e2b32174052657950ff;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 2ce076a..e54ae71 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -35,13 +35,15 @@ public class AnnotationFile + new java.util.Date() + "\n\n"); public String printAnnotations(AlignmentAnnotation[] annotations, - Vector groups) + Vector groups, + Hashtable properties) { if (annotations != null) { + boolean oneColour = true; AlignmentAnnotation row; String comma; - SequenceI seqref = null; + SequenceI refSeq = null; StringBuffer colours = new StringBuffer(); StringBuffer graphLine = new StringBuffer(); @@ -60,21 +62,22 @@ public class AnnotationFile } color = null; + oneColour = true; 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 +129,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; } @@ -140,7 +143,8 @@ public class AnnotationFile text.append(comma + row.annotations[j].secondaryStructure); comma = ","; } - if (row.annotations[j].displayCharacter.length() > 0 + if (row.annotations[j].displayCharacter!=null + && row.annotations[j].displayCharacter.length() > 0 && !row.annotations[j].displayCharacter.equals(" ")) { text.append(comma + row.annotations[j].displayCharacter); @@ -149,19 +153,35 @@ 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) { 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(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" @@ -190,6 +210,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(); } @@ -384,43 +416,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, @@ -430,9 +498,11 @@ public class AnnotationFile 0, graphStyle); + annotation.score = score; + if (refSeq != null) { - System.out.println(refSeq.getName()+" "+refSeqIndex); + annotation.belowAlignment=false; annotation.createSequenceMapping(refSeq, refSeqIndex, false); annotation.adjustForAlignment(); refSeq.addAlignmentAnnotation(annotation); @@ -457,10 +527,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 +585,21 @@ public class AnnotationFile } - if (desc == null) - { - desc = value + ""; - } - - if (displayChar.length() > 1 && desc.length() == 1) + if (displayChar!=null + && 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 +733,8 @@ public class AnnotationFile } } + + if (refSeq != null) { sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1); @@ -757,4 +845,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