2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.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.GraduatedColor;
31 import jalview.schemes.UserColourScheme;
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.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 implements
52 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.";
84 private static Map<String, Map<String, String[]>> featureMap;
86 private static Map<String, Map<String, Map<String, Object>>> annotMap;
88 private static String DONTCOMBINE = "DONTCOMBINE";
90 private static String INVISIBLE = "INVISIBLE";
93 // TODO: turn this into some kind of configuration file that's a bit easier
95 featureMap = new HashMap<String, Map<String, String[]>>();
96 Map<String, String[]> fmap;
97 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
98 fmap = new HashMap<String, String[]>());
99 fmap.put("Glob", new String[]
100 { "Globular Domain", "Predicted globular domain" });
101 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
102 fmap = new HashMap<String, String[]>());
103 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
104 fmap = new HashMap<String, String[]>());
105 fmap.put("REM465", new String[]
106 { "REM465", "Missing density" });
107 fmap.put("HOTLOOPS", new String[]
108 { "HOTLOOPS", "Flexible loops" });
109 fmap.put("COILS", new String[]
110 { "COILS", "Random coil" });
111 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
112 fmap = new HashMap<String, String[]>());
113 fmap.put("GlobDoms", new String[]
114 { "Globular Domain", "Predicted globular domain" });
115 fmap.put("Disorder", new String[]
116 { "Protein Disorder", "Probable unstructured peptide region" });
117 Map<String, Map<String, Object>> amap;
118 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
119 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
120 amap = new HashMap<String, Map<String, Object>>());
121 amap.put("Dydx", new HashMap<String, Object>());
122 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
123 amap.get("Dydx").put(THRESHOLD, new double[]
125 amap.get("Dydx").put(RANGE, new float[]
128 amap.put("SmoothedScore", new HashMap<String, Object>());
129 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
130 amap.put("RawScore", new HashMap<String, Object>());
131 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
132 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
133 amap = new HashMap<String, Map<String, Object>>());
134 amap.put("COILS", new HashMap<String, Object>());
135 amap.put("HOTLOOPS", new HashMap<String, Object>());
136 amap.put("REM465", new HashMap<String, Object>());
137 amap.get("COILS").put(THRESHOLD, new double[]
139 amap.get("COILS").put(RANGE, new float[]
142 amap.get("HOTLOOPS").put(THRESHOLD, new double[]
144 amap.get("HOTLOOPS").put(RANGE, new float[]
146 amap.get("REM465").put(THRESHOLD, new double[]
148 amap.get("REM465").put(RANGE, new float[]
152 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
153 amap = new HashMap<String, Map<String, Object>>());
154 amap.put("Long", new HashMap<String, Object>());
155 amap.put("Short", new HashMap<String, Object>());
156 amap.get("Long").put(THRESHOLD, new double[]
158 amap.get("Long").put(RANGE, new float[]
160 amap.get("Short").put(THRESHOLD, new double[]
162 amap.get("Short").put(RANGE, new float[]
164 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
165 amap = new HashMap<String, Map<String, Object>>());
166 amap.put("JRonn", new HashMap<String, Object>());
167 amap.get("JRonn").put(THRESHOLD, new double[]
169 amap.get("JRonn").put(RANGE, new float[]
174 public void updateResultAnnotation(boolean immediate)
177 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
179 Map<String, String[]> featureTypeMap = featureMap
180 .get(service.serviceType);
181 Map<String, Map<String, Object>> annotTypeMap = annotMap
182 .get(service.serviceType);
183 boolean dispFeatures = false;
184 Map<String, Object> fc = new Hashtable<String, Object>();
185 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
187 * grouping for any annotation rows created
190 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
192 for (AlignmentAnnotation ala : alignViewport.getAlignment()
193 .getAlignmentAnnotation())
195 if (ala.graphGroup > graphGroup)
197 graphGroup = ala.graphGroup;
202 for (String seqId : seqNames.keySet())
204 boolean sameGroup = false;
205 SequenceI dseq, aseq, seq = seqNames.get(seqId);
206 int base = seq.findPosition(start)-1;
208 while ((dseq = seq).getDatasetSequence() != null)
210 seq = seq.getDatasetSequence();
212 ScoreHolder scores = null;
214 scores = scoremanager.getAnnotationForSequence(seqId);
215 } catch (Exception q)
218 .info("Couldn't recover disorder prediction for sequence "
220 + "(Prediction name was "
222 + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
224 float last = Float.NaN, val = Float.NaN;
225 int lastAnnot = ourAnnot.size();
226 if (scores!=null && scores.scores!=null) {
227 for (Score scr : scores.scores)
230 if (scr.getRanges() != null && scr.getRanges().size() > 0)
232 Iterator<Float> vals = scr.getScores().iterator();
233 // make features on sequence
234 for (Range rn : scr.getRanges())
238 String[] type = featureTypeMap.get(scr.getMethod());
241 // create a default type for this feature
243 { typeName + " (" + scr.getMethod() + ")",
244 service.getActionText() };
248 sf = new SequenceFeature(type[0], type[1],
249 base + rn.from, base + rn.to, val = vals.next()
250 .floatValue(), methodName);
254 sf = new SequenceFeature(type[0], type[1], null, base
255 + rn.from, base + rn.to, methodName);
257 dseq.addSequenceFeature(sf);
258 if (last != val && last != Float.NaN)
260 fc.put(sf.getType(), sf);
268 if (scr.getScores().size() == 0)
272 AlignmentAnnotation annot = createAnnotationRowsForScores(
274 service.serviceType + " (" + scr.getMethod() + ")",
275 service.getServiceTypeURI() + "/" + scr.getMethod(),
276 aseq, base + 1, scr);
277 annot.graph = AlignmentAnnotation.LINE_GRAPH;
279 Map<String,Object> styleMap = (annotTypeMap == null) ? null : annotTypeMap.get(scr.getMethod());
281 annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
282 double[] thrsh = (styleMap==null) ? null
283 : (double[]) styleMap.get(
285 float[] range = (styleMap==null) ? null : (float[]) styleMap.get(
289 annot.graphMin = range[0];
290 annot.graphMax = range[1];
292 if (styleMap==null || styleMap.get(DONTCOMBINE) == null)
301 annot.graphGroup = graphGroup;
305 annot.description = "<html>" + service.getActionText()
309 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
310 + thrsh[1] + " indicates disorder";
311 annot.threshold = new GraphLine((float) thrsh[1],
312 threshNote, Color.red);
313 annot.description += "<br/>" + threshNote;
315 annot.description += "</html>";
316 Color col = new UserColourScheme(typeName)
317 .createColourFromName(typeName + scr.getMethod());
318 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
320 if (annot.annotations[p] != null)
322 annot.annotations[p].colour = col;
325 annot._linecolour = col;
329 if (lastAnnot + 1 == ourAnnot.size())
331 // remove singleton alignment annotation row
332 ourAnnot.get(lastAnnot).graphGroup = -1;
338 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
339 .cloneFeatureRenderer();
340 for (String ft : fc.keySet())
342 Object gc = fr.getFeatureStyle(ft);
343 if (gc instanceof Color)
345 // set graduated color as fading to white for minimum, and
346 // autoscaling to values on alignment
347 GraduatedColor ggc = new GraduatedColor(Color.white,
348 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
349 ggc.setAutoScaled(true);
350 fr.setColour(ft, ggc);
353 // TODO: JAL-1150 - create sequence feature settings API for defining
354 // styles and enabling/disabling feature overlay on alignment panel
355 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
356 if (af.alignPanel == ap)
358 // only do this if the alignFrame is currently showing this view.
359 af.setShowSeqFeatures(true);
361 ap.paintAlignment(true);
363 if (ourAnnot.size() > 0)
365 // Modify the visible annotation on the alignment viewport with the
366 // new alignment annotation rows created.
367 updateOurAnnots(ourAnnot);
368 ap.adjustAnnotationHeight();