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.bin.Cache;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.GraphLine;
26 import jalview.datamodel.SequenceFeature;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.AlignFrame;
29 import jalview.schemes.GraduatedColor;
30 import jalview.schemes.UserColourScheme;
31 import jalview.ws.jws2.jabaws2.Jws2Instance;
32 import jalview.ws.params.WsParamSetI;
34 import java.awt.Color;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.Hashtable;
38 import java.util.Iterator;
39 import java.util.List;
42 import compbio.data.sequence.FastaSequence;
43 import compbio.data.sequence.Range;
44 import compbio.data.sequence.Score;
45 import compbio.data.sequence.ScoreManager.ScoreHolder;
46 import compbio.metadata.Argument;
48 public class AADisorderClient extends JabawsCalcWorker
51 private static final String THRESHOLD = "THRESHOLD";
53 private static final String RANGE = "RANGE";
63 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
64 WsParamSetI preset, List<Argument> paramset)
66 super(sh, alignFrame, preset, paramset);
69 methodName = sh.serviceType;
73 nucleotidesAllowed = false;
74 proteinAllowed = true;
79 public String getServiceActionText()
81 return "Submitting amino acid sequences for disorder prediction.";
85 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
87 return (seqs.size() > 0);
90 private static Map<String, Map<String, String[]>> featureMap;
92 private static Map<String, Map<String, Map<String, Object>>> annotMap;
94 private static String DONTCOMBINE = "DONTCOMBINE";
96 private static String INVISIBLE = "INVISIBLE";
99 // TODO: turn this into some kind of configuration file that's a bit easier
101 featureMap = new HashMap<String, Map<String, String[]>>();
102 Map<String, String[]> fmap;
103 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
104 fmap = new HashMap<String, String[]>());
105 fmap.put("Glob", new String[] { "Globular Domain",
106 "Predicted globular domain" });
107 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
108 fmap = new HashMap<String, String[]>());
109 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
110 fmap = new HashMap<String, String[]>());
111 fmap.put("REM465", new String[] { "REM465", "Missing density" });
112 fmap.put("HOTLOOPS", new String[] { "HOTLOOPS", "Flexible loops" });
113 fmap.put("COILS", new String[] { "COILS", "Random coil" });
114 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
115 fmap = new HashMap<String, String[]>());
116 fmap.put("GlobDoms", new String[] { "Globular Domain",
117 "Predicted globular domain" });
118 fmap.put("Disorder", new String[] { "Protein Disorder",
119 "Probable unstructured peptide region" });
120 Map<String, Map<String, Object>> amap;
121 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
122 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
123 amap = new HashMap<String, Map<String, Object>>());
124 amap.put("Dydx", new HashMap<String, Object>());
125 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
126 amap.get("Dydx").put(THRESHOLD, new double[] { 1, 0 });
127 amap.get("Dydx").put(RANGE, new float[] { -1, +1 });
129 amap.put("SmoothedScore", new HashMap<String, Object>());
130 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
131 amap.put("RawScore", new HashMap<String, Object>());
132 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
133 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
134 amap = new HashMap<String, Map<String, Object>>());
135 amap.put("COILS", new HashMap<String, Object>());
136 amap.put("HOTLOOPS", new HashMap<String, Object>());
137 amap.put("REM465", new HashMap<String, Object>());
138 amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516 });
139 amap.get("COILS").put(RANGE, new float[] { 0, 1 });
141 amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6 });
142 amap.get("HOTLOOPS").put(RANGE, new float[] { 0, 1 });
143 amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204 });
144 amap.get("REM465").put(RANGE, new float[] { 0, 1 });
146 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
147 amap = new HashMap<String, Map<String, Object>>());
148 amap.put("Long", new HashMap<String, Object>());
149 amap.put("Short", new HashMap<String, Object>());
150 amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5 });
151 amap.get("Long").put(RANGE, new float[] { 0, 1 });
152 amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5 });
153 amap.get("Short").put(RANGE, new float[] { 0, 1 });
154 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
155 amap = new HashMap<String, Map<String, Object>>());
156 amap.put("JRonn", new HashMap<String, Object>());
157 amap.get("JRonn").put(THRESHOLD, new double[] { 1, 0.5 });
158 amap.get("JRonn").put(RANGE, new float[] { 0, 1 });
162 public void updateResultAnnotation(boolean immediate)
165 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
167 Map<String, String[]> featureTypeMap = featureMap
168 .get(service.serviceType);
169 Map<String, Map<String, Object>> annotTypeMap = annotMap
170 .get(service.serviceType);
171 boolean dispFeatures = false;
172 Map<String, Object> fc = new Hashtable<String, Object>();
173 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
175 * grouping for any annotation rows created
178 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
180 for (AlignmentAnnotation ala : alignViewport.getAlignment()
181 .getAlignmentAnnotation())
183 if (ala.graphGroup > graphGroup)
185 graphGroup = ala.graphGroup;
190 for (String seqId : seqNames.keySet())
192 boolean sameGroup = false;
193 SequenceI dseq, aseq, seq = seqNames.get(seqId);
194 int base = seq.findPosition(start) - 1;
196 while ((dseq = seq).getDatasetSequence() != null)
198 seq = seq.getDatasetSequence();
200 ScoreHolder scores = null;
203 scores = scoremanager.getAnnotationForSequence(seqId);
204 } catch (Exception q)
207 .info("Couldn't recover disorder prediction for sequence "
209 + "(Prediction name was "
212 + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
214 float last = Float.NaN, val = Float.NaN;
215 int lastAnnot = ourAnnot.size();
216 if (scores != null && scores.scores != null)
218 for (Score scr : scores.scores)
221 if (scr.getRanges() != null && scr.getRanges().size() > 0)
223 Iterator<Float> vals = scr.getScores().iterator();
224 // make features on sequence
225 for (Range rn : scr.getRanges())
229 String[] type = featureTypeMap.get(scr.getMethod());
232 // create a default type for this feature
233 type = new String[] {
234 typeName + " (" + scr.getMethod() + ")",
235 service.getActionText() };
239 sf = new SequenceFeature(type[0], type[1],
240 base + rn.from, base + rn.to, val = vals.next()
241 .floatValue(), methodName);
245 sf = new SequenceFeature(type[0], type[1], null, base
246 + rn.from, base + rn.to, methodName);
248 dseq.addSequenceFeature(sf);
249 if (last != val && !Float.isNaN(last))
251 fc.put(sf.getType(), sf);
259 if (scr.getScores().size() == 0)
263 String typename, calcName;
264 AlignmentAnnotation annot = createAnnotationRowsForScores(
266 typename = service.serviceType + " ("
267 + scr.getMethod() + ")",
268 calcName = service.getServiceTypeURI() + "/"
269 + scr.getMethod(), aseq, base + 1, scr);
270 annot.graph = AlignmentAnnotation.LINE_GRAPH;
272 Map<String, Object> styleMap = (annotTypeMap == null) ? null
273 : annotTypeMap.get(scr.getMethod());
275 annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
276 double[] thrsh = (styleMap == null) ? null
277 : (double[]) styleMap.get(THRESHOLD);
278 float[] range = (styleMap == null) ? null
279 : (float[]) styleMap.get(RANGE);
282 annot.graphMin = range[0];
283 annot.graphMax = range[1];
285 if (styleMap == null || styleMap.get(DONTCOMBINE) == null)
294 annot.graphGroup = graphGroup;
298 annot.description = "<html>" + service.getActionText()
302 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
303 + thrsh[1] + " indicates disorder";
304 annot.threshold = new GraphLine((float) thrsh[1],
305 threshNote, Color.red);
306 annot.description += "<br/>" + threshNote;
308 annot.description += "</html>";
309 Color col = new UserColourScheme(typeName)
310 .createColourFromName(typeName + scr.getMethod());
311 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
313 if (annot.annotations[p] != null)
315 annot.annotations[p].colour = col;
318 annot._linecolour = col;
319 // finally, update any dataset annotation
320 replaceAnnotationOnAlignmentWith(annot, typename, calcName,
325 if (lastAnnot + 1 == ourAnnot.size())
327 // remove singleton alignment annotation row
328 ourAnnot.get(lastAnnot).graphGroup = -1;
334 jalview.api.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
335 .cloneFeatureRenderer();
336 for (String ft : fc.keySet())
338 Object gc = fr.getFeatureStyle(ft);
339 if (gc instanceof Color)
341 // set graduated color as fading to white for minimum, and
342 // autoscaling to values on alignment
343 GraduatedColor ggc = new GraduatedColor(Color.white,
344 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
345 ggc.setAutoScaled(true);
346 fr.setColour(ft, ggc);
349 // TODO: JAL-1150 - create sequence feature settings API for defining
350 // styles and enabling/disabling feature overlay on alignment panel
351 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
352 if (af.alignPanel == ap)
354 // only do this if the alignFrame is currently showing this view.
355 af.setShowSeqFeatures(true);
357 ap.paintAlignment(true);
359 if (ourAnnot.size() > 0)
361 // Modify the visible annotation on the alignment viewport with the
362 // new alignment annotation rows created.
363 updateOurAnnots(ourAnnot);
364 ap.adjustAnnotationHeight();
371 public String getCalcId()
373 // Disorder predictions are not dynamically updated so we return null