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";
59 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
60 WsParamSetI preset, List<Argument> paramset)
62 super(sh, alignFrame, preset, paramset);
65 methodName = sh.serviceType;
69 nucleotidesAllowed = false;
70 proteinAllowed = true;
75 public String getServiceActionText()
77 return "Submitting amino acid sequences for disorder prediction.";
80 private static Map<String, Map<String, String[]>> featureMap;
82 private static Map<String, Map<String, Map<String, Object>>> annotMap;
84 private static String DONTCOMBINE = "DONTCOMBINE";
86 private static String INVISIBLE = "INVISIBLE";
89 // TODO: turn this into some kind of configuration file that's a bit easier
91 featureMap = new HashMap<String, Map<String, String[]>>();
92 Map<String, String[]> fmap;
93 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
94 fmap = new HashMap<String, String[]>());
95 fmap.put("Glob", new String[]
96 { "Globular Domain", "Predicted globular domain" });
97 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
98 fmap = new HashMap<String, String[]>());
99 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
100 fmap = new HashMap<String, String[]>());
101 fmap.put("REM465", new String[]
102 { "REM465", "Missing density" });
103 fmap.put("HOTLOOPS", new String[]
104 { "HOTLOOPS", "Flexible loops" });
105 fmap.put("COILS", new String[]
106 { "COILS", "Random coil" });
107 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
108 fmap = new HashMap<String, String[]>());
109 fmap.put("GlobDoms", new String[]
110 { "Globular Domain", "Predicted globular domain" });
111 fmap.put("Disorder", new String[]
112 { "Protein Disorder", "Probable unstructured peptide region" });
113 Map<String, Map<String, Object>> amap;
114 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
115 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
116 amap = new HashMap<String, Map<String, Object>>());
117 amap.put("Dydx", new HashMap<String, Object>());
118 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
119 amap.get("Dydx").put(THRESHOLD, new double[]
121 amap.put("SmoothedScore", new HashMap<String, Object>());
122 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
123 amap.put("RawScore", new HashMap<String, Object>());
124 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
125 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
126 amap = new HashMap<String, Map<String, Object>>());
127 amap.put("COILS", new HashMap<String, Object>());
128 amap.put("HOTLOOPS", new HashMap<String, Object>());
129 amap.put("REM465", new HashMap<String, Object>());
130 amap.get("COILS").put(THRESHOLD, new double[]
132 amap.get("HOTLOOPS").put(THRESHOLD, new double[]
134 amap.get("REM465").put(THRESHOLD, new double[]
137 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
138 amap = new HashMap<String, Map<String, Object>>());
139 amap.put("Long", new HashMap<String, Object>());
140 amap.put("Short", new HashMap<String, Object>());
141 amap.get("Long").put(THRESHOLD, new double[]
143 amap.get("Short").put(THRESHOLD, new double[]
145 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
146 amap = new HashMap<String, Map<String, Object>>());
147 amap.put("JRonn", new HashMap<String, Object>());
148 amap.get("JRonn").put(THRESHOLD, new double[]
153 public void updateResultAnnotation(boolean immediate)
156 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
158 Map<String, String[]> featureTypeMap = featureMap
159 .get(service.serviceType);
160 Map<String, Map<String, Object>> annotTypeMap = annotMap
161 .get(service.serviceType);
162 boolean dispFeatures = false;
163 Map<String, Object> fc = new Hashtable<String, Object>();
164 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
166 * grouping for any annotation rows created
169 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
171 for (AlignmentAnnotation ala : alignViewport.getAlignment()
172 .getAlignmentAnnotation())
174 if (ala.graphGroup > graphGroup)
176 graphGroup = ala.graphGroup;
181 for (String seqId : seqNames.keySet())
183 boolean sameGroup = false;
184 SequenceI dseq, aseq, seq = seqNames.get(seqId);
185 int base = seq.findPosition(start)-1;
187 while ((dseq = seq).getDatasetSequence() != null)
189 seq = seq.getDatasetSequence();
192 ScoreHolder scores = scoremanager.getAnnotationForSequence(seqId);
193 float last = Float.NaN, val = Float.NaN;
194 int lastAnnot = ourAnnot.size();
195 if (scores!=null && scores.scores!=null) {
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],
218 base + rn.from, base + rn.to, val = vals.next()
219 .floatValue(), methodName);
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(
243 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
251 .get(scr.getMethod()) == null) ? null
252 : (double[]) annotTypeMap.get(scr.getMethod()).get(
254 if (annotTypeMap == null
255 || annotTypeMap.get(scr.getMethod()) == null
256 || annotTypeMap.get(scr.getMethod()).get(DONTCOMBINE) == null)
265 annot.graphGroup = graphGroup;
269 annot.description = "<html>" + service.getActionText()
273 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
274 + thrsh[1] + " indicates disorder";
275 annot.threshold = new GraphLine((float) thrsh[1],
276 threshNote, Color.red);
277 annot.description += "<br/>" + threshNote;
279 annot.description += "</html>";
280 Color col = new UserColourScheme(typeName)
281 .createColourFromName(typeName + scr.getMethod());
282 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
284 if (annot.annotations[p] != null)
286 annot.annotations[p].colour = col;
289 annot._linecolour = col;
293 if (lastAnnot + 1 == ourAnnot.size())
295 // remove singleton alignment annotation row
296 ourAnnot.get(lastAnnot).graphGroup = -1;
302 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
303 .cloneFeatureRenderer();
304 for (String ft : fc.keySet())
306 Object gc = fr.getFeatureStyle(ft);
307 if (gc instanceof Color)
309 // set graduated color as fading to white for minimum, and
310 // autoscaling to values on alignment
311 GraduatedColor ggc = new GraduatedColor(Color.white,
312 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
313 ggc.setAutoScaled(true);
314 fr.setColour(ft, ggc);
317 // TODO: JAL-1150 - create sequence feature settings API for defining
318 // styles and enabling/disabling feature overlay on alignment panel
319 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
320 if (af.alignPanel == ap)
322 // only do this if the alignFrame is currently showing this view.
323 af.setShowSeqFeatures(true);
325 ap.paintAlignment(true);
327 if (ourAnnot.size() > 0)
329 // Modify the visible annotation on the alignment viewport with the
330 // new alignment annotation rows created.
331 updateOurAnnots(ourAnnot);
332 ap.adjustAnnotationHeight();