2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.jws2;
21 import jalview.api.AlignCalcWorkerI;
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;
45 public class AADisorderClient extends JabawsCalcWorker implements
49 private static final String THRESHOLD = "THRESHOLD";
50 private static final String RANGE = "RANGE";
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.get("Dydx").put(RANGE, new float[]
125 amap.put("SmoothedScore", new HashMap<String, Object>());
126 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
127 amap.put("RawScore", new HashMap<String, Object>());
128 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
129 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
130 amap = new HashMap<String, Map<String, Object>>());
131 amap.put("COILS", new HashMap<String, Object>());
132 amap.put("HOTLOOPS", new HashMap<String, Object>());
133 amap.put("REM465", new HashMap<String, Object>());
134 amap.get("COILS").put(THRESHOLD, new double[]
136 amap.get("COILS").put(RANGE, new float[]
139 amap.get("HOTLOOPS").put(THRESHOLD, new double[]
141 amap.get("HOTLOOPS").put(RANGE, new float[]
143 amap.get("REM465").put(THRESHOLD, new double[]
145 amap.get("REM465").put(RANGE, new float[]
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[]
155 amap.get("Long").put(RANGE, new float[]
157 amap.get("Short").put(THRESHOLD, new double[]
159 amap.get("Short").put(RANGE, new float[]
161 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
162 amap = new HashMap<String, Map<String, Object>>());
163 amap.put("JRonn", new HashMap<String, Object>());
164 amap.get("JRonn").put(THRESHOLD, new double[]
166 amap.get("JRonn").put(RANGE, new float[]
171 public void updateResultAnnotation(boolean immediate)
174 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
176 Map<String, String[]> featureTypeMap = featureMap
177 .get(service.serviceType);
178 Map<String, Map<String, Object>> annotTypeMap = annotMap
179 .get(service.serviceType);
180 boolean dispFeatures = false;
181 Map<String, Object> fc = new Hashtable<String, Object>();
182 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
184 * grouping for any annotation rows created
187 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
189 for (AlignmentAnnotation ala : alignViewport.getAlignment()
190 .getAlignmentAnnotation())
192 if (ala.graphGroup > graphGroup)
194 graphGroup = ala.graphGroup;
199 for (String seqId : seqNames.keySet())
201 boolean sameGroup = false;
202 SequenceI dseq, aseq, seq = seqNames.get(seqId);
203 int base = seq.findPosition(start)-1;
205 while ((dseq = seq).getDatasetSequence() != null)
207 seq = seq.getDatasetSequence();
210 ScoreHolder scores = scoremanager.getAnnotationForSequence(seqId);
211 float last = Float.NaN, val = Float.NaN;
212 int lastAnnot = ourAnnot.size();
213 if (scores!=null && scores.scores!=null) {
214 for (Score scr : scores.scores)
217 if (scr.getRanges() != null && scr.getRanges().size() > 0)
219 Iterator<Float> vals = scr.getScores().iterator();
220 // make features on sequence
221 for (Range rn : scr.getRanges())
225 String[] type = featureTypeMap.get(scr.getMethod());
228 // create a default type for this feature
230 { typeName + " (" + scr.getMethod() + ")",
231 service.getActionText() };
235 sf = new SequenceFeature(type[0], type[1],
236 base + rn.from, base + rn.to, val = vals.next()
237 .floatValue(), methodName);
241 sf = new SequenceFeature(type[0], type[1], null, base
242 + rn.from, base + rn.to, methodName);
244 dseq.addSequenceFeature(sf);
245 if (last != val && last != Float.NaN)
247 fc.put(sf.getType(), sf);
255 if (scr.getScores().size() == 0)
259 AlignmentAnnotation annot = createAnnotationRowsForScores(
261 service.serviceType + " (" + scr.getMethod() + ")",
262 service.getServiceTypeURI() + "/" + scr.getMethod(),
263 aseq, base + 1, scr);
264 annot.graph = AlignmentAnnotation.LINE_GRAPH;
266 Map<String,Object> styleMap = (annotTypeMap == null) ? null : annotTypeMap.get(scr.getMethod());
268 annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
269 double[] thrsh = (styleMap==null) ? null
270 : (double[]) styleMap.get(
272 float[] range = (styleMap==null) ? null : (float[]) styleMap.get(
276 annot.graphMin = range[0];
277 annot.graphMax = range[1];
279 if (styleMap==null || styleMap.get(DONTCOMBINE) == null)
288 annot.graphGroup = graphGroup;
292 annot.description = "<html>" + service.getActionText()
296 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
297 + thrsh[1] + " indicates disorder";
298 annot.threshold = new GraphLine((float) thrsh[1],
299 threshNote, Color.red);
300 annot.description += "<br/>" + threshNote;
302 annot.description += "</html>";
303 Color col = new UserColourScheme(typeName)
304 .createColourFromName(typeName + scr.getMethod());
305 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
307 if (annot.annotations[p] != null)
309 annot.annotations[p].colour = col;
312 annot._linecolour = col;
316 if (lastAnnot + 1 == ourAnnot.size())
318 // remove singleton alignment annotation row
319 ourAnnot.get(lastAnnot).graphGroup = -1;
325 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
326 .cloneFeatureRenderer();
327 for (String ft : fc.keySet())
329 Object gc = fr.getFeatureStyle(ft);
330 if (gc instanceof Color)
332 // set graduated color as fading to white for minimum, and
333 // autoscaling to values on alignment
334 GraduatedColor ggc = new GraduatedColor(Color.white,
335 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
336 ggc.setAutoScaled(true);
337 fr.setColour(ft, ggc);
340 // TODO: JAL-1150 - create sequence feature settings API for defining
341 // styles and enabling/disabling feature overlay on alignment panel
342 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
343 if (af.alignPanel == ap)
345 // only do this if the alignFrame is currently showing this view.
346 af.setShowSeqFeatures(true);
348 ap.paintAlignment(true);
350 if (ourAnnot.size() > 0)
352 // Modify the visible annotation on the alignment viewport with the
353 // new alignment annotation rows created.
354 updateOurAnnots(ourAnnot);
355 ap.adjustAnnotationHeight();