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";
64 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
65 WsParamSetI preset, List<Argument> paramset)
67 super(sh, alignFrame, preset, paramset);
70 methodName = sh.serviceType;
74 nucleotidesAllowed = false;
75 proteinAllowed = true;
80 public String getServiceActionText()
82 return "Submitting amino acid sequences for disorder prediction.";
86 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
88 return (seqs.size() > 0);
91 private static Map<String, Map<String, String[]>> featureMap;
93 private static Map<String, Map<String, Map<String, Object>>> annotMap;
95 private static String DONTCOMBINE = "DONTCOMBINE";
97 private static String INVISIBLE = "INVISIBLE";
100 // TODO: turn this into some kind of configuration file that's a bit easier
102 featureMap = new HashMap<String, Map<String, String[]>>();
103 Map<String, String[]> fmap;
104 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
105 fmap = new HashMap<String, String[]>());
106 fmap.put("Glob", new String[] { "Globular Domain",
107 "Predicted globular domain" });
108 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
109 fmap = new HashMap<String, String[]>());
110 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
111 fmap = new HashMap<String, String[]>());
112 fmap.put("REM465", new String[] { "REM465", "Missing density" });
113 fmap.put("HOTLOOPS", new String[] { "HOTLOOPS", "Flexible loops" });
114 fmap.put("COILS", new String[] { "COILS", "Random coil" });
115 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
116 fmap = new HashMap<String, String[]>());
117 fmap.put("GlobDoms", new String[] { "Globular Domain",
118 "Predicted globular domain" });
119 fmap.put("Disorder", new String[] { "Protein Disorder",
120 "Probable unstructured peptide region" });
121 Map<String, Map<String, Object>> amap;
122 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
123 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
124 amap = new HashMap<String, Map<String, Object>>());
125 amap.put("Dydx", new HashMap<String, Object>());
126 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
127 amap.get("Dydx").put(THRESHOLD, new double[] { 1, 0 });
128 amap.get("Dydx").put(RANGE, new float[] { -1, +1 });
130 amap.put("SmoothedScore", new HashMap<String, Object>());
131 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
132 amap.put("RawScore", new HashMap<String, Object>());
133 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
134 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
135 amap = new HashMap<String, Map<String, Object>>());
136 amap.put("COILS", new HashMap<String, Object>());
137 amap.put("HOTLOOPS", new HashMap<String, Object>());
138 amap.put("REM465", new HashMap<String, Object>());
139 amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516 });
140 amap.get("COILS").put(RANGE, new float[] { 0, 1 });
142 amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6 });
143 amap.get("HOTLOOPS").put(RANGE, new float[] { 0, 1 });
144 amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204 });
145 amap.get("REM465").put(RANGE, new float[] { 0, 1 });
147 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
148 amap = new HashMap<String, Map<String, Object>>());
149 amap.put("Long", new HashMap<String, Object>());
150 amap.put("Short", new HashMap<String, Object>());
151 amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5 });
152 amap.get("Long").put(RANGE, new float[] { 0, 1 });
153 amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5 });
154 amap.get("Short").put(RANGE, new float[] { 0, 1 });
155 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
156 amap = new HashMap<String, Map<String, Object>>());
157 amap.put("JRonn", new HashMap<String, Object>());
158 amap.get("JRonn").put(THRESHOLD, new double[] { 1, 0.5 });
159 amap.get("JRonn").put(RANGE, new float[] { 0, 1 });
163 public void updateResultAnnotation(boolean immediate)
166 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
168 Map<String, String[]> featureTypeMap = featureMap
169 .get(service.serviceType);
170 Map<String, Map<String, Object>> annotTypeMap = annotMap
171 .get(service.serviceType);
172 boolean dispFeatures = false;
173 Map<String, Object> fc = new Hashtable<String, Object>();
174 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
176 * grouping for any annotation rows created
179 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
181 for (AlignmentAnnotation ala : alignViewport.getAlignment()
182 .getAlignmentAnnotation())
184 if (ala.graphGroup > graphGroup)
186 graphGroup = ala.graphGroup;
191 for (String seqId : seqNames.keySet())
193 boolean sameGroup = false;
194 SequenceI dseq, aseq, seq = seqNames.get(seqId);
195 int base = seq.findPosition(start) - 1;
197 while ((dseq = seq).getDatasetSequence() != null)
199 seq = seq.getDatasetSequence();
201 ScoreHolder scores = null;
204 scores = scoremanager.getAnnotationForSequence(seqId);
205 } catch (Exception q)
208 .info("Couldn't recover disorder prediction for sequence "
210 + "(Prediction name was "
213 + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
215 float last = Float.NaN, val = Float.NaN;
216 int lastAnnot = ourAnnot.size();
217 if (scores != null && scores.scores != null)
219 for (Score scr : scores.scores)
222 if (scr.getRanges() != null && scr.getRanges().size() > 0)
224 Iterator<Float> vals = scr.getScores().iterator();
225 // make features on sequence
226 for (Range rn : scr.getRanges())
230 String[] type = featureTypeMap.get(scr.getMethod());
233 // create a default type for this feature
234 type = new String[] {
235 typeName + " (" + scr.getMethod() + ")",
236 service.getActionText() };
240 val = vals.next().floatValue();
241 sf = new SequenceFeature(type[0], type[1],
242 base + rn.from, base + rn.to, val, methodName);
246 sf = new SequenceFeature(type[0], type[1],
247 base + rn.from, base + rn.to, methodName);
249 dseq.addSequenceFeature(sf);
250 if (last != val && !Float.isNaN(last))
252 fc.put(sf.getType(), sf);
260 if (scr.getScores().size() == 0)
264 String typename, calcName;
265 AlignmentAnnotation annot = createAnnotationRowsForScores(
267 typename = service.serviceType + " ("
268 + scr.getMethod() + ")",
269 calcName = service.getServiceTypeURI() + "/"
270 + scr.getMethod(), aseq, base + 1, scr);
271 annot.graph = AlignmentAnnotation.LINE_GRAPH;
273 Map<String, Object> styleMap = (annotTypeMap == null) ? null
274 : annotTypeMap.get(scr.getMethod());
276 annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
277 double[] thrsh = (styleMap == null) ? null
278 : (double[]) styleMap.get(THRESHOLD);
279 float[] range = (styleMap == null) ? null
280 : (float[]) styleMap.get(RANGE);
283 annot.graphMin = range[0];
284 annot.graphMax = range[1];
286 if (styleMap == null || styleMap.get(DONTCOMBINE) == null)
295 annot.graphGroup = graphGroup;
299 annot.description = "<html>" + service.getActionText()
303 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
304 + thrsh[1] + " indicates disorder";
305 annot.threshold = new GraphLine((float) thrsh[1],
306 threshNote, Color.red);
307 annot.description += "<br/>" + threshNote;
309 annot.description += "</html>";
310 Color col = ColorUtils.createColourFromName(typeName
312 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
314 if (annot.annotations[p] != null)
316 annot.annotations[p].colour = col;
319 annot._linecolour = col;
320 // finally, update any dataset annotation
321 replaceAnnotationOnAlignmentWith(annot, typename, calcName,
326 if (lastAnnot + 1 == ourAnnot.size())
328 // remove singleton alignment annotation row
329 ourAnnot.get(lastAnnot).graphGroup = -1;
335 jalview.api.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
336 .cloneFeatureRenderer();
337 for (String ft : fc.keySet())
339 FeatureColourI gc = fr.getFeatureStyle(ft);
340 if (gc.isSimpleColour())
342 // set graduated color as fading to white for minimum, and
343 // autoscaling to values on alignment
344 FeatureColourI ggc = new FeatureColour(Color.white,
345 gc.getColour(), Float.MIN_VALUE, Float.MAX_VALUE);
346 ggc.setAutoScaled(true);
347 fr.setColour(ft, ggc);
350 // TODO: JAL-1150 - create sequence feature settings API for defining
351 // styles and enabling/disabling feature overlay on alignment panel
352 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
353 if (af.alignPanel == ap)
355 // only do this if the alignFrame is currently showing this view.
356 af.setShowSeqFeatures(true);
358 ap.paintAlignment(true);
360 if (ourAnnot.size() > 0)
362 // Modify the visible annotation on the alignment viewport with the
363 // new alignment annotation rows created.
364 updateOurAnnots(ourAnnot);
365 ap.adjustAnnotationHeight();
372 public String getCalcId()
374 // Disorder predictions are not dynamically updated so we return null