Refactored code for creating annotation objects from a jnetfile object.
authorjprocter <Jim Procter>
Wed, 17 May 2006 16:48:49 +0000 (16:48 +0000)
committerjprocter <Jim Procter>
Wed, 17 May 2006 16:48:49 +0000 (16:48 +0000)
src/jalview/io/JnetAnnotationMaker.java [new file with mode: 0755]

diff --git a/src/jalview/io/JnetAnnotationMaker.java b/src/jalview/io/JnetAnnotationMaker.java
new file mode 100755 (executable)
index 0000000..9a397d7
--- /dev/null
@@ -0,0 +1,123 @@
+package jalview.io;\r
+\r
+import jalview.datamodel.*;\r
+import java.net.URL;\r
+import java.io.BufferedReader;\r
+import java.io.InputStreamReader;\r
+import java.io.FileReader;\r
+\r
+\r
+public class JnetAnnotationMaker\r
+{\r
+  /**\r
+   * adds the annotation parsed by prediction to al.\r
+   * @param prediction JPredFile\r
+   * @param al AlignmentI\r
+   * @param FirstSeq int -\r
+   * @param noMsa boolean\r
+   */\r
+  public static void add_annotation(JPredFile prediction, AlignmentI al,\r
+                                    int FirstSeq, boolean noMsa)\r
+      throws Exception\r
+  {\r
+    int i = 0;\r
+    SequenceI[] preds = prediction.getSeqsAsArray();\r
+    SequenceI seqRef = al.getSequenceAt(FirstSeq);\r
+    int width = preds[0].getSequence().length();\r
+    int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();\r
+    if (gapmap.length != width)\r
+    {\r
+      throw (new Exception(\r
+          "Number of residues in supposed query sequence ('" +\r
+          al.getSequenceAt(FirstSeq).getName() + "'\n" +\r
+          al.getSequenceAt(FirstSeq).getSequence() +\r
+          ")\ndiffer from number of prediction sites in prediction (" + width +\r
+          ")"));\r
+    }\r
+\r
+    AlignmentAnnotation annot;\r
+    Annotation[] annotations = null;\r
+\r
+    while (i < preds.length)\r
+    {\r
+      String id = preds[i].getName().toUpperCase();\r
+\r
+      if (id.startsWith("LUPAS") || id.startsWith("JNET") ||\r
+          id.startsWith("JPRED"))\r
+      {\r
+        annotations = new Annotation[al.getWidth()];\r
+\r
+        if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||\r
+            id.equals("JNETFREQ") || id.equals("JNETHMM") ||\r
+            id.equals("JNETALIGN") || id.equals("JPRED"))\r
+        {\r
+          for (int j = 0; j < width; j++)\r
+          {\r
+            annotations[gapmap[j]] = new Annotation("", "",\r
+                preds[i].getCharAt(j), 0);\r
+          }\r
+        }\r
+        else if (id.equals("JNETCONF"))\r
+        {\r
+          for (int j = 0; j < width; j++)\r
+          {\r
+            float value = Float.parseFloat(preds[i].getCharAt(\r
+                j) + "");\r
+            annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
+                j) + "", "", preds[i].getCharAt(j),\r
+                value);\r
+          }\r
+        }\r
+        else\r
+        {\r
+          for (int j = 0; j < width; j++)\r
+          {\r
+            annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
+                j) + "", "", ' ', 0);\r
+          }\r
+        }\r
+\r
+        if (id.equals("JNETCONF"))\r
+        {\r
+          annot = new AlignmentAnnotation(preds[i].getName(),\r
+                                          "JNet Output", annotations, 0f,\r
+                                          10f,\r
+                                          AlignmentAnnotation.BAR_GRAPH);\r
+        }\r
+        else\r
+        {\r
+          annot = new AlignmentAnnotation(preds[i].getName(),\r
+                                          "JNet Output", annotations);\r
+        }\r
+\r
+        if (seqRef != null)\r
+        {\r
+          annot.createSequenceMapping(seqRef, 0);\r
+          seqRef.addAlignmentAnnotation(annot);\r
+        }\r
+\r
+        al.addAnnotation(annot);\r
+\r
+        if (noMsa)\r
+        {\r
+          al.deleteSequence(preds[i]);\r
+        }\r
+      }\r
+\r
+      i++;\r
+    }\r
+\r
+    //Hashtable scores = prediction.getScores();\r
+\r
+    /*  addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPH"),\r
+                          "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);\r
+\r
+      addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPB"),\r
+     "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);\r
+\r
+      addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPC"),\r
+                          "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);\r
+     */\r
+\r
+  }\r
+}\r