Refactored code for creating annotation objects from a jnetfile object.
[jalview.git] / src / jalview / io / JnetAnnotationMaker.java
1 package jalview.io;\r
2 \r
3 import jalview.datamodel.*;\r
4 import java.net.URL;\r
5 import java.io.BufferedReader;\r
6 import java.io.InputStreamReader;\r
7 import java.io.FileReader;\r
8 \r
9 \r
10 public class JnetAnnotationMaker\r
11 {\r
12   /**\r
13    * adds the annotation parsed by prediction to al.\r
14    * @param prediction JPredFile\r
15    * @param al AlignmentI\r
16    * @param FirstSeq int -\r
17    * @param noMsa boolean\r
18    */\r
19   public static void add_annotation(JPredFile prediction, AlignmentI al,\r
20                                     int FirstSeq, boolean noMsa)\r
21       throws Exception\r
22   {\r
23     int i = 0;\r
24     SequenceI[] preds = prediction.getSeqsAsArray();\r
25     SequenceI seqRef = al.getSequenceAt(FirstSeq);\r
26     int width = preds[0].getSequence().length();\r
27     int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();\r
28     if (gapmap.length != width)\r
29     {\r
30       throw (new Exception(\r
31           "Number of residues in supposed query sequence ('" +\r
32           al.getSequenceAt(FirstSeq).getName() + "'\n" +\r
33           al.getSequenceAt(FirstSeq).getSequence() +\r
34           ")\ndiffer from number of prediction sites in prediction (" + width +\r
35           ")"));\r
36     }\r
37 \r
38     AlignmentAnnotation annot;\r
39     Annotation[] annotations = null;\r
40 \r
41     while (i < preds.length)\r
42     {\r
43       String id = preds[i].getName().toUpperCase();\r
44 \r
45       if (id.startsWith("LUPAS") || id.startsWith("JNET") ||\r
46           id.startsWith("JPRED"))\r
47       {\r
48         annotations = new Annotation[al.getWidth()];\r
49 \r
50         if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||\r
51             id.equals("JNETFREQ") || id.equals("JNETHMM") ||\r
52             id.equals("JNETALIGN") || id.equals("JPRED"))\r
53         {\r
54           for (int j = 0; j < width; j++)\r
55           {\r
56             annotations[gapmap[j]] = new Annotation("", "",\r
57                 preds[i].getCharAt(j), 0);\r
58           }\r
59         }\r
60         else if (id.equals("JNETCONF"))\r
61         {\r
62           for (int j = 0; j < width; j++)\r
63           {\r
64             float value = Float.parseFloat(preds[i].getCharAt(\r
65                 j) + "");\r
66             annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
67                 j) + "", "", preds[i].getCharAt(j),\r
68                 value);\r
69           }\r
70         }\r
71         else\r
72         {\r
73           for (int j = 0; j < width; j++)\r
74           {\r
75             annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
76                 j) + "", "", ' ', 0);\r
77           }\r
78         }\r
79 \r
80         if (id.equals("JNETCONF"))\r
81         {\r
82           annot = new AlignmentAnnotation(preds[i].getName(),\r
83                                           "JNet Output", annotations, 0f,\r
84                                           10f,\r
85                                           AlignmentAnnotation.BAR_GRAPH);\r
86         }\r
87         else\r
88         {\r
89           annot = new AlignmentAnnotation(preds[i].getName(),\r
90                                           "JNet Output", annotations);\r
91         }\r
92 \r
93         if (seqRef != null)\r
94         {\r
95           annot.createSequenceMapping(seqRef, 0);\r
96           seqRef.addAlignmentAnnotation(annot);\r
97         }\r
98 \r
99         al.addAnnotation(annot);\r
100 \r
101         if (noMsa)\r
102         {\r
103           al.deleteSequence(preds[i]);\r
104         }\r
105       }\r
106 \r
107       i++;\r
108     }\r
109 \r
110     //Hashtable scores = prediction.getScores();\r
111 \r
112     /*  addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPH"),\r
113                           "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);\r
114 \r
115       addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPB"),\r
116      "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);\r
117 \r
118       addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPC"),\r
119                           "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);\r
120      */\r
121 \r
122   }\r
123 }\r