1 package jalview.ws.jws2.jabaws2;
3 import jalview.api.FeatureColourI;
4 import jalview.datamodel.Alignment;
5 import jalview.datamodel.AlignmentAnnotation;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.Annotation;
8 import jalview.datamodel.SequenceI;
9 import jalview.datamodel.features.FeatureMatcherSetI;
10 import jalview.util.MessageManager;
11 import jalview.ws.api.JobId;
12 import jalview.ws.api.SequenceAnnotationServiceI;
13 import jalview.ws.jws2.JabaParamStore;
14 import jalview.ws.jws2.JabaPreset;
15 import jalview.ws.params.ArgumentI;
16 import jalview.ws.params.WsParamSetI;
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
23 import compbio.data.msa.SequenceAnnotation;
24 import compbio.data.sequence.FastaSequence;
25 import compbio.data.sequence.Score;
26 import compbio.data.sequence.ScoreManager;
27 import compbio.metadata.JobSubmissionException;
28 import compbio.metadata.WrongParameterException;
30 public abstract class JabawsAnnotationInstance
31 extends JabawsServiceInstance<SequenceAnnotation>
32 implements SequenceAnnotationServiceI
36 * holds last results obtained when non-null. TODO: remove this as a field ?
38 protected ScoreManager scoremanager = null;
40 public JabawsAnnotationInstance(Jws2Instance handle)
48 * @return the calcId for this Jabaws Service (convenience method).
50 * TODO: decide if this is really convenient since manager and
51 * instance have same method !
53 public String getCalcId()
55 return our.getAlignAnalysisUI() == null ? null
56 : our.getAlignAnalysisUI().getCalcId();
60 public JobId submitToService(List<SequenceI> seqs, WsParamSetI preset,
61 List<ArgumentI> arguments) throws Throwable
65 List<FastaSequence> jabaseqs = new ArrayList(seqs.size());
66 for (SequenceI seq : seqs)
69 new FastaSequence(seq.getName(), seq.getSequenceAsString()));
71 if (preset == null && arguments == null)
73 rslt = service.analize(jabaseqs);
77 if (preset instanceof JabaPreset)
79 // TODO: verify behaviour is really the same, since preset analyze was
80 // never called in Jalview 2.11.x
81 rslt = service.presetAnalize(jabaseqs,
82 ((JabaPreset) preset).getJabaPreset());
86 rslt = service.customAnalize(jabaseqs,
87 JabaParamStore.getJabafromJwsArgs(preset.getArguments()));
90 else if (arguments != null && arguments.size() > 0)
94 rslt = service.customAnalize(jabaseqs,
95 JabaParamStore.getJabafromJwsArgs(arguments));
96 } catch (WrongParameterException x)
98 throw new JobSubmissionException(MessageManager.getString(
99 "exception.jobsubmission_invalid_params_set"), x);
108 return new JobId(our.getServiceType(), our.getName(), rslt);
114 List<AlignmentAnnotation> getAnnotationResult(JobId job,
115 List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
116 Map<String, FeatureMatcherSetI> featureFilters) throws Throwable
118 if (scoremanager == null)
120 // TODO: raise annotation unavailable exception ?
121 scoremanager = service.getAnnotation(job.getJobId());
123 if (scoremanager == null)
128 * dummy alignment to perform annotation on
130 AlignmentI newal = new Alignment(seqs.toArray(new SequenceI[0]));
131 List<AlignmentAnnotation> ourAnnot = annotationFromScoreManager(newal,
132 featureColours, featureFilters);
137 * service specific annotation creation method
140 * - sequences to be annotated with results
141 * @param featureColours
142 * - - updated with any colours imported during result processing
143 * @param featureFilters
144 * - updated with any filters imported during result processing
148 abstract List<AlignmentAnnotation> annotationFromScoreManager(
149 AlignmentI seqs, Map<String, FeatureColourI> featureColours,
150 Map<String, FeatureMatcherSetI> featureFilters);
154 * create and complete an annotation row from a JABAWS score object
156 * @param alignViewport
164 protected void createAnnotationRowsForScores(AlignmentI al_result,
165 boolean[] gapMap, List<AlignmentAnnotation> ourAnnot,
167 int alWidth, Score scr)
169 // simple annotation row
170 AlignmentAnnotation annotation = al_result
171 .findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
173 if (gapMap == null || alWidth == gapMap.length) // scr.getScores().size())
175 constructAnnotationFromScore(gapMap, annotation, 0,
177 ourAnnot.add(annotation);
182 * create a sequence associated annotation row for JABAWS score object scr
184 * @param alignViewport
194 protected AlignmentAnnotation createAnnotationRowsForScores(
195 AlignmentI alignment, boolean[] gapMap,
196 List<AlignmentAnnotation> ourAnnot, String typeName,
197 String calcId, SequenceI dseq, int base, Score scr)
199 System.out.println("Creating annotation on dseq:" + dseq.getStart()
200 + " base is " + base + " and length=" + dseq.getLength()
201 + " == " + scr.getScores().size());
202 // AlignmentAnnotation annotation = new AlignmentAnnotation(
203 // scr.getMethod(), typeName, new Annotation[]
204 // {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
205 // annotation.setCalcId(calcId);
206 AlignmentAnnotation annotation = alignment
207 .findOrCreateAnnotation(typeName, calcId, false, dseq, null);
208 constructAnnotationFromScore(gapMap, annotation, 0, dseq.getLength(),
210 annotation.createSequenceMapping(dseq, base, false);
211 annotation.adjustForAlignment();
212 dseq.addAlignmentAnnotation(annotation);
213 ourAnnot.add(annotation);
218 * create column annotation elements from Jabaws score object
225 * JABAWS score object
227 protected void constructAnnotationFromScore(boolean[] gapMap,
228 AlignmentAnnotation annotation,
229 int base, int alWidth, Score scr)
231 Annotation[] elm = new Annotation[alWidth];
232 Iterator<Float> vals = scr.getScores().iterator();
233 float m = 0f, x = 0f;
234 for (int i = 0; vals.hasNext(); i++)
236 float val = vals.next().floatValue();
254 // if we're at a gapped column then skip to next ungapped position
255 if (gapMap != null && gapMap.length > 0)
257 // if gapMap is a different length to the result then it may be out of
258 // sync with the job.
259 while (i < gapMap.length && !gapMap[i])
261 elm[i++] = new Annotation("", "", ' ', Float.NaN);
264 elm[i] = new Annotation("", "" + val, ' ', val);
267 annotation.annotations = elm;
268 annotation.belowAlignment = true;
274 annotation.graphMax = x;
275 annotation.graphMin = m;
276 annotation.validateRangeAndDisplay();