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;
23 import jalview.api.FeatureColourI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.GraphLine;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.AlignFrame;
30 import jalview.schemes.FeatureColour;
31 import jalview.util.ColorUtils;
32 import jalview.ws.jws2.jabaws2.Jws2Instance;
33 import jalview.ws.params.WsParamSetI;
35 import java.awt.Color;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.Hashtable;
39 import java.util.Iterator;
40 import java.util.List;
43 import compbio.data.sequence.FastaSequence;
44 import compbio.data.sequence.Range;
45 import compbio.data.sequence.Score;
46 import compbio.data.sequence.ScoreManager.ScoreHolder;
47 import compbio.metadata.Argument;
49 public class AADisorderClient extends JabawsCalcWorker
52 private static final String THRESHOLD = "THRESHOLD";
54 private static final String RANGE = "RANGE";
56 private String typeName;
58 private String methodName;
60 // private String groupName;
64 private final static Map<String, Map<String, String[]>> featureMap;
66 private final static Map<String, Map<String, Map<String, Object>>> annotMap;
68 private final static String DONTCOMBINE = "DONTCOMBINE";
70 private final static String INVISIBLE = "INVISIBLE";
74 // TODO: turn this into some kind of configuration file that's a bit easier
76 featureMap = new HashMap<>();
77 Map<String, String[]> fmap;
78 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
79 fmap = new HashMap<>());
82 { "Globular Domain", "Predicted globular domain" });
83 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
84 fmap = new HashMap<>());
85 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
86 fmap = new HashMap<>());
87 fmap.put("REM465", new String[] { "REM465", "Missing density" });
88 fmap.put("HOTLOOPS", new String[] { "HOTLOOPS", "Flexible loops" });
89 fmap.put("COILS", new String[] { "COILS", "Random coil" });
90 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
91 fmap = new HashMap<>());
94 { "Globular Domain", "Predicted globular domain" });
97 { "Protein Disorder", "Probable unstructured peptide region" });
98 Map<String, Map<String, Object>> amap;
99 annotMap = new HashMap<>();
100 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
101 amap = new HashMap<>());
102 amap.put("Dydx", new HashMap<String, Object>());
103 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
104 amap.get("Dydx").put(THRESHOLD, new double[] { 1, 0 });
105 amap.get("Dydx").put(RANGE, new float[] { -1, +1 });
107 amap.put("SmoothedScore", new HashMap<String, Object>());
108 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
109 amap.put("RawScore", new HashMap<String, Object>());
110 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
111 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
112 amap = new HashMap<>());
113 amap.put("COILS", new HashMap<String, Object>());
114 amap.put("HOTLOOPS", new HashMap<String, Object>());
115 amap.put("REM465", new HashMap<String, Object>());
116 amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516 });
117 amap.get("COILS").put(RANGE, new float[] { 0, 1 });
119 amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6 });
120 amap.get("HOTLOOPS").put(RANGE, new float[] { 0, 1 });
121 amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204 });
122 amap.get("REM465").put(RANGE, new float[] { 0, 1 });
124 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
125 amap = new HashMap<>());
126 amap.put("Long", new HashMap<String, Object>());
127 amap.put("Short", new HashMap<String, Object>());
128 amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5 });
129 amap.get("Long").put(RANGE, new float[] { 0, 1 });
130 amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5 });
131 amap.get("Short").put(RANGE, new float[] { 0, 1 });
132 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
133 amap = new HashMap<>());
134 amap.put("JRonn", new HashMap<String, Object>());
135 amap.get("JRonn").put(THRESHOLD, new double[] { 1, 0.5 });
136 amap.get("JRonn").put(RANGE, new float[] { 0, 1 });
139 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
140 WsParamSetI thePreset, List<Argument> paramset)
142 super(sh, alignFrame, thePreset, paramset);
144 typeName = sh.action;
145 methodName = sh.serviceType;
149 nucleotidesAllowed = false;
150 proteinAllowed = true;
155 public String getServiceActionText()
157 return "Submitting amino acid sequences for disorder prediction.";
161 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
163 return (seqs.size() > 0);
167 public void updateResultAnnotation(boolean immediate)
170 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
172 Map<String, String[]> featureTypeMap = featureMap
173 .get(service.serviceType);
174 Map<String, Map<String, Object>> annotTypeMap = annotMap
175 .get(service.serviceType);
176 boolean dispFeatures = false;
177 Map<String, Object> fc = new Hashtable<>();
178 List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
180 * grouping for any annotation rows created
183 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
185 for (AlignmentAnnotation ala : alignViewport.getAlignment()
186 .getAlignmentAnnotation())
188 if (ala.graphGroup > graphGroup)
190 graphGroup = ala.graphGroup;
195 for (String seqId : seqNames.keySet())
197 boolean sameGroup = false;
198 SequenceI dseq, aseq, seq = seqNames.get(seqId);
199 int base = seq.findPosition(start) - 1;
201 while ((dseq = seq).getDatasetSequence() != null)
203 seq = seq.getDatasetSequence();
205 ScoreHolder scores = null;
208 scores = scoremanager.getAnnotationForSequence(seqId);
209 } catch (Exception q)
212 .info("Couldn't recover disorder prediction for sequence "
213 + seq.getName() + "(Prediction name was " + seqId
215 + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
217 float last = Float.NaN, val = Float.NaN;
218 int lastAnnot = ourAnnot.size();
219 if (scores != null && scores.scores != null)
221 for (Score scr : scores.scores)
224 if (scr.getRanges() != null && scr.getRanges().size() > 0)
226 Iterator<Float> vals = scr.getScores().iterator();
227 // make features on sequence
228 for (Range rn : scr.getRanges())
232 String[] type = featureTypeMap.get(scr.getMethod());
235 // create a default type for this feature
236 type = new String[] {
237 typeName + " (" + scr.getMethod() + ")",
238 service.getActionText() };
242 val = vals.next().floatValue();
243 sf = new SequenceFeature(type[0], type[1], base + rn.from,
244 base + rn.to, val, methodName);
248 sf = new SequenceFeature(type[0], type[1], base + rn.from,
249 base + rn.to, methodName);
251 dseq.addSequenceFeature(sf);
252 if (last != val && !Float.isNaN(last))
254 fc.put(sf.getType(), sf);
262 if (scr.getScores().size() == 0)
266 String typename, calcName;
267 AlignmentAnnotation annot = createAnnotationRowsForScores(
269 typename = service.serviceType + " ("
270 + scr.getMethod() + ")",
271 calcName = service.getServiceTypeURI() + "/"
273 aseq, base + 1, scr);
274 annot.graph = AlignmentAnnotation.LINE_GRAPH;
276 Map<String, Object> styleMap = (annotTypeMap == null) ? null
277 : annotTypeMap.get(scr.getMethod());
279 annot.visible = (styleMap == null
280 || styleMap.get(INVISIBLE) == null);
281 double[] thrsh = (styleMap == null) ? null
282 : (double[]) styleMap.get(THRESHOLD);
283 float[] range = (styleMap == null) ? null
284 : (float[]) styleMap.get(RANGE);
287 annot.graphMin = range[0];
288 annot.graphMax = range[1];
290 if (styleMap == null || styleMap.get(DONTCOMBINE) == null)
299 annot.graphGroup = graphGroup;
303 annot.description = "<html>" + service.getActionText()
307 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
308 + thrsh[1] + " indicates disorder";
309 annot.threshold = new GraphLine((float) thrsh[1],
310 threshNote, Color.red);
311 annot.description += "<br/>" + threshNote;
313 annot.description += "</html>";
314 Color col = ColorUtils
315 .createColourFromName(typeName + scr.getMethod());
316 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
318 if (annot.annotations[p] != null)
320 annot.annotations[p].colour = col;
323 annot._linecolour = col;
324 // finally, update any dataset annotation
325 replaceAnnotationOnAlignmentWith(annot, typename, calcName,
330 if (lastAnnot + 1 == ourAnnot.size())
332 // remove singleton alignment annotation row
333 ourAnnot.get(lastAnnot).graphGroup = -1;
339 jalview.api.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
340 .cloneFeatureRenderer();
341 for (String ft : fc.keySet())
343 FeatureColourI gc = fr.getFeatureStyle(ft);
344 if (gc.isSimpleColour())
346 // set graduated color as fading to white for minimum, and
347 // autoscaling to values on alignment
348 FeatureColourI ggc = new FeatureColour(gc.getColour(),
349 Color.white, gc.getColour(), Color.white,
350 Float.MIN_VALUE, Float.MAX_VALUE);
351 ggc.setAutoScaled(true);
352 fr.setColour(ft, ggc);
355 // TODO: JAL-1150 - create sequence feature settings API for defining
356 // styles and enabling/disabling feature overlay on alignment panel
357 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
358 if (af.alignPanel == ap)
360 // only do this if the alignFrame is currently showing this view.
361 af.setShowSeqFeatures(true);
364 if (ourAnnot.size() > 0)
366 // Modify the visible annotation on the alignment viewport with the
367 // new alignment annotation rows created.
368 updateOurAnnots(ourAnnot);
369 ap.adjustAnnotationHeight();
370 ap.paintAlignment(true, true);
377 public String getCalcId()
379 // Disorder predictions are not dynamically updated so we return null