import java.io.*;\r
import jalview.datamodel.*;\r
import java.util.*;\r
-import jalview.schemes.UserColourScheme;\r
import java.net.URL;\r
+import jalview.schemes.*;\r
+import jalview.analysis.Conservation;\r
\r
\r
public class AnnotationFile\r
{\r
+ StringBuffer text = new StringBuffer(\r
+ "JALVIEW_ANNOTATION\n"\r
+ +"# Created: "\r
+ +new java.util.Date()+"\n\n");\r
\r
- public String printAnnotations(AlignmentAnnotation [] annotations)\r
+ public String printAnnotations(AlignmentAnnotation [] annotations,\r
+ Vector groups)\r
{\r
- StringBuffer text = new StringBuffer(\r
- "JALVIEW_ANNOTATION\n"\r
- +"# Created: "\r
- +new java.util.Date()+"\n\n");\r
+ if(annotations!=null)\r
+ {\r
+ AlignmentAnnotation row;\r
+ String comma;\r
+ SequenceI seqref = null;\r
\r
- AlignmentAnnotation row;\r
- String comma;\r
- SequenceI seqref = null;\r
+ StringBuffer colours = new StringBuffer();\r
+ StringBuffer graphLine = new StringBuffer();\r
\r
- StringBuffer colours = new StringBuffer();\r
- StringBuffer graphLine = new StringBuffer();\r
+ Hashtable graphGroup = new Hashtable();\r
\r
- Hashtable graphGroup = new Hashtable();\r
+ java.awt.Color color;\r
\r
- java.awt.Color color;\r
+ for (int i = 0; i < annotations.length; i++)\r
+ {\r
+ row = annotations[i];\r
\r
- for(int i=0; i<annotations.length; i++)\r
- {\r
- row = annotations[i];\r
- color = null;\r
+ if (!row.visible)\r
+ continue;\r
\r
- if( row.sequenceRef == null)\r
- seqref = null;\r
+ color = null;\r
\r
- else if (seqref == null || seqref != row.sequenceRef)\r
- {\r
- seqref = row.sequenceRef;\r
- text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n");\r
- }\r
+ if (row.sequenceRef == null)\r
+ {\r
+ if (seqref != null)\r
+ text.append("\nSEQUENCE_REF\tALIGNMENT\n");\r
\r
+ seqref = null;\r
+ }\r
\r
- if( row.graph == AlignmentAnnotation.NO_GRAPH)\r
- {\r
+ else if (seqref == null || seqref != row.sequenceRef)\r
+ {\r
+ seqref = row.sequenceRef;\r
+ text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n");\r
+ }\r
+\r
+ if (row.graph == AlignmentAnnotation.NO_GRAPH)\r
+ {\r
text.append("NO_GRAPH\t");\r
- }\r
- else\r
- {\r
- if( row.graph == AlignmentAnnotation.BAR_GRAPH)\r
- text.append("BAR_GRAPH\t");\r
- else if(row.graph == AlignmentAnnotation.LINE_GRAPH)\r
- text.append("LINE_GRAPH\t");\r
+ }\r
+ else\r
+ {\r
+ if (row.graph == AlignmentAnnotation.BAR_GRAPH)\r
+ text.append("BAR_GRAPH\t");\r
+ else if (row.graph == AlignmentAnnotation.LINE_GRAPH)\r
+ text.append("LINE_GRAPH\t");\r
\r
- if(row.getThreshold()!=null)\r
+ if (row.getThreshold() != null)\r
graphLine.append("GRAPHLINE\t"\r
+ row.label + "\t"\r
+ row.getThreshold().value + "\t"\r
+ row.getThreshold().label + "\t"\r
+ jalview.util.Format.getHexString(\r
- row.getThreshold().colour)+"\n"\r
+ row.getThreshold().colour) + "\n"\r
);\r
\r
- if(row.graphGroup>-1)\r
+ if (row.graphGroup > -1)\r
{\r
String key = String.valueOf(row.graphGroup);\r
- if(graphGroup.containsKey(key))\r
+ if (graphGroup.containsKey(key))\r
graphGroup.put(key, graphGroup.get(key)\r
- +"\t"+row.label);\r
+ + "\t" + row.label);\r
else\r
graphGroup.put(key, row.label);\r
}\r
- }\r
-\r
- text.append(row.label+"\t");\r
+ }\r
\r
- for(int j=0; j<row.annotations.length; j++)\r
- {\r
- if (seqref != null && jalview.util.Comparison.isGap(seqref.getCharAt(j)))\r
- continue;\r
+ text.append(row.label + "\t");\r
+ if (row.description != null)\r
+ text.append(row.description + "\t");\r
\r
- if(row.annotations[j]!=null)\r
+ for (int j = 0; j < row.annotations.length; j++)\r
{\r
- comma = "";\r
- if (row.annotations[j].secondaryStructure!=' ')\r
- {\r
- text.append(comma + row.annotations[j].secondaryStructure);\r
- comma = ",";\r
- }\r
- if (row.annotations[j].displayCharacter.length() > 0\r
- && !row.annotations[j].displayCharacter.equals(" "))\r
- {\r
- text.append(comma + row.annotations[j].displayCharacter);\r
- comma = ",";\r
- }\r
-\r
- if (row.annotations[j]!=null)\r
+ if (seqref != null &&\r
+ jalview.util.Comparison.isGap(seqref.getCharAt(j)))\r
+ continue;\r
+\r
+ if (row.annotations[j] != null)\r
{\r
- color = row.annotations[j].colour;\r
- if (row.annotations[j].value!=0f)\r
- text.append(comma + row.annotations[j].value);\r
+ comma = "";\r
+ if (row.annotations[j].secondaryStructure != ' ')\r
+ {\r
+ text.append(comma + row.annotations[j].secondaryStructure);\r
+ comma = ",";\r
+ }\r
+ if (row.annotations[j].displayCharacter.length() > 0\r
+ && !row.annotations[j].displayCharacter.equals(" "))\r
+ {\r
+ text.append(comma + row.annotations[j].displayCharacter);\r
+ comma = ",";\r
+ }\r
+\r
+ if (row.annotations[j] != null)\r
+ {\r
+ color = row.annotations[j].colour;\r
+ if (row.annotations[j].value != 0f)\r
+ text.append(comma + row.annotations[j].value);\r
+ }\r
}\r
+ text.append("|");\r
+ }\r
+\r
+ text.append("\n");\r
+\r
+ if (color != null && color != java.awt.Color.black)\r
+ {\r
+ colours.append("COLOUR\t"\r
+ + row.label + "\t"\r
+ + jalview.util.Format.getHexString(color) + "\n");\r
}\r
- text.append("|");\r
+\r
}\r
\r
text.append("\n");\r
\r
- if(color!=null && color!=java.awt.Color.black)\r
+ text.append(colours.toString());\r
+ text.append(graphLine.toString());\r
+ if (graphGroup.size() > 0)\r
{\r
- colours.append("COLOUR\t"\r
- +row.label+"\t"\r
- +jalview.util.Format.getHexString(color)+"\n");\r
+ text.append("COMBINE\t");\r
+ Enumeration en = graphGroup.elements();\r
+ while (en.hasMoreElements())\r
+ {\r
+ text.append(en.nextElement() + "\n");\r
+ }\r
}\r
+ }\r
+\r
\r
+ if(groups!=null)\r
+ {\r
+ printGroups(groups);\r
}\r
\r
- text.append("\n");\r
+ return text.toString();\r
+ }\r
+\r
\r
- text.append(colours.toString());\r
- text.append(graphLine.toString());\r
- if(graphGroup.size()>0)\r
+ public void printGroups(Vector sequenceGroups)\r
+ {\r
+ SequenceGroup sg;\r
+ for (int i = 0; i < sequenceGroups.size(); i++)\r
{\r
- text.append("COMBINE\t");\r
- Enumeration en = graphGroup.elements();\r
- while(en.hasMoreElements())\r
+ sg = (SequenceGroup) sequenceGroups.elementAt(i);\r
+ text.append("SEQUENCE_GROUP\t"\r
+ + sg.getName() + "\t"\r
+ + (sg.getStartRes()+1) + "\t"\r
+ + (sg.getEndRes()+1) + "\t" + "-1\t");\r
+ for(int s=0; s<sg.getSize(); s++)\r
{\r
- text.append(en.nextElement()+"\n");\r
+ text.append(sg.getSequenceAt(s).getName()+"\t");\r
}\r
- }\r
\r
- return text.toString();\r
+ text.append("\nPROPERTIES\t"+sg.getName()+"\t");\r
+\r
+ if(sg.getDescription()!=null)\r
+ text.append("description="+sg.getDescription()+"\t");\r
+ if(sg.cs!=null)\r
+ {\r
+ text.append("colour="+ColourSchemeProperty.getColourName(sg.cs)+"\t");\r
+ if(sg.cs.getThreshold()!=0)\r
+ text.append("pidThreshold="+sg.cs.getThreshold());\r
+ if(sg.cs.conservationApplied())\r
+ text.append("consThreshold="+sg.cs.getConservationInc()+"\t");\r
+ }\r
+ text.append("outlineColour="+\r
+ jalview.util.Format.getHexString(sg.getOutlineColour())+"\t");\r
+\r
+ text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");\r
+ text.append("displayText=" + sg.getDisplayText() + "\t");\r
+ text.append("colourText=" + sg.getColourText() + "\t");\r
+\r
+ if (sg.textColour != java.awt.Color.black)\r
+ text.append("textCol1=" +\r
+ jalview.util.Format.getHexString(sg.textColour) + "\t");\r
+ if (sg.textColour2 != java.awt.Color.white)\r
+ text.append("textCol2=" +\r
+ jalview.util.Format.getHexString(sg.textColour2) + "\t");\r
+ if(sg.thresholdTextColour!=0)\r
+ text.append("textColThreshold="+sg.thresholdTextColour);\r
+\r
+ text.append("\n\n");\r
+\r
+ }\r
}\r
\r
- public boolean readAnnotationFile(AlignmentI al, String file)\r
+\r
+ SequenceI refSeq = null;\r
+ Hashtable annotationsHash = new Hashtable();\r
+ public boolean readAnnotationFile(AlignmentI al,\r
+ String file,\r
+ String protocol)\r
{\r
try\r
{\r
BufferedReader in = null;\r
- java.io.InputStream is = getClass().getResourceAsStream("/" + file);\r
- if (is != null)\r
+ if (protocol.equals(AppletFormatAdapter.FILE))\r
{\r
- in = new BufferedReader(new java.io.InputStreamReader(is));\r
+ in = new BufferedReader(new FileReader(file));\r
}\r
- else\r
+ else if (protocol.equals(AppletFormatAdapter.URL))\r
{\r
- try\r
- {\r
- URL url = new URL(file);\r
- in = new BufferedReader(new InputStreamReader(url.openStream()));\r
- }\r
- catch (java.net.MalformedURLException ex)\r
+ URL url = new URL(file);\r
+ in = new BufferedReader(new InputStreamReader(url.openStream()));\r
+ }\r
+ else if (protocol.equals(AppletFormatAdapter.PASTE))\r
+ {\r
+ in = new BufferedReader(new StringReader(file));\r
+ }\r
+ else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))\r
+ {\r
+ java.io.InputStream is = getClass().getResourceAsStream("/" + file);\r
+ if (is != null)\r
{\r
- in = new BufferedReader(new FileReader(file));\r
+ in = new BufferedReader(new java.io.InputStreamReader(is));\r
}\r
- }\r
+ }\r
\r
String line, label, description, token;\r
int graphStyle, index;\r
- SequenceI refSeq = null;\r
int refSeqIndex = 1;\r
int existingAnnotations = 0;\r
if(al.getAlignmentAnnotation()!=null)\r
continue;\r
}\r
\r
- if(token.equalsIgnoreCase("COMBINE") )\r
+ else if(token.equalsIgnoreCase("COMBINE") )\r
{\r
combineAnnotations(al, st);\r
continue;\r
}\r
\r
- if (token.equalsIgnoreCase("GRAPHLINE"))\r
+ else if (token.equalsIgnoreCase("GRAPHLINE"))\r
{\r
addLine(al, st);\r
continue;\r
}\r
\r
\r
- if(token.equalsIgnoreCase("SEQUENCE_REF") )\r
+ else if(token.equalsIgnoreCase("SEQUENCE_REF") )\r
{\r
refSeq = al.findName(st.nextToken());\r
try{\r
continue;\r
}\r
\r
+ else if(token.equalsIgnoreCase("SEQUENCE_GROUP"))\r
+ {\r
+ addGroup(al, st);\r
+ continue;\r
+ }\r
+\r
+ else if(token.equalsIgnoreCase("PROPERTIES"))\r
+ {\r
+ addProperties(al, st);\r
+ continue;\r
+ }\r
+\r
\r
graphStyle = AlignmentAnnotation.getGraphValueFromString(token);\r
- label = description = st.nextToken();\r
+ label = st.nextToken();\r
+\r
+ if(st.countTokens()>1)\r
+ description = st.nextToken();\r
+ else\r
+ description = null;\r
\r
line = st.nextToken();\r
\r
}\r
\r
annotation.setThreshold(new GraphLine(value, label, colour));\r
+ }\r
+\r
+ void addGroup(AlignmentI al, StringTokenizer st)\r
+ {\r
+ SequenceGroup sg = new SequenceGroup();\r
+ sg.setName(st.nextToken());\r
+ sg.setStartRes(Integer.parseInt(st.nextToken())-1);\r
+ sg.setEndRes(Integer.parseInt(st.nextToken())-1);\r
+\r
+ String index = st.nextToken();\r
+ if(index.equals("-1"))\r
+ {\r
+ while (st.hasMoreElements())\r
+ {\r
+ sg.addSequence(al.findName(st.nextToken()), false);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ StringTokenizer st2 = new StringTokenizer(index, ",");\r
+\r
+ while (st2.hasMoreTokens())\r
+ {\r
+ String tmp = st2.nextToken();\r
+ if (tmp.equals("*"))\r
+ {\r
+ for (int i = 0; i < al.getHeight(); i++)\r
+ {\r
+ sg.addSequence(al.getSequenceAt(i), false);\r
+ }\r
+ }\r
+ else if (tmp.indexOf("-") >= 0)\r
+ {\r
+ StringTokenizer st3 = new StringTokenizer(tmp, "-");\r
\r
+ int start = (Integer.parseInt(st3.nextToken()));\r
+ int end = (Integer.parseInt(st3.nextToken()));\r
+\r
+ if (end > start)\r
+ for (int i = start; i <= end; i++)\r
+ sg.addSequence(al.getSequenceAt(i-1), false);\r
+ }\r
+ else\r
+ {\r
+ sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp)-1 ), false);\r
+ }\r
+ }\r
+ }\r
+\r
+ if(refSeq!=null)\r
+ {\r
+ sg.setStartRes( refSeq.findIndex( sg.getStartRes()+1 )-1 );\r
+ sg.setEndRes( refSeq.findIndex( sg.getEndRes() +1) -1 );\r
+ }\r
+\r
+ al.addGroup(sg);\r
+ annotationsHash.put(sg.getName(), sg);\r
+ }\r
+\r
+ void addProperties(AlignmentI al, StringTokenizer st)\r
+ {\r
+\r
+ //So far we have only added groups to the annotationHash,\r
+ //the idea is in the future properties can be added to\r
+ //alignments, other annotations etc\r
+ SequenceGroup sg = (SequenceGroup)annotationsHash.get(st.nextToken());\r
+\r
+ if(sg!=null)\r
+ {\r
+ String keyValue, key, value;\r
+ while(st.hasMoreTokens())\r
+ {\r
+ keyValue = st.nextToken();\r
+ key = keyValue.substring(0,keyValue.indexOf("="));\r
+ value=keyValue.substring(keyValue.indexOf("=")+1);\r
+\r
+ if(key.equalsIgnoreCase("description"))\r
+ sg.setDescription(value);\r
+ else if(key.equalsIgnoreCase("colour"))\r
+ sg.cs = ColourSchemeProperty.getColour(al, value);\r
+ else if (key.equalsIgnoreCase("pidThreshold"))\r
+ {\r
+ sg.cs.setThreshold(Integer.parseInt(value), true);\r
+\r
+ }\r
+ else if (key.equalsIgnoreCase("consThreshold"))\r
+ {\r
+ sg.cs.setConservationInc(Integer.parseInt(value));\r
+ Conservation c = new Conservation("Group",\r
+ ResidueProperties.propHash, 3,\r
+ sg.getSequences(null),\r
+ sg.getStartRes(),\r
+ sg.getEndRes() + 1);\r
+\r
+ c.calculate();\r
+ c.verdict(false, 25);\r
+\r
+ sg.cs.setConservation(c);\r
+\r
+ }\r
+ else if (key.equalsIgnoreCase("outlineColour"))\r
+ {\r
+ sg.setOutlineColour(new UserColourScheme(value).findColour('A'));\r
+ }\r
+ else if (key.equalsIgnoreCase("displayBoxes"))\r
+ sg.setDisplayBoxes( Boolean.valueOf(value).booleanValue() );\r
+ else if (key.equalsIgnoreCase("displayText"))\r
+ sg.setDisplayText( Boolean.valueOf(value).booleanValue() );\r
+ else if (key.equalsIgnoreCase("colourText"))\r
+ sg.setColourText( Boolean.valueOf(value).booleanValue() );\r
+ else if (key.equalsIgnoreCase("textCol1"))\r
+ {\r
+ sg.textColour = new UserColourScheme(value).findColour('A');\r
+ }\r
+ else if (key.equalsIgnoreCase("textCol2"))\r
+ {\r
+ sg.textColour2 = new UserColourScheme(value).findColour('A');\r
+ }\r
+ else if (key.equalsIgnoreCase("textColThreshold"))\r
+ sg.thresholdTextColour = Integer.parseInt(value);\r
+\r
+ sg.recalcConservation();\r
+ }\r
+ }\r
}\r
}\r