2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.util.Locale;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.Annotation;
28 import jalview.datamodel.SequenceI;
29 import jalview.util.MessageManager;
31 public class JnetAnnotationMaker
33 public static void add_annotation(JPredFile prediction, AlignmentI al,
34 int firstSeq, boolean noMsa) throws Exception
36 JnetAnnotationMaker.add_annotation(prediction, al, firstSeq, noMsa,
41 * adds the annotation parsed by prediction to al.
48 * int the index of the sequence to attach the annotation to (usually
53 * mapping from columns in JPredFile prediction to residue number in
54 * al.getSequence(firstSeq)
56 public static void add_annotation(JPredFile prediction, AlignmentI al,
57 int firstSeq, boolean noMsa, int[] delMap) throws Exception
60 SequenceI[] preds = prediction.getSeqsAsArray();
61 // in the future we could search for the query
62 // sequence in the alignment before calling this function.
63 SequenceI seqRef = al.getSequenceAt(firstSeq);
64 int width = preds[0].getLength();
65 int[] gapmap = al.getSequenceAt(firstSeq).gapMap();
66 if ((delMap != null && delMap.length > width)
67 || (delMap == null && gapmap.length != width))
69 throw (new Exception(MessageManager.formatMessage(
70 "exception.number_of_residues_in_query_sequence_differ_from_prediction",
72 { (delMap == null ? ""
73 : MessageManager.getString("label.mapped")),
74 al.getSequenceAt(firstSeq).getName(),
75 al.getSequenceAt(firstSeq).getSequenceAsString(),
76 Integer.valueOf(width).toString() })));
79 AlignmentAnnotation annot;
80 Annotation[] annotations = null;
82 int existingAnnotations = 0;
83 if (al.getAlignmentAnnotation() != null)
85 existingAnnotations = al.getAlignmentAnnotation().length;
88 Annotation[] sol = new Annotation[al.getWidth()];
89 boolean firstsol = true;
91 while (i < preds.length)
93 String id = preds[i].getName().toUpperCase(Locale.ROOT);
95 if (id.startsWith("LUPAS") || id.startsWith("JNET")
96 || id.startsWith("JPRED"))
98 if (id.startsWith("JNETSOL"))
100 float amnt = (id.endsWith("25") ? 3f
101 : id.endsWith("5") ? 6f : 9f);
102 for (int spos = 0; spos < width; spos++)
104 int sposw = (delMap == null) ? gapmap[spos]
105 : gapmap[delMap[spos]];
108 sol[sposw] = new Annotation(0f);
110 if (preds[i].getCharAt(spos) == 'B'
111 && (sol[sposw].value == 0f || sol[sposw].value < amnt))
113 sol[sposw].value = amnt;
120 // some other kind of annotation
121 annotations = new Annotation[al.getWidth()];
123 * if (delMap!=null) { for (int j=0; j<annotations.length; j++)
124 * annotations[j] = new Annotation("","",'',0); }
126 if (id.equals("JNETPRED") || id.equals("JNETPSSM")
127 || id.equals("JNETFREQ") || id.equals("JNETHMM")
128 || id.equals("JNETALIGN") || id.equals("JPRED"))
132 for (int j = 0; j < width; j++)
134 annotations[gapmap[j]] = new Annotation("", "",
135 preds[i].getCharAt(j), 0);
140 for (int j = 0; j < width; j++)
142 annotations[gapmap[delMap[j]]] = new Annotation("", "",
143 preds[i].getCharAt(j), 0);
147 else if (id.equals("JNETCONF"))
151 for (int j = 0; j < width; j++)
153 float value = Float.valueOf(preds[i].getCharAt(j) + "")
155 annotations[gapmap[j]] = new Annotation(
156 preds[i].getCharAt(j) + "", "",
157 preds[i].getCharAt(j), value);
162 for (int j = 0; j < width; j++)
164 float value = Float.valueOf(preds[i].getCharAt(j) + "")
166 annotations[gapmap[delMap[j]]] = new Annotation(
167 preds[i].getCharAt(j) + "", "",
168 preds[i].getCharAt(j), value);
176 for (int j = 0; j < width; j++)
178 annotations[gapmap[j]] = new Annotation(
179 preds[i].getCharAt(j) + "", "", ' ', 0);
184 for (int j = 0; j < width; j++)
186 annotations[gapmap[delMap[j]]] = new Annotation(
187 preds[i].getCharAt(j) + "", "", ' ', 0);
192 if (id.equals("JNETCONF"))
194 annot = new AlignmentAnnotation(preds[i].getName(),
195 "JPred Output", annotations, 0f, 10f,
196 AlignmentAnnotation.BAR_GRAPH);
200 annot = new AlignmentAnnotation(preds[i].getName(),
201 "JPred Output", annotations);
206 annot.createSequenceMapping(seqRef, 1, true);
207 seqRef.addAlignmentAnnotation(annot);
210 al.addAnnotation(annot);
211 al.setAnnotationIndex(annot, al.getAlignmentAnnotation().length
212 - existingAnnotations - 1);
216 al.deleteSequence(preds[i]);
224 // add the solvent accessibility
225 annot = new AlignmentAnnotation("Jnet Burial",
226 "<html>Prediction of Solvent Accessibility<br/>levels are<ul><li>0 - Exposed</li><li>3 - 25% or more S.A. accessible</li><li>6 - 5% or more S.A. accessible</li><li>9 - Buried (<5% exposed)</li></ul>",
227 sol, 0f, 9f, AlignmentAnnotation.BAR_GRAPH);
229 annot.validateRangeAndDisplay();
232 annot.createSequenceMapping(seqRef, 1, true);
233 seqRef.addAlignmentAnnotation(annot);
235 al.addAnnotation(annot);
236 al.setAnnotationIndex(annot,
237 al.getAlignmentAnnotation().length - existingAnnotations - 1);
239 // Hashtable scores = prediction.getScores();
242 * addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
243 * "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
245 * addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
246 * "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
248 * addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
249 * "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);