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.
21 package jalview.ws.jws2.jabaws2;
23 import jalview.analysis.AlignmentAnnotationUtils;
24 import jalview.api.FeatureColourI;
25 import jalview.bin.Cache;
26 import jalview.bin.Console;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.GraphLine;
30 import jalview.datamodel.SequenceFeature;
31 import jalview.datamodel.SequenceI;
32 import jalview.datamodel.features.FeatureMatcherSetI;
33 import jalview.schemes.FeatureColour;
34 import jalview.util.ColorUtils;
36 import java.awt.Color;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.Hashtable;
40 import java.util.Iterator;
41 import java.util.List;
44 import compbio.data.sequence.Range;
45 import compbio.data.sequence.Score;
46 import compbio.data.sequence.ScoreManager.ScoreHolder;
48 public class AADisorderClient extends JabawsAnnotationInstance
50 // static configuration
51 public static String getServiceActionText()
53 return "Submitting amino acid sequences for disorder prediction.";
56 // minSeq = 1; protein only, no gaps
59 public AADisorderClient(Jws2Instance handle)
66 List<AlignmentAnnotation> annotationFromScoreManager(AlignmentI seqs,
67 Map<String, FeatureColourI> featureColours,
68 Map<String, FeatureMatcherSetI> featureFilters)
71 Map<String, String[]> featureTypeMap = featureMap.get(our.getName());
72 Map<String, Map<String, Object>> annotTypeMap = annotMap
74 boolean dispFeatures = false;
75 Map<String, SequenceFeature> fc = new Hashtable<>(),
76 fex = new Hashtable();
77 List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
78 int graphGroup = 1, lastAnnot = 0;
80 for (SequenceI seq : seqs.getSequences())
82 String seqId = seq.getName();
83 boolean sameGroup = false;
85 int base = seq.findPosition(0) - 1;
87 while ((dseq = seq).getDatasetSequence() != null)
89 seq = seq.getDatasetSequence();
91 ScoreHolder scores = null;
94 scores = scoremanager.getAnnotationForSequence(seqId);
97 Console.info("Couldn't recover disorder prediction for sequence "
98 + seq.getName() + "(Prediction name was " + seqId + ")"
99 + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.",
102 float last = Float.NaN, val = Float.NaN;
103 if (scores != null && scores.scores != null)
105 for (Score scr : scores.scores)
108 if (scr.getRanges() != null && scr.getRanges().size() > 0)
110 Iterator<Float> vals = scr.getScores().iterator();
111 // make features on sequence
112 for (Range rn : scr.getRanges())
114 // TODO: Create virtual feature settings
116 String[] type = featureTypeMap.get(scr.getMethod());
119 // create a default type for this feature
120 type = new String[] {
121 typeName + " (" + scr.getMethod() + ")",
122 our.getActionText() };
126 val = vals.next().floatValue();
127 sf = new SequenceFeature(type[0], type[1], base + rn.from,
128 base + rn.to, val, methodName);
132 sf = new SequenceFeature(type[0], type[1], base + rn.from,
133 base + rn.to, methodName);
135 dseq.addSequenceFeature(sf);
136 // mark feature as requiring a graduated colourscheme if has
138 if (!Float.isNaN(last) && !Float.isNaN(val) && last != val)
140 fc.put(sf.getType(), sf);
143 fex.put(sf.getType(), sf);
151 if (scr.getScores().size() == 0)
155 String typename, calcName;
156 AlignmentAnnotation annot = createAnnotationRowsForScores(
157 seqs, null, ourAnnot,
158 typename = our.getName() + " (" + scr.getMethod() + ")",
159 calcName = our.getNameURI() + "/" + scr.getMethod(),
160 aseq, base + 1, scr);
161 annot.graph = AlignmentAnnotation.LINE_GRAPH;
163 Map<String, Object> styleMap = (annotTypeMap == null) ? null
164 : annotTypeMap.get(scr.getMethod());
166 annot.visible = (styleMap == null
167 || styleMap.get(INVISIBLE) == null);
168 double[] thrsh = (styleMap == null) ? null
169 : (double[]) styleMap.get(THRESHOLD);
170 float[] range = (styleMap == null) ? null
171 : (float[]) styleMap.get(RANGE);
174 annot.graphMin = range[0];
175 annot.graphMax = range[1];
177 if (styleMap == null || styleMap.get(DONTCOMBINE) == null)
186 annot.graphGroup = graphGroup;
190 annot.description = "<html>" + our.getActionText()
194 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
195 + thrsh[1] + " indicates disorder";
196 annot.threshold = new GraphLine((float) thrsh[1], threshNote,
198 annot.description += "<br/>" + threshNote;
200 annot.description += "</html>";
201 Color col = ColorUtils
202 .createColourFromName(typeName + scr.getMethod());
203 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
205 if (annot.annotations[p] != null)
207 annot.annotations[p].colour = col;
210 annot._linecolour = col;
211 // finally, update any dataset annotation
212 AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(annot,
217 if (lastAnnot + 1 == ourAnnot.size())
219 // remove singleton alignment annotation row
220 ourAnnot.get(lastAnnot).graphGroup = -1;
226 // TODO: virtual feature settings
227 // feature colours need to merged with current viewport's colours
228 // simple feature colours promoted to colour-by-score ranges using
229 // currently assigned or created feature colour
230 for (String ft : fex.keySet())
232 Color col = ColorUtils.createColourFromName(ft);
233 // set graduated color as fading to white for minimum, and
234 // autoscaling to values on alignment
237 if (fc.get(ft) != null)
239 ggc = new FeatureColour(col, Color.white, col,
241 Color.white, Float.MIN_VALUE, Float.MAX_VALUE);
242 ggc.setAutoScaled(true);
246 ggc = new FeatureColour(col);
248 featureColours.put(ft, ggc);
256 private static final String THRESHOLD = "THRESHOLD";
258 private static final String RANGE = "RANGE";
266 private static Map<String, Map<String, String[]>> featureMap;
268 private static Map<String, Map<String, Map<String, Object>>> annotMap;
270 private static String DONTCOMBINE = "DONTCOMBINE";
272 private static String INVISIBLE = "INVISIBLE";
275 // TODO: turn this into some kind of configuration file that's a bit easier
277 featureMap = new HashMap<>();
278 Map<String, String[]> fmap;
279 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
280 fmap = new HashMap<>());
283 { "Globular Domain", "Predicted globular domain" });
284 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
285 fmap = new HashMap<>());
286 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
287 fmap = new HashMap<>());
288 fmap.put("REM465", new String[] { "REM465", "Missing density" });
289 fmap.put("HOTLOOPS", new String[] { "HOTLOOPS", "Flexible loops" });
290 fmap.put("COILS", new String[] { "COILS", "Random coil" });
291 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
292 fmap = new HashMap<>());
295 { "Globular Domain", "Predicted globular domain" });
298 { "Protein Disorder", "Probable unstructured peptide region" });
299 Map<String, Map<String, Object>> amap;
300 annotMap = new HashMap<>();
301 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
302 amap = new HashMap<>());
303 amap.put("Dydx", new HashMap<String, Object>());
304 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
305 amap.get("Dydx").put(THRESHOLD, new double[] { 1, 0 });
306 amap.get("Dydx").put(RANGE, new float[] { -1, +1 });
308 amap.put("SmoothedScore", new HashMap<String, Object>());
309 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
310 amap.put("RawScore", new HashMap<String, Object>());
311 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
312 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
313 amap = new HashMap<>());
314 amap.put("COILS", new HashMap<String, Object>());
315 amap.put("HOTLOOPS", new HashMap<String, Object>());
316 amap.put("REM465", new HashMap<String, Object>());
317 amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516 });
318 amap.get("COILS").put(RANGE, new float[] { 0, 1 });
320 amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6 });
321 amap.get("HOTLOOPS").put(RANGE, new float[] { 0, 1 });
322 amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204 });
323 amap.get("REM465").put(RANGE, new float[] { 0, 1 });
325 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
326 amap = new HashMap<>());
327 amap.put("Long", new HashMap<String, Object>());
328 amap.put("Short", new HashMap<String, Object>());
329 amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5 });
330 amap.get("Long").put(RANGE, new float[] { 0, 1 });
331 amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5 });
332 amap.get("Short").put(RANGE, new float[] { 0, 1 });
333 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
334 amap = new HashMap<>());
335 amap.put("JRonn", new HashMap<String, Object>());
336 amap.get("JRonn").put(THRESHOLD, new double[] { 1, 0.5 });
337 amap.get("JRonn").put(RANGE, new float[] { 0, 1 });