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