2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws2;
20 import jalview.api.AlignCalcWorkerI;
21 import jalview.datamodel.AlignmentAnnotation;
23 import jalview.datamodel.GraphLine;
24 import jalview.datamodel.SequenceFeature;
25 import jalview.datamodel.SequenceI;
26 import jalview.gui.AlignFrame;
27 import jalview.schemes.GraduatedColor;
28 import jalview.schemes.UserColourScheme;
29 import jalview.ws.jws2.jabaws2.Jws2Instance;
30 import jalview.ws.params.WsParamSetI;
32 import java.awt.Color;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.Hashtable;
36 import java.util.Iterator;
37 import java.util.List;
39 import compbio.data.sequence.Range;
40 import compbio.data.sequence.Score;
41 import compbio.data.sequence.ScoreManager.ScoreHolder;
42 import compbio.metadata.Argument;
44 public class AADisorderClient extends JabawsAlignCalcWorker implements
48 private static final String THRESHOLD = "THRESHOLD";
58 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
59 WsParamSetI preset, List<Argument> paramset)
61 super(sh, alignFrame, preset, paramset);
64 methodName = sh.serviceType;
68 nucleotidesAllowed = false;
69 proteinAllowed = true;
74 public String getServiceActionText()
76 return "Submitting amino acid sequences for disorder prediction.";
79 private static Map<String, Map<String, String[]>> featureMap;
81 private static Map<String, Map<String, Map<String, Object>>> annotMap;
83 private static String DONTCOMBINE = "DONTCOMBINE";
85 private static String INVISIBLE = "INVISIBLE";
88 // TODO: turn this into some kind of configuration file that's a bit easier
90 featureMap = new HashMap<String, Map<String, String[]>>();
91 Map<String, String[]> fmap;
92 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
93 fmap = new HashMap<String, String[]>());
94 fmap.put("Glob", new String[]
95 { "Globular Domain", "Predicted globular domain" });
96 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
97 fmap = new HashMap<String, String[]>());
98 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
99 fmap = new HashMap<String, String[]>());
100 fmap.put("REM465", new String[]
101 { "REM465", "Missing density" });
102 fmap.put("HOTLOOPS", new String[]
103 { "HOTLOOPS", "Flexible loops" });
104 fmap.put("COILS", new String[]
105 { "COILS", "Random coil" });
106 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
107 fmap = new HashMap<String, String[]>());
108 fmap.put("GlobDoms", new String[]
109 { "Globular Domain", "Predicted globular domain" });
110 fmap.put("Disorder", new String[]
111 { "Protein Disorder", "Probable unstructured peptide region" });
112 Map<String, Map<String, Object>> amap;
113 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
114 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
115 amap = new HashMap<String, Map<String, Object>>());
116 amap.put("Dydx", new HashMap<String, Object>());
117 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
118 amap.get("Dydx").put(THRESHOLD, new double[]
120 amap.put("SmoothedScore", new HashMap<String, Object>());
121 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
122 amap.put("RawScore", new HashMap<String, Object>());
123 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
124 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
125 amap = new HashMap<String, Map<String, Object>>());
126 amap.put("COILS", new HashMap<String, Object>());
127 amap.put("HOTLOOPS", new HashMap<String, Object>());
128 amap.put("REM465", new HashMap<String, Object>());
129 amap.get("COILS").put(THRESHOLD, new double[]
131 amap.get("HOTLOOPS").put(THRESHOLD, new double[]
133 amap.get("REM465").put(THRESHOLD, new double[]
136 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
137 amap = new HashMap<String, Map<String, Object>>());
138 amap.put("Long", new HashMap<String, Object>());
139 amap.put("Short", new HashMap<String, Object>());
140 amap.get("Long").put(THRESHOLD, new double[]
142 amap.get("Short").put(THRESHOLD, new double[]
144 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
145 amap = new HashMap<String, Map<String, Object>>());
146 amap.put("JRonn", new HashMap<String, Object>());
147 amap.get("JRonn").put(THRESHOLD, new double[]
152 public void updateResultAnnotation(boolean immediate)
155 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
157 Map<String, String[]> featureTypeMap = featureMap
158 .get(service.serviceType);
159 Map<String, Map<String, Object>> annotTypeMap = annotMap
160 .get(service.serviceType);
161 boolean dispFeatures = false;
162 Map<String, Object> fc = new Hashtable<String, Object>();
163 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
165 * grouping for any annotation rows created
168 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
170 for (AlignmentAnnotation ala : alignViewport.getAlignment()
171 .getAlignmentAnnotation())
173 if (ala.graphGroup > graphGroup)
175 graphGroup = ala.graphGroup;
180 for (String seqId : seqNames.keySet())
182 boolean sameGroup = false;
183 SequenceI dseq, aseq, seq = seqNames.get(seqId);
184 int base = seq.getStart() - 1;
186 while ((dseq = seq).getDatasetSequence() != null)
188 seq = seq.getDatasetSequence();
191 ScoreHolder scores = scoremanager.getAnnotationForSequence(seqId);
192 float last = Float.NaN, val = Float.NaN;
193 int lastAnnot = ourAnnot.size();
194 if (scores!=null && scores.scores!=null) {
195 for (Score scr : scores.scores)
198 if (scr.getRanges() != null && scr.getRanges().size() > 0)
200 Iterator<Float> vals = scr.getScores().iterator();
201 // make features on sequence
202 for (Range rn : scr.getRanges())
206 String[] type = featureTypeMap.get(scr.getMethod());
209 // create a default type for this feature
211 { typeName + " (" + scr.getMethod() + ")",
212 service.getActionText() };
216 sf = new SequenceFeature(type[0], type[1],
217 base + rn.from, base + rn.to, val = vals.next()
218 .floatValue(), methodName);
222 sf = new SequenceFeature(type[0], type[1], null, base
223 + rn.from, base + rn.to, methodName);
225 dseq.addSequenceFeature(sf);
226 if (last != val && last != Float.NaN)
228 fc.put(sf.getType(), sf);
236 if (scr.getScores().size() == 0)
240 AlignmentAnnotation annot = createAnnotationRowsForScores(
242 service.serviceType + " (" + scr.getMethod() + ")",
243 service.getServiceTypeURI() + "/" + scr.getMethod(),
244 aseq, base + 1, scr);
245 annot.graph = AlignmentAnnotation.LINE_GRAPH;
246 annot.visible = (annotTypeMap == null
247 || annotTypeMap.get(scr.getMethod()) == null || annotTypeMap
248 .get(scr.getMethod()).get(INVISIBLE) == null);
249 double[] thrsh = (annotTypeMap == null || annotTypeMap
250 .get(scr.getMethod()) == null) ? null
251 : (double[]) annotTypeMap.get(scr.getMethod()).get(
253 if (annotTypeMap == null
254 || annotTypeMap.get(scr.getMethod()) == null
255 || annotTypeMap.get(scr.getMethod()).get(DONTCOMBINE) == null)
264 annot.graphGroup = graphGroup;
268 annot.description = "<html>" + service.getActionText()
272 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
273 + thrsh[1] + " indicates disorder";
274 annot.threshold = new GraphLine((float) thrsh[1],
275 threshNote, Color.red);
276 annot.description += "<br/>" + threshNote;
278 annot.description += "</html>";
279 Color col = new UserColourScheme(typeName)
280 .createColourFromName(typeName + scr.getMethod());
281 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
283 if (annot.annotations[p] != null)
285 annot.annotations[p].colour = col;
288 annot._linecolour = col;
292 if (lastAnnot + 1 == ourAnnot.size())
294 // remove singleton alignment annotation row
295 ourAnnot.get(lastAnnot).graphGroup = -1;
301 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
302 .cloneFeatureRenderer();
303 for (String ft : fc.keySet())
305 Object gc = fr.getFeatureStyle(ft);
306 if (gc instanceof Color)
308 // set graduated color as fading to white for minimum, and
309 // autoscaling to values on alignment
310 GraduatedColor ggc = new GraduatedColor(Color.white,
311 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
312 ggc.setAutoScaled(true);
313 fr.setColour(ft, ggc);
316 // TODO: JAL-1150 - create sequence feature settings API for defining
317 // styles and enabling/disabling feature overlay on alignment panel
318 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
319 if (af.alignPanel == ap)
321 // only do this if the alignFrame is currently showing this view.
322 af.setShowSeqFeatures(true);
324 ap.paintAlignment(true);
326 if (ourAnnot.size() > 0)
328 // Modify the visible annotation on the alignment viewport with the
329 // new alignment annotation rows created.
330 updateOurAnnots(ourAnnot);
331 ap.adjustAnnotationHeight();