1 package jalview.ws.jws2;
3 import jalview.api.AlignCalcWorkerI;
4 import jalview.bin.Cache;
5 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.GraphLine;
8 import jalview.datamodel.SequenceFeature;
9 import jalview.datamodel.SequenceI;
10 import jalview.gui.AlignFrame;
11 import jalview.schemes.GraduatedColor;
12 import jalview.schemes.UserColourScheme;
13 import jalview.ws.jws2.jabaws2.Jws2Instance;
14 import jalview.ws.params.WsParamSetI;
16 import java.awt.Color;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.Hashtable;
20 import java.util.Iterator;
21 import java.util.List;
23 import compbio.data.sequence.Range;
24 import compbio.data.sequence.Score;
25 import compbio.data.sequence.ScoreManager.ScoreHolder;
26 import compbio.metadata.Argument;
27 import compbio.ws.client.Services;
29 public class AADisorderClient extends JabawsAlignCalcWorker implements
33 private static final String THRESHOLD = "THRESHOLD";
43 public AADisorderClient(Jws2Instance sh, AlignFrame alignFrame,
44 WsParamSetI preset, List<Argument> paramset)
46 super(sh, alignFrame, preset, paramset);
49 methodName = sh.serviceType;
53 nucleotidesAllowed = false;
54 proteinAllowed = true;
59 public String getServiceActionText()
61 return "Submitting amino acid sequences for disorder prediction.";
64 private static Map<String, Map<String, String[]>> featureMap;
66 private static Map<String, Map<String, Map<String, Object>>> annotMap;
68 private static String DONTCOMBINE = "DONTCOMBINE";
70 private static String INVISIBLE = "INVISIBLE";
73 // TODO: turn this into some kind of configuration file that's a bit easier
75 featureMap = new HashMap<String, Map<String, String[]>>();
76 Map<String, String[]> fmap;
77 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
78 fmap = new HashMap<String, String[]>());
79 fmap.put("Glob", new String[]
80 { "Globular Domain", "Predicted globular domain" });
81 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
82 fmap = new HashMap<String, String[]>());
83 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
84 fmap = new HashMap<String, String[]>());
85 fmap.put("REM465", new String[]
86 { "REM465", "Missing density" });
87 fmap.put("HOTLOOPS", new String[]
88 { "HOTLOOPS", "Flexible loops" });
89 fmap.put("COILS", new String[]
90 { "COILS", "Random coil" });
91 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
92 fmap = new HashMap<String, String[]>());
93 fmap.put("GlobDoms", new String[]
94 { "Globular Domain", "Predicted globular domain" });
95 fmap.put("Disorder", new String[]
96 { "Protein Disorder", "Probable unstructured peptide region" });
97 Map<String, Map<String, Object>> amap;
98 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
99 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
100 amap = new HashMap<String, Map<String, Object>>());
101 amap.put("Dydx", new HashMap<String, Object>());
102 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
103 amap.get("Dydx").put(THRESHOLD, new double[]
105 amap.put("SmoothedScore", new HashMap<String, Object>());
106 amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
107 amap.put("RawScore", new HashMap<String, Object>());
108 amap.get("RawScore").put(INVISIBLE, INVISIBLE);
109 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
110 amap = new HashMap<String, Map<String, Object>>());
111 amap.put("COILS", new HashMap<String, Object>());
112 amap.put("HOTLOOPS", new HashMap<String, Object>());
113 amap.put("REM465", new HashMap<String, Object>());
114 amap.get("COILS").put(THRESHOLD, new double[]
116 amap.get("HOTLOOPS").put(THRESHOLD, new double[]
118 amap.get("REM465").put(THRESHOLD, new double[]
121 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
122 amap = new HashMap<String, Map<String, Object>>());
123 amap.put("Long", new HashMap<String, Object>());
124 amap.put("Short", new HashMap<String, Object>());
125 amap.get("Long").put(THRESHOLD, new double[]
127 amap.get("Short").put(THRESHOLD, new double[]
129 annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
130 amap = new HashMap<String, Map<String, Object>>());
131 amap.put("JRonn", new HashMap<String, Object>());
132 amap.get("JRonn").put(THRESHOLD, new double[]
137 public void updateResultAnnotation(boolean immediate)
140 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
142 Map<String, String[]> featureTypeMap = featureMap
143 .get(service.serviceType);
144 Map<String, Map<String, Object>> annotTypeMap = annotMap
145 .get(service.serviceType);
146 boolean dispFeatures = false;
147 Map<String, Object> fc = new Hashtable<String, Object>();
148 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
150 * grouping for any annotation rows created
153 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
155 for (AlignmentAnnotation ala : alignViewport.getAlignment()
156 .getAlignmentAnnotation())
158 if (ala.graphGroup > graphGroup)
160 graphGroup = ala.graphGroup;
165 for (String seqId : seqNames.keySet())
167 boolean sameGroup = false;
168 SequenceI dseq, aseq, seq = seqNames.get(seqId);
169 int base = seq.getStart() - 1;
171 while ((dseq = seq).getDatasetSequence() != null)
173 seq = seq.getDatasetSequence();
176 ScoreHolder scores = scoremanager.getAnnotationForSequence(seqId);
177 float last = Float.NaN, val = Float.NaN;
178 int lastAnnot = ourAnnot.size();
179 for (Score scr : scores.scores)
182 if (scr.getRanges() != null && scr.getRanges().size() > 0)
184 Iterator<Float> vals = scr.getScores().iterator();
185 // make features on sequence
186 for (Range rn : scr.getRanges())
190 String[] type = featureTypeMap.get(scr.getMethod());
193 // create a default type for this feature
195 { typeName + " (" + scr.getMethod() + ")",
196 service.getActionText() };
200 sf = new SequenceFeature(type[0], type[1], base + rn.from,
201 base + rn.to, val = vals.next().floatValue(),
206 sf = new SequenceFeature(type[0], type[1], null, base
207 + rn.from, base + rn.to, methodName);
209 dseq.addSequenceFeature(sf);
210 if (last != val && last != Float.NaN)
212 fc.put(sf.getType(), sf);
220 if (scr.getScores().size() == 0)
224 AlignmentAnnotation annot = createAnnotationRowsForScores(
225 ourAnnot, service.serviceType + " (" + scr.getMethod()
227 service.getServiceTypeURI() + "/" + scr.getMethod(),
228 aseq, base + 1, scr);
229 annot.graph = AlignmentAnnotation.LINE_GRAPH;
230 annot.visible = (annotTypeMap == null
231 || annotTypeMap.get(scr.getMethod()) == null || annotTypeMap
232 .get(scr.getMethod()).get(INVISIBLE) == null);
233 double[] thrsh = (annotTypeMap == null || annotTypeMap.get(scr
234 .getMethod()) == null) ? null : (double[]) annotTypeMap
235 .get(scr.getMethod()).get(THRESHOLD);
236 if (annotTypeMap == null
237 || annotTypeMap.get(scr.getMethod()) == null
238 || annotTypeMap.get(scr.getMethod()).get(DONTCOMBINE) == null)
247 annot.graphGroup = graphGroup;
251 annot.description = "<html>" + service.getActionText()
255 String threshNote = (thrsh[0] > 0 ? "Above " : "Below ")
256 + thrsh[1] + " indicates disorder";
257 annot.threshold = new GraphLine((float) thrsh[1], threshNote,
259 annot.description += "<br/>" + threshNote;
261 annot.description += "</html>";
262 Color col = new UserColourScheme(typeName)
263 .createColourFromName(typeName + scr.getMethod());
264 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
266 if (annot.annotations[p] != null)
268 annot.annotations[p].colour = col;
271 annot._linecolour = col;
274 if (lastAnnot + 1 == ourAnnot.size())
276 // remove singleton alignment annotation row
277 ourAnnot.get(lastAnnot).graphGroup = -1;
283 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
284 .cloneFeatureRenderer();
285 for (String ft : fc.keySet())
287 Object gc = fr.getFeatureStyle(ft);
288 if (gc instanceof Color)
290 // set graduated color as fading to white for minimum, and
291 // autoscaling to values on alignment
292 GraduatedColor ggc = new GraduatedColor(Color.white,
293 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
294 ggc.setAutoScaled(true);
295 fr.setColour(ft, ggc);
298 // TODO: JAL-1150 - create sequence feature settings API for defining
299 // styles and enabling/disabling feature overlay on alignment panel
300 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
301 if (af.alignPanel == ap)
303 // only do this if the alignFrame is currently showing this view.
304 af.setShowSeqFeatures(true);
306 ap.paintAlignment(true);
308 if (ourAnnot.size() > 0)
310 // Modify the visible annotation on the alignment viewport with the
311 // new alignment annotation rows created.
312 updateOurAnnots(ourAnnot);
313 ap.adjustAnnotationHeight();