jnet file is 1 to 1 mapping
[jalview.git] / src / jalview / io / JnetAnnotationMaker.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */package jalview.io;\r
19 \r
20 import jalview.datamodel.*;\r
21 \r
22 public class JnetAnnotationMaker\r
23 {\r
24   /**\r
25    * adds the annotation parsed by prediction to al.\r
26    * @param prediction JPredFile\r
27    * @param al AlignmentI\r
28    * @param FirstSeq int -\r
29    * @param noMsa boolean\r
30    */\r
31   public static void add_annotation(JPredFile prediction, AlignmentI al,\r
32                                     int FirstSeq, boolean noMsa)\r
33       throws Exception\r
34   {\r
35     int i = 0;\r
36     SequenceI[] preds = prediction.getSeqsAsArray();\r
37     // in the future we could search for the query\r
38     // sequence in the alignment before calling this function.\r
39     SequenceI seqRef = al.getSequenceAt(FirstSeq);\r
40     int width = preds[0].getSequence().length();\r
41     int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();\r
42     if (gapmap.length != width)\r
43     {\r
44       throw (new Exception(\r
45           "Number of residues in supposed query sequence ('" +\r
46           al.getSequenceAt(FirstSeq).getName() + "'\n" +\r
47           al.getSequenceAt(FirstSeq).getSequence() +\r
48           ")\ndiffer from number of prediction sites in prediction (" + width +\r
49           ")"));\r
50     }\r
51 \r
52     AlignmentAnnotation annot;\r
53     Annotation[] annotations = null;\r
54 \r
55     int existingAnnotations = 0;\r
56     if(al.getAlignmentAnnotation()!=null)\r
57        existingAnnotations = al.getAlignmentAnnotation().length;\r
58 \r
59 \r
60     while (i < preds.length)\r
61     {\r
62       String id = preds[i].getName().toUpperCase();\r
63 \r
64       if (id.startsWith("LUPAS") || id.startsWith("JNET") ||\r
65           id.startsWith("JPRED"))\r
66       {\r
67         annotations = new Annotation[al.getWidth()];\r
68 \r
69         if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||\r
70             id.equals("JNETFREQ") || id.equals("JNETHMM") ||\r
71             id.equals("JNETALIGN") || id.equals("JPRED"))\r
72         {\r
73           for (int j = 0; j < width; j++)\r
74           {\r
75             annotations[gapmap[j]] = new Annotation("", "",\r
76                 preds[i].getCharAt(j), 0);\r
77           }\r
78         }\r
79         else if (id.equals("JNETCONF"))\r
80         {\r
81           for (int j = 0; j < width; j++)\r
82           {\r
83             float value = new Float(preds[i].getCharAt(\r
84                 j) + "").floatValue();\r
85             annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
86                 j) + "", "", preds[i].getCharAt(j),\r
87                 value);\r
88           }\r
89         }\r
90         else\r
91         {\r
92           for (int j = 0; j < width; j++)\r
93           {\r
94             annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
95                 j) + "", "", ' ', 0);\r
96           }\r
97         }\r
98 \r
99         if (id.equals("JNETCONF"))\r
100         {\r
101           annot = new AlignmentAnnotation(preds[i].getName(),\r
102                                           "JNet Output", annotations, 0f,\r
103                                           10f,\r
104                                           AlignmentAnnotation.BAR_GRAPH);\r
105         }\r
106         else\r
107         {\r
108           annot = new AlignmentAnnotation(preds[i].getName(),\r
109                                           "JNet Output", annotations);\r
110         }\r
111 \r
112         if (seqRef != null)\r
113         {\r
114           annot.createSequenceMapping(seqRef, 1, true);\r
115           seqRef.addAlignmentAnnotation(annot);\r
116         }\r
117 \r
118         al.addAnnotation(annot);\r
119         al.setAnnotationIndex(annot,\r
120                               al.getAlignmentAnnotation().\r
121                               length - existingAnnotations - 1);\r
122 \r
123         if (noMsa)\r
124         {\r
125           al.deleteSequence(preds[i]);\r
126         }\r
127       }\r
128 \r
129       i++;\r
130     }\r
131 \r
132     //Hashtable scores = prediction.getScores();\r
133 \r
134     /*  addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPH"),\r
135                           "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);\r
136 \r
137       addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPB"),\r
138      "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);\r
139 \r
140       addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPC"),\r
141                           "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);\r
142      */\r
143 \r
144   }\r
145 }\r