SequenceGroup parsing added to annotation file
authoramwaterhouse <Andrew Waterhouse>
Mon, 29 Jan 2007 17:39:59 +0000 (17:39 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 29 Jan 2007 17:39:59 +0000 (17:39 +0000)
src/jalview/io/AnnotationFile.java

index 2291f39..a7c67cd 100755 (executable)
@@ -22,8 +22,8 @@ package jalview.io;
 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
 \r
 \r
 public class AnnotationFile\r
@@ -164,6 +164,9 @@ public class AnnotationFile
     return text.toString();\r
   }\r
 \r
+\r
+  SequenceI refSeq = null;\r
+  Hashtable annotationsHash = new Hashtable();\r
   public boolean readAnnotationFile(AlignmentI al,\r
                                     String file,\r
                                     String protocol)\r
@@ -195,7 +198,6 @@ public class AnnotationFile
 \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
@@ -242,20 +244,20 @@ public class AnnotationFile
           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
@@ -274,6 +276,18 @@ public class AnnotationFile
           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 = st.nextToken();\r
@@ -460,6 +474,113 @@ public class AnnotationFile
     }\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
+\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
+          sg.cs.setThreshold(Integer.parseInt(value), false);//\r
+        else if (key.equalsIgnoreCase("outlineColour"))\r
+         {\r
+           sg.setOutlineColour(new UserColourScheme(value).findColour('A'));\r
+         }\r
+\r
+         //Boolean.valueOf(string).booleanValue();\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
+      }\r
+    }\r
   }\r
 }\r