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 java.util.Iterator;
24 import java.util.List;
26 import compbio.data.msa.MsaWS;
27 import compbio.data.msa.SequenceAnnotation;
28 import compbio.data.sequence.Alignment;
29 import compbio.data.sequence.Score;
30 import compbio.data.sequence.ScoreManager;
31 import compbio.metadata.Argument;
32 import compbio.metadata.ChunkHolder;
33 import compbio.metadata.JobStatus;
34 import compbio.metadata.JobSubmissionException;
35 import compbio.metadata.ResultNotAvailableException;
36 import compbio.metadata.WrongParameterException;
37 import jalview.api.AlignViewportI;
38 import jalview.api.AlignmentViewPanel;
39 import jalview.datamodel.AlignmentAnnotation;
40 import jalview.datamodel.Annotation;
41 import jalview.datamodel.SequenceI;
42 import jalview.gui.AlignFrame;
43 import jalview.util.MessageManager;
44 import jalview.workers.AlignCalcWorker;
45 import jalview.ws.jws2.jabaws2.Jws2Instance;
46 import jalview.ws.params.WsParamSetI;
48 public abstract class JabawsMsaInterfaceAlignCalcWorker extends AbstractJabaCalcWorker
51 @SuppressWarnings("unchecked")
52 protected MsaWS msaservice;
54 protected Alignment msascoreset;
56 public JabawsMsaInterfaceAlignCalcWorker(AlignViewportI alignViewport,
57 AlignmentViewPanel alignPanel)
59 super(alignViewport, alignPanel);
62 public JabawsMsaInterfaceAlignCalcWorker(Jws2Instance service, AlignFrame alignFrame,
63 WsParamSetI preset, List<Argument> paramset)
65 this(alignFrame.getCurrentView(), alignFrame.alignPanel);
66 this.guiProgress = alignFrame;
68 this.arguments = paramset;
69 this.service = service;
70 msaservice = (MsaWS) service.service;
75 ChunkHolder pullExecStatistics(String rslt, long rpos)
77 return msaservice.pullExecStatistics(rslt, rpos);
81 boolean collectAnnotationResultsFor(String rslt)
82 throws ResultNotAvailableException
84 msascoreset = msaservice.getResult(rslt);
85 if (msascoreset != null)
93 boolean cancelJob(String rslt) throws Exception
95 return msaservice.cancelJob(rslt);
99 protected JobStatus getJobStatus(String rslt) throws Exception
101 return msaservice.getJobStatus(rslt);
107 return msaservice != null;
111 protected boolean isInteractiveUpdate()
113 return false; // this instanceof AAConClient;
117 protected String submitToService(
118 List<compbio.data.sequence.FastaSequence> seqs)
119 throws JobSubmissionException
122 if (preset == null && arguments == null)
124 rslt = msaservice.align(seqs);
130 rslt = msaservice.customAlign(seqs, getJabaArguments());
131 } catch (WrongParameterException x)
133 throw new JobSubmissionException(MessageManager.getString("exception.jobsubmission_invalid_params_set"), x);
139 protected void createAnnotationRowsForScores(
140 List<AlignmentAnnotation> ourAnnot, String calcId, int alWidth,
143 // simple annotation row
144 AlignmentAnnotation annotation = alignViewport.getAlignment()
145 .findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
147 if (alWidth == gapMap.length) // scr.getScores().size())
149 constructAnnotationFromScore(annotation, 0, alWidth, scr);
150 ourAnnot.add(annotation);
154 protected AlignmentAnnotation createAnnotationRowsForScores(
155 List<AlignmentAnnotation> ourAnnot, String typeName,
156 String calcId, SequenceI dseq, int base, Score scr)
158 System.out.println("Creating annotation on dseq:" + dseq.getStart()
159 + " base is " + base + " and length=" + dseq.getLength()
160 + " == " + scr.getScores().size());
161 // AlignmentAnnotation annotation = new AlignmentAnnotation(
162 // scr.getMethod(), typeName, new Annotation[]
163 // {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
164 // annotation.setCalcId(calcId);
165 AlignmentAnnotation annotation = alignViewport.getAlignment()
166 .findOrCreateAnnotation(typeName, calcId, false, dseq, null);
167 constructAnnotationFromScore(annotation, 0, dseq.getLength(), scr);
168 annotation.createSequenceMapping(dseq, base, false);
169 annotation.adjustForAlignment();
170 dseq.addAlignmentAnnotation(annotation);
171 ourAnnot.add(annotation);
175 private void constructAnnotationFromScore(AlignmentAnnotation annotation,
176 int base, int alWidth, Score scr)
178 Annotation[] elm = new Annotation[alWidth];
179 Iterator<Float> vals = scr.getScores().iterator();
180 float m = 0f, x = 0f;
181 for (int i = 0; vals.hasNext(); i++)
183 float val = vals.next().floatValue();
201 // if we're at a gapped column then skip to next ungapped position
202 if (gapMap != null && gapMap.length > 0)
206 elm[i++] = new Annotation("", "", ' ', Float.NaN);
209 elm[i] = new Annotation("", "" + val, ' ', val);
212 annotation.annotations = elm;
213 annotation.belowAlignment = true;
219 annotation.graphMax = x;
220 annotation.graphMin = m;
221 annotation.validateRangeAndDisplay();