Make 1.1 compatible
[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     // in the future we could search for the query\r
26     // sequence in the alignment before calling this function.\r
27     SequenceI seqRef = al.getSequenceAt(FirstSeq);\r
28     int width = preds[0].getSequence().length();\r
29     int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();\r
30     if (gapmap.length != width)\r
31     {\r
32       throw (new Exception(\r
33           "Number of residues in supposed query sequence ('" +\r
34           al.getSequenceAt(FirstSeq).getName() + "'\n" +\r
35           al.getSequenceAt(FirstSeq).getSequence() +\r
36           ")\ndiffer from number of prediction sites in prediction (" + width +\r
37           ")"));\r
38     }\r
39 \r
40     AlignmentAnnotation annot;\r
41     Annotation[] annotations = null;\r
42 \r
43     while (i < preds.length)\r
44     {\r
45       String id = preds[i].getName().toUpperCase();\r
46 \r
47       if (id.startsWith("LUPAS") || id.startsWith("JNET") ||\r
48           id.startsWith("JPRED"))\r
49       {\r
50         annotations = new Annotation[al.getWidth()];\r
51 \r
52         if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||\r
53             id.equals("JNETFREQ") || id.equals("JNETHMM") ||\r
54             id.equals("JNETALIGN") || id.equals("JPRED"))\r
55         {\r
56           for (int j = 0; j < width; j++)\r
57           {\r
58             annotations[gapmap[j]] = new Annotation("", "",\r
59                 preds[i].getCharAt(j), 0);\r
60           }\r
61         }\r
62         else if (id.equals("JNETCONF"))\r
63         {\r
64           for (int j = 0; j < width; j++)\r
65           {\r
66             float value = new Float(preds[i].getCharAt(\r
67                 j) + "").floatValue();\r
68             annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
69                 j) + "", "", preds[i].getCharAt(j),\r
70                 value);\r
71           }\r
72         }\r
73         else\r
74         {\r
75           for (int j = 0; j < width; j++)\r
76           {\r
77             annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
78                 j) + "", "", ' ', 0);\r
79           }\r
80         }\r
81 \r
82         if (id.equals("JNETCONF"))\r
83         {\r
84           annot = new AlignmentAnnotation(preds[i].getName(),\r
85                                           "JNet Output", annotations, 0f,\r
86                                           10f,\r
87                                           AlignmentAnnotation.BAR_GRAPH);\r
88         }\r
89         else\r
90         {\r
91           annot = new AlignmentAnnotation(preds[i].getName(),\r
92                                           "JNet Output", annotations);\r
93         }\r
94 \r
95         if (seqRef != null)\r
96         {\r
97           annot.createSequenceMapping(seqRef, 0);\r
98           seqRef.addAlignmentAnnotation(annot);\r
99         }\r
100 \r
101         al.addAnnotation(annot);\r
102 \r
103         if (noMsa)\r
104         {\r
105           al.deleteSequence(preds[i]);\r
106         }\r
107       }\r
108 \r
109       i++;\r
110     }\r
111 \r
112     //Hashtable scores = prediction.getScores();\r
113 \r
114     /*  addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPH"),\r
115                           "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);\r
116 \r
117       addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPB"),\r
118      "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);\r
119 \r
120       addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPC"),\r
121                           "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);\r
122      */\r
123 \r
124   }\r
125 }\r