2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws2;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.Annotation;
25 import jalview.datamodel.SequenceI;
26 import jalview.gui.AlignFrame;
27 import jalview.util.MessageManager;
28 import jalview.ws.jws2.jabaws2.Jws2Instance;
29 import jalview.ws.params.WsParamSetI;
31 import java.util.Iterator;
32 import java.util.List;
34 import compbio.data.msa.SequenceAnnotation;
35 import compbio.data.sequence.Score;
36 import compbio.data.sequence.ScoreManager;
37 import compbio.metadata.Argument;
38 import compbio.metadata.ChunkHolder;
39 import compbio.metadata.JobStatus;
40 import compbio.metadata.JobSubmissionException;
41 import compbio.metadata.ResultNotAvailableException;
42 import compbio.metadata.WrongParameterException;
44 public abstract class JabawsCalcWorker extends AbstractJabaCalcWorker
47 @SuppressWarnings("unchecked")
48 protected SequenceAnnotation aaservice;
50 protected ScoreManager scoremanager;
52 public JabawsCalcWorker(Jws2Instance service, AlignFrame alignFrame,
53 WsParamSetI preset, List<Argument> paramset)
55 super(service, alignFrame, preset, paramset);
56 aaservice = (SequenceAnnotation) service.service;
60 ChunkHolder pullExecStatistics(String rslt, long rpos)
62 return aaservice.pullExecStatistics(rslt, rpos);
66 boolean collectAnnotationResultsFor(String rslt)
67 throws ResultNotAvailableException
69 scoremanager = aaservice.getAnnotation(rslt);
70 if (scoremanager != null)
78 boolean cancelJob(String rslt) throws Exception
80 return aaservice.cancelJob(rslt);
84 protected JobStatus getJobStatus(String rslt) throws Exception
86 return aaservice.getJobStatus(rslt);
92 return aaservice != null;
96 protected boolean isInteractiveUpdate()
98 return this instanceof AAConClient;
102 protected String submitToService(
103 List<compbio.data.sequence.FastaSequence> seqs)
104 throws JobSubmissionException
107 if (preset == null && arguments == null)
109 rslt = aaservice.analize(seqs);
115 rslt = aaservice.customAnalize(seqs, getJabaArguments());
116 } catch (WrongParameterException x)
118 throw new JobSubmissionException(MessageManager.getString(
119 "exception.jobsubmission_invalid_params_set"), x);
126 protected void createAnnotationRowsForScores(
127 List<AlignmentAnnotation> ourAnnot, String calcId, int alWidth,
130 // simple annotation row
131 AlignmentAnnotation annotation = alignViewport.getAlignment()
132 .findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
134 if (alWidth == gapMap.length) // scr.getScores().size())
136 constructAnnotationFromScore(annotation, 0, alWidth, scr);
137 ourAnnot.add(annotation);
141 protected AlignmentAnnotation createAnnotationRowsForScores(
142 List<AlignmentAnnotation> ourAnnot, String typeName,
143 String calcId, SequenceI dseq, int base, Score scr)
145 System.out.println("Creating annotation on dseq:" + dseq.getStart()
146 + " base is " + base + " and length=" + dseq.getLength()
147 + " == " + scr.getScores().size());
148 // AlignmentAnnotation annotation = new AlignmentAnnotation(
149 // scr.getMethod(), typeName, new Annotation[]
150 // {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
151 // annotation.setCalcId(calcId);
152 AlignmentAnnotation annotation = alignViewport.getAlignment()
153 .findOrCreateAnnotation(typeName, calcId, false, dseq, null);
154 constructAnnotationFromScore(annotation, 0, dseq.getLength(), scr);
155 annotation.createSequenceMapping(dseq, base, false);
156 annotation.adjustForAlignment();
157 dseq.addAlignmentAnnotation(annotation);
158 ourAnnot.add(annotation);
162 protected void replaceAnnotationOnAlignmentWith(
163 AlignmentAnnotation newAnnot, String typeName, String calcId,
166 SequenceI dsseq = aSeq.getDatasetSequence();
167 while (dsseq.getDatasetSequence() != null)
169 dsseq = dsseq.getDatasetSequence();
171 // look for same annotation on dataset and lift this one over
172 List<AlignmentAnnotation> dsan = dsseq.getAlignmentAnnotations(calcId,
174 if (dsan != null && dsan.size() > 0)
176 for (AlignmentAnnotation dssan : dsan)
178 dsseq.removeAlignmentAnnotation(dssan);
181 AlignmentAnnotation dssan = new AlignmentAnnotation(newAnnot);
182 dsseq.addAlignmentAnnotation(dssan);
183 dssan.adjustForAlignment();
186 private void constructAnnotationFromScore(AlignmentAnnotation annotation,
187 int base, int alWidth, Score scr)
189 Annotation[] elm = new Annotation[alWidth];
190 Iterator<Float> vals = scr.getScores().iterator();
191 float m = 0f, x = 0f;
192 for (int i = 0; vals.hasNext(); i++)
194 float val = vals.next().floatValue();
212 // if we're at a gapped column then skip to next ungapped position
213 if (gapMap != null && gapMap.length > 0)
217 elm[i++] = new Annotation("", "", ' ', Float.NaN);
220 elm[i] = new Annotation("", "" + val, ' ', val);
223 annotation.annotations = elm;
224 annotation.belowAlignment = true;
230 annotation.graphMax = x;
231 annotation.graphMin = m;
232 annotation.validateRangeAndDisplay();