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.bin.Cache;
22 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.GraphLine;
25 import jalview.datamodel.SequenceFeature;
26 import jalview.datamodel.SequenceI;
27 import jalview.gui.AlignFrame;
28 import jalview.schemes.GraduatedColor;
29 import jalview.schemes.UserColourScheme;
30 import jalview.ws.jws2.jabaws2.Jws2Instance;
31 import jalview.ws.params.WsParamSetI;
33 import java.awt.Color;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.Hashtable;
37 import java.util.Iterator;
38 import java.util.List;
40 import compbio.data.sequence.Range;
41 import compbio.data.sequence.Score;
42 import compbio.data.sequence.ScoreManager.ScoreHolder;
43 import compbio.metadata.Argument;
44 import compbio.ws.client.Services;
46 public class AADisorderClient extends JabawsAlignCalcWorker implements
50 private static final String THRESHOLD = "THRESHOLD";
60 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
61 WsParamSetI preset, List<Argument> paramset)
63 super(sh, alignFrame, preset, paramset);
66 methodName = sh.serviceType;
70 nucleotidesAllowed = false;
71 proteinAllowed = true;
76 public String getServiceActionText()
78 return "Submitting amino acid sequences for disorder prediction.";
81 private static Map<String, Map<String, String[]>> featureMap;
83 private static Map<String, Map<String, Map<String, Object>>> annotMap;
85 private static String DONTCOMBINE = "DONTCOMBINE";
87 private static String INVISIBLE = "INVISIBLE";
90 // TODO: turn this into some kind of configuration file that's a bit easier
92 featureMap = new HashMap<String, Map<String, String[]>>();
93 Map<String, String[]> fmap;
94 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
95 fmap = new HashMap<String, String[]>());
96 fmap.put("Glob", new String[]
97 { "Globular Domain", "Predicted globular domain" });
98 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
99 fmap = new HashMap<String, String[]>());
100 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
101 fmap = new HashMap<String, String[]>());
102 fmap.put("REM465", new String[]
103 { "REM465", "Missing density" });
104 fmap.put("HOTLOOPS", new String[]
105 { "HOTLOOPS", "Flexible loops" });
106 fmap.put("COILS", new String[]
107 { "COILS", "Random coil" });
108 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
109 fmap = new HashMap<String, String[]>());
110 fmap.put("GlobDoms", new String[]
111 { "Globular Domain", "Predicted globular domain" });
112 fmap.put("Disorder", new String[]
113 { "Protein Disorder", "Probable unstructured peptide region" });
114 Map<String, Map<String, Object>> amap;
115 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
116 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
117 amap = new HashMap<String, Map<String, Object>>());
118 amap.put("Dydx", new HashMap<String, Object>());
119 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
120 amap.get("Dydx").put(THRESHOLD, new double[]
122 amap.put("SmoothedScore", new HashMap<String, Object>());
123 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
124 amap.put("RawScore", new HashMap<String, Object>());
125 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
126 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
127 amap = new HashMap<String, Map<String, Object>>());
128 amap.put("COILS", new HashMap<String, Object>());
129 amap.put("HOTLOOPS", new HashMap<String, Object>());
130 amap.put("REM465", new HashMap<String, Object>());
131 amap.get("COILS").put(THRESHOLD, new double[]
133 amap.get("HOTLOOPS").put(THRESHOLD, new double[]
135 amap.get("REM465").put(THRESHOLD, new double[]
138 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
139 amap = new HashMap<String, Map<String, Object>>());
140 amap.put("Long", new HashMap<String, Object>());
141 amap.put("Short", new HashMap<String, Object>());
142 amap.get("Long").put(THRESHOLD, new double[]
144 amap.get("Short").put(THRESHOLD, new double[]
146 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
147 amap = new HashMap<String, Map<String, Object>>());
148 amap.put("JRonn", new HashMap<String, Object>());
149 amap.get("JRonn").put(THRESHOLD, new double[]
154 public void updateResultAnnotation(boolean immediate)
157 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
159 Map<String, String[]> featureTypeMap = featureMap
160 .get(service.serviceType);
161 Map<String, Map<String, Object>> annotTypeMap = annotMap
162 .get(service.serviceType);
163 boolean dispFeatures = false;
164 Map<String, Object> fc = new Hashtable<String, Object>();
165 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
167 * grouping for any annotation rows created
170 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
172 for (AlignmentAnnotation ala : alignViewport.getAlignment()
173 .getAlignmentAnnotation())
175 if (ala.graphGroup > graphGroup)
177 graphGroup = ala.graphGroup;
182 for (String seqId : seqNames.keySet())
184 boolean sameGroup = false;
185 SequenceI dseq, aseq, seq = seqNames.get(seqId);
186 int base = seq.getStart() - 1;
188 while ((dseq = seq).getDatasetSequence() != null)
190 seq = seq.getDatasetSequence();
193 ScoreHolder scores = scoremanager.getAnnotationForSequence(seqId);
194 float last = Float.NaN, val = Float.NaN;
195 int lastAnnot = ourAnnot.size();
196 for (Score scr : scores.scores)
199 if (scr.getRanges() != null && scr.getRanges().size() > 0)
201 Iterator<Float> vals = scr.getScores().iterator();
202 // make features on sequence
203 for (Range rn : scr.getRanges())
207 String[] type = featureTypeMap.get(scr.getMethod());
210 // create a default type for this feature
212 { typeName + " (" + scr.getMethod() + ")",
213 service.getActionText() };
217 sf = new SequenceFeature(type[0], type[1], base + rn.from,
218 base + rn.to, val = vals.next().floatValue(),
223 sf = new SequenceFeature(type[0], type[1], null, base
224 + rn.from, base + rn.to, methodName);
226 dseq.addSequenceFeature(sf);
227 if (last != val && last != Float.NaN)
229 fc.put(sf.getType(), sf);
237 if (scr.getScores().size() == 0)
241 AlignmentAnnotation annot = createAnnotationRowsForScores(
242 ourAnnot, service.serviceType + " (" + scr.getMethod()
244 service.getServiceTypeURI() + "/" + scr.getMethod(),
245 aseq, base + 1, scr);
246 annot.graph = AlignmentAnnotation.LINE_GRAPH;
247 annot.visible = (annotTypeMap == null
248 || annotTypeMap.get(scr.getMethod()) == null || annotTypeMap
249 .get(scr.getMethod()).get(INVISIBLE) == null);
250 double[] thrsh = (annotTypeMap == null || annotTypeMap.get(scr
251 .getMethod()) == null) ? null : (double[]) annotTypeMap
252 .get(scr.getMethod()).get(THRESHOLD);
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], threshNote,
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;
291 if (lastAnnot + 1 == ourAnnot.size())
293 // remove singleton alignment annotation row
294 ourAnnot.get(lastAnnot).graphGroup = -1;
300 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
301 .cloneFeatureRenderer();
302 for (String ft : fc.keySet())
304 Object gc = fr.getFeatureStyle(ft);
305 if (gc instanceof Color)
307 // set graduated color as fading to white for minimum, and
308 // autoscaling to values on alignment
309 GraduatedColor ggc = new GraduatedColor(Color.white,
310 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
311 ggc.setAutoScaled(true);
312 fr.setColour(ft, ggc);
315 // TODO: JAL-1150 - create sequence feature settings API for defining
316 // styles and enabling/disabling feature overlay on alignment panel
317 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
318 if (af.alignPanel == ap)
320 // only do this if the alignFrame is currently showing this view.
321 af.setShowSeqFeatures(true);
323 ap.paintAlignment(true);
325 if (ourAnnot.size() > 0)
327 // Modify the visible annotation on the alignment viewport with the
328 // new alignment annotation rows created.
329 updateOurAnnots(ourAnnot);
330 ap.adjustAnnotationHeight();