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";
69 private static String INVISIBLE = "INVISIBLE";
72 // TODO: turn this into some kind of configuration file that's a bit easier to edit
73 featureMap = new HashMap<String, Map<String, String[]>>();
74 Map<String, String[]> fmap;
75 featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
76 fmap = new HashMap<String, String[]>());
77 fmap.put("Glob", new String[]
78 { "Globular Domain", "Predicted globular domain" });
79 featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
80 fmap = new HashMap<String, String[]>());
81 featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
82 fmap = new HashMap<String, String[]>());
83 fmap.put("REM465", new String[]
84 { "REM465", "Missing density" });
85 fmap.put("HOTLOOPS", new String[]
86 { "HOTLOOPS", "Flexible loops" });
87 fmap.put("COILS", new String[]
88 { "COILS", "Random coil" });
89 featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
90 fmap = new HashMap<String, String[]>());
91 fmap.put("GlobDoms", new String[]
92 { "Globular Domain", "Predicted globular domain" });
93 fmap.put("Disorder", new String[]
94 { "Protein Disorder", "Probable unstructured peptide region" });
95 Map<String, Map<String, Object>> amap;
96 annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
97 annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
98 amap = new HashMap<String, Map<String, Object>>());
99 amap.put("Dydx", new HashMap<String, Object>());
100 amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
101 amap.get("Dydx").put(THRESHOLD, new double[] {1, 0});
102 amap.put("SmoothedScore", new HashMap<String, Object>());
103 amap.get("SmoothedScore").put(INVISIBLE,INVISIBLE);
104 amap.put("RawScore", new HashMap<String, Object>());
105 amap.get("RawScore").put(INVISIBLE,INVISIBLE);
106 annotMap.put(compbio.ws.client.Services.DisemblWS.toString(),
107 amap = new HashMap<String, Map<String, Object>>());
108 amap.put("COILS", new HashMap<String, Object>());
109 amap.put("HOTLOOPS", new HashMap<String, Object>());
110 amap.put("REM465", new HashMap<String, Object>());
111 amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516});
112 amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6});
113 amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204});
115 annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
116 amap = new HashMap<String, Map<String, Object>>());
117 amap.put("Long", new HashMap<String, Object>());
118 amap.put("Short", new HashMap<String, Object>());
119 amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5});
120 amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5});
125 public void updateResultAnnotation(boolean immediate)
128 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
130 Map<String, String[]> featureTypeMap = featureMap
131 .get(service.serviceType);
132 Map<String, Map<String, Object>> annotTypeMap = annotMap
133 .get(service.serviceType);
134 boolean dispFeatures = false;
135 Map<String, Object> fc = new Hashtable<String, Object>();
136 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
138 * grouping for any annotation rows created
140 int graphGroup = 1, iGraphGroup = 1;
141 if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
143 for (AlignmentAnnotation ala : alignViewport.getAlignment()
144 .getAlignmentAnnotation())
146 if (ala.graphGroup > graphGroup)
148 graphGroup = ala.graphGroup;
153 for (String seqId : seqNames.keySet())
155 boolean sameGroup = false;
156 SequenceI dseq, aseq, seq = seqNames.get(seqId);
157 int base = seq.getStart() - 1;
159 while ((dseq = seq).getDatasetSequence() != null)
161 seq = seq.getDatasetSequence();
164 ScoreHolder scores = scoremanager.getAnnotationForSequence(seqId);
165 float last = Float.NaN, val = Float.NaN;
166 int lastAnnot = ourAnnot.size();
167 for (Score scr : scores.scores)
170 if (scr.getRanges() != null && scr.getRanges().size() > 0)
172 Iterator<Float> vals = scr.getScores().iterator();
173 // make features on sequence
174 for (Range rn : scr.getRanges())
178 String[] type = featureTypeMap.get(scr.getMethod());
181 // create a default type for this feature
183 { typeName + " (" + scr.getMethod() + ")",
184 service.getActionText() };
188 sf = new SequenceFeature(type[0], type[1], base + rn.from,
189 base + rn.to, val = vals.next().floatValue(),
194 sf = new SequenceFeature(type[0], type[1], null, base
195 + rn.from, base + rn.to, methodName);
197 dseq.addSequenceFeature(sf);
198 if (last != val && last != Float.NaN)
200 fc.put(sf.getType(), sf);
208 if (scr.getScores().size()==0)
212 AlignmentAnnotation annot = createAnnotationRowsForScores(
213 ourAnnot, service.serviceType + " (" + scr.getMethod()
214 + ")", service.getServiceTypeURI()+"/"+ scr.getMethod(), aseq,
216 annot.graph = AlignmentAnnotation.LINE_GRAPH;
217 annot.visible = (annotTypeMap==null || annotTypeMap.get(scr.getMethod())==null || annotTypeMap.get(scr.getMethod()).get(INVISIBLE) == null);
218 double[] thrsh=(annotTypeMap==null || annotTypeMap.get(scr.getMethod())==null) ? null : (double[]) annotTypeMap.get(scr.getMethod()).get(THRESHOLD);
219 if (annotTypeMap==null || annotTypeMap.get(scr.getMethod())==null || annotTypeMap.get(scr.getMethod()).get(DONTCOMBINE) == null)
228 annot.graphGroup = graphGroup;
232 annot.description = "<html>"+service.getActionText() + " - raw scores";
235 String threshNote=(thrsh[0]>0 ? "Above " : "Below ")+thrsh[1]+" indicates disorder";
236 annot.threshold=new GraphLine((float) thrsh[1], threshNote, Color.red);
237 annot.description+="<br/>"+threshNote;
239 annot.description+="</html>";
240 Color col = new UserColourScheme(typeName)
241 .createColourFromName(typeName + scr.getMethod());
242 for (int p = 0, ps = annot.annotations.length; p < ps; p++)
244 if (annot.annotations[p] != null)
246 annot.annotations[p].colour = col;
249 annot._linecolour=col;
252 if (lastAnnot + 1 == ourAnnot.size())
254 // remove singleton alignment annotation row
255 ourAnnot.get(lastAnnot).graphGroup = -1;
261 jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
262 .cloneFeatureRenderer();
263 for (String ft : fc.keySet())
265 Object gc = fr.getFeatureStyle(ft);
266 if (gc instanceof Color)
268 // set graduated color as fading to white for minimum, and
269 // autoscaling to values on alignment
270 GraduatedColor ggc = new GraduatedColor(Color.white,
271 (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
272 ggc.setAutoScaled(true);
273 fr.setColour(ft, ggc);
276 // TODO: JAL-1150 - create sequence feature settings API for defining styles and enabling/disabling feature overlay on alignment panel
277 ((jalview.gui.AlignmentPanel) ap).updateFeatureRendererFrom(fr);
278 if (af.alignPanel==ap)
280 // only do this if the alignFrame is currently showing this view.
281 af.setShowSeqFeatures(true);
283 ap.paintAlignment(true);
285 if (ourAnnot.size() > 0)
287 // Modify the visible annotation on the alignment viewport with the
288 // new alignment annotation rows created.
289 updateOurAnnots(ourAnnot);
290 ap.adjustAnnotationHeight();