From d70d7e5bc8da1189f44709b6ec59ea1e23f6f557 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 29 Jan 2007 17:39:59 +0000 Subject: [PATCH] SequenceGroup parsing added to annotation file --- src/jalview/io/AnnotationFile.java | 131 ++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 2291f39..a7c67cd 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -22,8 +22,8 @@ package jalview.io; import java.io.*; import jalview.datamodel.*; import java.util.*; -import jalview.schemes.UserColourScheme; import java.net.URL; +import jalview.schemes.*; public class AnnotationFile @@ -164,6 +164,9 @@ public class AnnotationFile return text.toString(); } + + SequenceI refSeq = null; + Hashtable annotationsHash = new Hashtable(); public boolean readAnnotationFile(AlignmentI al, String file, String protocol) @@ -195,7 +198,6 @@ public class AnnotationFile String line, label, description, token; int graphStyle, index; - SequenceI refSeq = null; int refSeqIndex = 1; int existingAnnotations = 0; if(al.getAlignmentAnnotation()!=null) @@ -242,20 +244,20 @@ public class AnnotationFile continue; } - if(token.equalsIgnoreCase("COMBINE") ) + else if(token.equalsIgnoreCase("COMBINE") ) { combineAnnotations(al, st); continue; } - if (token.equalsIgnoreCase("GRAPHLINE")) + else if (token.equalsIgnoreCase("GRAPHLINE")) { addLine(al, st); continue; } - if(token.equalsIgnoreCase("SEQUENCE_REF") ) + else if(token.equalsIgnoreCase("SEQUENCE_REF") ) { refSeq = al.findName(st.nextToken()); try{ @@ -274,6 +276,18 @@ public class AnnotationFile continue; } + else if(token.equalsIgnoreCase("SEQUENCE_GROUP")) + { + addGroup(al, st); + continue; + } + + else if(token.equalsIgnoreCase("PROPERTIES")) + { + addProperties(al, st); + continue; + } + graphStyle = AlignmentAnnotation.getGraphValueFromString(token); label = st.nextToken(); @@ -460,6 +474,113 @@ 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), false);// + else if (key.equalsIgnoreCase("outlineColour")) + { + sg.setOutlineColour(new UserColourScheme(value).findColour('A')); + } + + //Boolean.valueOf(string).booleanValue(); + 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); + + } + } } } -- 1.7.10.2