X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=80d31fb7fa4153c573eec2a7ea7c819caa1a8ac6;hb=558597672640984d936ea22409a674293192a09c;hp=a211d1aa415ab7ac9761286137a3a35a77ed6d88;hpb=544ccf2cea9d02873528cc8be4ca1682d56cfaad;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index a211d1a..80d31fb 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -22,163 +22,241 @@ package jalview.io; import java.io.*; import jalview.datamodel.*; import java.util.*; -import jalview.schemes.UserColourScheme; import java.net.URL; +import jalview.schemes.*; +import jalview.analysis.Conservation; public class AnnotationFile { + StringBuffer text = new StringBuffer( + "JALVIEW_ANNOTATION\n" + +"# Created: " + +new java.util.Date()+"\n\n"); - public String printAnnotations(AlignmentAnnotation [] annotations) + public String printAnnotations(AlignmentAnnotation [] annotations, + Vector groups) { - StringBuffer text = new StringBuffer( - "JALVIEW_ANNOTATION\n" - +"# Created: " - +new java.util.Date()+"\n\n"); + if(annotations!=null) + { + AlignmentAnnotation row; + String comma; + SequenceI seqref = null; - AlignmentAnnotation row; - String comma; - SequenceI seqref = null; + StringBuffer colours = new StringBuffer(); + StringBuffer graphLine = new StringBuffer(); - StringBuffer colours = new StringBuffer(); - StringBuffer graphLine = new StringBuffer(); + Hashtable graphGroup = new Hashtable(); - Hashtable graphGroup = new Hashtable(); + java.awt.Color color; - java.awt.Color color; + for (int i = 0; i < annotations.length; i++) + { + row = annotations[i]; - for(int i=0; i-1) + if (row.graphGroup > -1) { String key = String.valueOf(row.graphGroup); - if(graphGroup.containsKey(key)) + if (graphGroup.containsKey(key)) graphGroup.put(key, graphGroup.get(key) - +"\t"+row.label); + + "\t" + row.label); else graphGroup.put(key, row.label); } - } - - text.append(row.label+"\t"); + } - for(int j=0; j 0 - && !row.annotations[j].displayCharacter.equals(" ")) - { - text.append(comma + row.annotations[j].displayCharacter); - comma = ","; - } - - if (row.annotations[j]!=null) + if (seqref != null && + jalview.util.Comparison.isGap(seqref.getCharAt(j))) + continue; + + if (row.annotations[j] != null) { - color = row.annotations[j].colour; - if (row.annotations[j].value!=0f) - text.append(comma + row.annotations[j].value); + comma = ""; + if (row.annotations[j].secondaryStructure != ' ') + { + text.append(comma + row.annotations[j].secondaryStructure); + comma = ","; + } + if (row.annotations[j].displayCharacter.length() > 0 + && !row.annotations[j].displayCharacter.equals(" ")) + { + text.append(comma + row.annotations[j].displayCharacter); + comma = ","; + } + + if (row.annotations[j] != null) + { + color = row.annotations[j].colour; + if (row.annotations[j].value != 0f) + text.append(comma + row.annotations[j].value); + } } + text.append("|"); + } + + text.append("\n"); + + if (color != null && color != java.awt.Color.black) + { + colours.append("COLOUR\t" + + row.label + "\t" + + jalview.util.Format.getHexString(color) + "\n"); } - text.append("|"); + } text.append("\n"); - if(color!=null && color!=java.awt.Color.black) + text.append(colours.toString()); + text.append(graphLine.toString()); + if (graphGroup.size() > 0) { - colours.append("COLOUR\t" - +row.label+"\t" - +jalview.util.Format.getHexString(color)+"\n"); + text.append("COMBINE\t"); + Enumeration en = graphGroup.elements(); + while (en.hasMoreElements()) + { + text.append(en.nextElement() + "\n"); + } } + } + + if(groups!=null) + { + printGroups(groups); } - text.append("\n"); + return text.toString(); + } + - text.append(colours.toString()); - text.append(graphLine.toString()); - if(graphGroup.size()>0) + public void printGroups(Vector sequenceGroups) + { + SequenceGroup sg; + for (int i = 0; i < sequenceGroups.size(); i++) { - text.append("COMBINE\t"); - Enumeration en = graphGroup.elements(); - while(en.hasMoreElements()) + sg = (SequenceGroup) sequenceGroups.elementAt(i); + text.append("SEQUENCE_GROUP\t" + + sg.getName() + "\t" + + (sg.getStartRes()+1) + "\t" + + (sg.getEndRes()+1) + "\t" + "-1\t"); + for(int s=0; s1) + description = st.nextToken(); + else + description = null; line = st.nextToken(); @@ -438,6 +533,129 @@ public class AnnotationFile } annotation.setThreshold(new GraphLine(value, label, colour)); + } + + void addGroup(AlignmentI al, StringTokenizer st) + { + SequenceGroup sg = new SequenceGroup(); + sg.setName(st.nextToken()); + sg.setStartRes(Integer.parseInt(st.nextToken())-1); + sg.setEndRes(Integer.parseInt(st.nextToken())-1); + + String index = st.nextToken(); + if(index.equals("-1")) + { + while (st.hasMoreElements()) + { + sg.addSequence(al.findName(st.nextToken()), false); + } + } + else + { + StringTokenizer st2 = new StringTokenizer(index, ","); + + while (st2.hasMoreTokens()) + { + String tmp = st2.nextToken(); + if (tmp.equals("*")) + { + for (int i = 0; i < al.getHeight(); i++) + { + sg.addSequence(al.getSequenceAt(i), false); + } + } + else if (tmp.indexOf("-") >= 0) + { + StringTokenizer st3 = new StringTokenizer(tmp, "-"); + int start = (Integer.parseInt(st3.nextToken())); + int end = (Integer.parseInt(st3.nextToken())); + + if (end > start) + for (int i = start; i <= end; i++) + sg.addSequence(al.getSequenceAt(i-1), false); + } + else + { + sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp)-1 ), false); + } + } + } + + if(refSeq!=null) + { + sg.setStartRes( refSeq.findIndex( sg.getStartRes()+1 )-1 ); + sg.setEndRes( refSeq.findIndex( sg.getEndRes() +1) -1 ); + } + + al.addGroup(sg); + annotationsHash.put(sg.getName(), sg); + } + + void addProperties(AlignmentI al, StringTokenizer st) + { + + //So far we have only added groups to the annotationHash, + //the idea is in the future properties can be added to + //alignments, other annotations etc + SequenceGroup sg = (SequenceGroup)annotationsHash.get(st.nextToken()); + + if(sg!=null) + { + String keyValue, key, value; + while(st.hasMoreTokens()) + { + keyValue = st.nextToken(); + key = keyValue.substring(0,keyValue.indexOf("=")); + value=keyValue.substring(keyValue.indexOf("=")+1); + + if(key.equalsIgnoreCase("description")) + sg.setDescription(value); + else if(key.equalsIgnoreCase("colour")) + sg.cs = ColourSchemeProperty.getColour(al, value); + else if (key.equalsIgnoreCase("pidThreshold")) + { + sg.cs.setThreshold(Integer.parseInt(value), true); + + } + else if (key.equalsIgnoreCase("consThreshold")) + { + sg.cs.setConservationInc(Integer.parseInt(value)); + Conservation c = new Conservation("Group", + ResidueProperties.propHash, 3, + sg.getSequences(null), + sg.getStartRes(), + sg.getEndRes() + 1); + + c.calculate(); + c.verdict(false, 25); + + sg.cs.setConservation(c); + + } + else if (key.equalsIgnoreCase("outlineColour")) + { + sg.setOutlineColour(new UserColourScheme(value).findColour('A')); + } + else if (key.equalsIgnoreCase("displayBoxes")) + sg.setDisplayBoxes( Boolean.valueOf(value).booleanValue() ); + else if (key.equalsIgnoreCase("displayText")) + sg.setDisplayText( Boolean.valueOf(value).booleanValue() ); + else if (key.equalsIgnoreCase("colourText")) + sg.setColourText( Boolean.valueOf(value).booleanValue() ); + else if (key.equalsIgnoreCase("textCol1")) + { + sg.textColour = new UserColourScheme(value).findColour('A'); + } + else if (key.equalsIgnoreCase("textCol2")) + { + sg.textColour2 = new UserColourScheme(value).findColour('A'); + } + else if (key.equalsIgnoreCase("textColThreshold")) + sg.thresholdTextColour = Integer.parseInt(value); + + sg.recalcConservation(); + } + } } }