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.AlignCalcWorkerI;
24 import jalview.api.FeatureColourI;
25 import jalview.bin.Cache;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.GraphLine;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.AlignFrame;
31 import jalview.schemes.FeatureColour;
32 import jalview.schemes.UserColourScheme;
33 import jalview.ws.jws2.jabaws2.Jws2Instance;
34 import jalview.ws.params.WsParamSetI;
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.FastaSequence;
45 import compbio.data.sequence.Range;
46 import compbio.data.sequence.Score;
47 import compbio.data.sequence.ScoreManager.ScoreHolder;
48 import compbio.metadata.Argument;
50 public class AADisorderClient extends JabawsCalcWorker implements
54 private static final String THRESHOLD = "THRESHOLD";
56 private static final String RANGE = "RANGE";
66 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
67 WsParamSetI preset, List<Argument> paramset)
69 super(sh, alignFrame, preset, paramset);
72 methodName = sh.serviceType;
76 nucleotidesAllowed = false;
77 proteinAllowed = true;
82 public String getServiceActionText()
84 return "Submitting amino acid sequences for disorder prediction.";
88 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
90 return (seqs.size() > 0);
93 private static Map<String, Map<String, String[]>> featureMap;
95 private static Map<String, Map<String, Map<String, Object>>> annotMap;
97 private static String DONTCOMBINE = "DONTCOMBINE";
99 private static String INVISIBLE = "INVISIBLE";
102 // TODO: turn this into some kind of configuration file that's a bit easier
104 featureMap = new HashMap<String, Map<String, String[]>>();
105 Map<String, String[]> fmap;
106 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
107 fmap = new HashMap<String, String[]>());
108 fmap.put("Glob", new String[] { "Globular Domain",
109 "Predicted globular domain" });
110 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
111 fmap = new HashMap<String, String[]>());
112 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
113 fmap = new HashMap<String, String[]>());
114 fmap.put("REM465", new String[] { "REM465", "Missing density" });
115 fmap.put("HOTLOOPS", new String[] { "HOTLOOPS", "Flexible loops" });
116 fmap.put("COILS", new String[] { "COILS", "Random coil" });
117 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
118 fmap = new HashMap<String, String[]>());
119 fmap.put("GlobDoms", new String[] { "Globular Domain",
120 "Predicted globular domain" });
121 fmap.put("Disorder", new String[] { "Protein Disorder",
122 "Probable unstructured peptide region" });
123 Map<String, Map<String, Object>> amap;
124 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
125 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
126 amap = new HashMap<String, Map<String, Object>>());
127 amap.put("Dydx", new HashMap<String, Object>());
128 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
129 amap.get("Dydx").put(THRESHOLD, new double[] { 1, 0 });
130 amap.get("Dydx").put(RANGE, new float[] { -1, +1 });
132 amap.put("SmoothedScore", new HashMap<String, Object>());
133 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
134 amap.put("RawScore", new HashMap<String, Object>());
135 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
136 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
137 amap = new HashMap<String, Map<String, Object>>());
138 amap.put("COILS", new HashMap<String, Object>());
139 amap.put("HOTLOOPS", new HashMap<String, Object>());
140 amap.put("REM465", new HashMap<String, Object>());
141 amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516 });
142 amap.get("COILS").put(RANGE, new float[] { 0, 1 });
144 amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6 });
145 amap.get("HOTLOOPS").put(RANGE, new float[] { 0, 1 });
146 amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204 });
147 amap.get("REM465").put(RANGE, new float[] { 0, 1 });
149 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
150 amap = new HashMap<String, Map<String, Object>>());
151 amap.put("Long", new HashMap<String, Object>());
152 amap.put("Short", new HashMap<String, Object>());
153 amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5 });
154 amap.get("Long").put(RANGE, new float[] { 0, 1 });
155 amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5 });
156 amap.get("Short").put(RANGE, new float[] { 0, 1 });
157 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
158 amap = new HashMap<String, Map<String, Object>>());
159 amap.put("JRonn", new HashMap<String, Object>());
160 amap.get("JRonn").put(THRESHOLD, new double[] { 1, 0.5 });
161 amap.get("JRonn").put(RANGE, new float[] { 0, 1 });
165 public void updateResultAnnotation(boolean immediate)
168 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
170 Map<String, String[]> featureTypeMap = featureMap
171 .get(service.serviceType);
172 Map<String, Map<String, Object>> annotTypeMap = annotMap
173 .get(service.serviceType);
174 boolean dispFeatures = false;
175 Map<String, Object> fc = new Hashtable<String, Object>();
176 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
178 * grouping for any annotation rows created
181 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
183 for (AlignmentAnnotation ala : alignViewport.getAlignment()
184 .getAlignmentAnnotation())
186 if (ala.graphGroup > graphGroup)
188 graphGroup = ala.graphGroup;
193 for (String seqId : seqNames.keySet())
195 boolean sameGroup = false;
196 SequenceI dseq, aseq, seq = seqNames.get(seqId);
197 int base = seq.findPosition(start) - 1;
199 while ((dseq = seq).getDatasetSequence() != null)
201 seq = seq.getDatasetSequence();
203 ScoreHolder scores = null;
206 scores = scoremanager.getAnnotationForSequence(seqId);
207 } catch (Exception q)
210 .info("Couldn't recover disorder prediction for sequence "
212 + "(Prediction name was "
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 sf = new SequenceFeature(type[0], type[1],
243 base + rn.from, base + rn.to, val = vals.next()
244 .floatValue(), methodName);
248 sf = new SequenceFeature(type[0], type[1], null, base
249 + rn.from, 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() + "/"
272 + scr.getMethod(), aseq, base + 1, scr);
273 annot.graph = AlignmentAnnotation.LINE_GRAPH;
275 Map<String, Object> styleMap = (annotTypeMap == null) ? null
276 : annotTypeMap.get(scr.getMethod());
278 annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
279 double[] thrsh = (styleMap == null) ? null
280 : (double[]) styleMap.get(THRESHOLD);
281 float[] range = (styleMap == null) ? null
282 : (float[]) styleMap.get(RANGE);
285 annot.graphMin = range[0];
286 annot.graphMax = range[1];
288 if (styleMap == null || styleMap.get(DONTCOMBINE) == null)
297 annot.graphGroup = graphGroup;
301 annot.description = "<html>" + service.getActionText()
305 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
306 + thrsh[1] + " indicates disorder";
307 annot.threshold = new GraphLine((float) thrsh[1],
308 threshNote, Color.red);
309 annot.description += "<br/>" + threshNote;
311 annot.description += "</html>";
312 Color col = UserColourScheme.createColourFromName(typeName
314 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
316 if (annot.annotations[p] != null)
318 annot.annotations[p].colour = col;
321 annot._linecolour = col;
322 // finally, update any dataset annotation
323 replaceAnnotationOnAlignmentWith(annot, typename, calcName,
328 if (lastAnnot + 1 == ourAnnot.size())
330 // remove singleton alignment annotation row
331 ourAnnot.get(lastAnnot).graphGroup = -1;
337 jalview.api.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
338 .cloneFeatureRenderer();
339 for (String ft : fc.keySet())
341 FeatureColourI gc = fr.getFeatureStyle(ft);
342 if (gc.isSimpleColour())
344 // set graduated color as fading to white for minimum, and
345 // autoscaling to values on alignment
346 FeatureColourI ggc = new FeatureColour(Color.white,
347 gc.getColour(), Float.MIN_VALUE, Float.MAX_VALUE);
348 ggc.setAutoScaled(true);
349 fr.setColour(ft, ggc);
352 // TODO: JAL-1150 - create sequence feature settings API for defining
353 // styles and enabling/disabling feature overlay on alignment panel
354 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
355 if (af.alignPanel == ap)
357 // only do this if the alignFrame is currently showing this view.
358 af.setShowSeqFeatures(true);
360 ap.paintAlignment(true);
362 if (ourAnnot.size() > 0)
364 // Modify the visible annotation on the alignment viewport with the
365 // new alignment annotation rows created.
366 updateOurAnnots(ourAnnot);
367 ap.adjustAnnotationHeight();
374 public String getCalcId()
376 // Disorder predictions are not dynamically updated so we return null