2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.workers.AlignCalcWorker;
44 import jalview.ws.jws2.jabaws2.Jws2Instance;
45 import jalview.ws.params.WsParamSetI;
47 public abstract class JabawsMsaInterfaceAlignCalcWorker extends AbstractJabaCalcWorker
50 @SuppressWarnings("unchecked")
51 protected MsaWS msaservice;
53 protected Alignment msascoreset;
55 public JabawsMsaInterfaceAlignCalcWorker(AlignViewportI alignViewport,
56 AlignmentViewPanel alignPanel)
58 super(alignViewport, alignPanel);
61 public JabawsMsaInterfaceAlignCalcWorker(Jws2Instance service, AlignFrame alignFrame,
62 WsParamSetI preset, List<Argument> paramset)
64 this(alignFrame.getCurrentView(), alignFrame.alignPanel);
65 this.guiProgress = alignFrame;
67 this.arguments = paramset;
68 this.service = service;
69 msaservice = (MsaWS) service.service;
74 ChunkHolder pullExecStatistics(String rslt, long rpos)
76 return msaservice.pullExecStatistics(rslt, rpos);
80 boolean collectAnnotationResultsFor(String rslt)
81 throws ResultNotAvailableException
83 msascoreset = msaservice.getResult(rslt);
84 if (msascoreset != null)
92 boolean cancelJob(String rslt) throws Exception
94 return msaservice.cancelJob(rslt);
98 protected JobStatus getJobStatus(String rslt) throws Exception
100 return msaservice.getJobStatus(rslt);
106 return msaservice != null;
110 protected boolean isInteractiveUpdate()
112 return false; // this instanceof AAConClient;
116 protected String submitToService(
117 List<compbio.data.sequence.FastaSequence> seqs)
118 throws JobSubmissionException
121 if (preset == null && arguments == null)
123 rslt = msaservice.align(seqs);
129 rslt = msaservice.customAlign(seqs, getJabaArguments());
130 } catch (WrongParameterException x)
132 throw new JobSubmissionException(
133 "Invalid parameter set. Check Jalview implementation.", x);
140 protected void createAnnotationRowsForScores(
141 List<AlignmentAnnotation> ourAnnot, String calcId, int alWidth,
144 // simple annotation row
145 AlignmentAnnotation annotation = alignViewport.getAlignment()
146 .findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
148 if (alWidth == gapMap.length) // scr.getScores().size())
150 constructAnnotationFromScore(annotation, 0, alWidth, scr);
151 ourAnnot.add(annotation);
155 protected AlignmentAnnotation createAnnotationRowsForScores(
156 List<AlignmentAnnotation> ourAnnot, String typeName,
157 String calcId, SequenceI dseq, int base, Score scr)
159 System.out.println("Creating annotation on dseq:" + dseq.getStart()
160 + " base is " + base + " and length=" + dseq.getLength()
161 + " == " + scr.getScores().size());
162 // AlignmentAnnotation annotation = new AlignmentAnnotation(
163 // scr.getMethod(), typeName, new Annotation[]
164 // {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
165 // annotation.setCalcId(calcId);
166 AlignmentAnnotation annotation = alignViewport.getAlignment()
167 .findOrCreateAnnotation(typeName, calcId, false, dseq, null);
168 constructAnnotationFromScore(annotation, 0, dseq.getLength(), scr);
169 annotation.createSequenceMapping(dseq, base, false);
170 annotation.adjustForAlignment();
171 dseq.addAlignmentAnnotation(annotation);
172 ourAnnot.add(annotation);
176 private void constructAnnotationFromScore(AlignmentAnnotation annotation,
177 int base, int alWidth, Score scr)
179 Annotation[] elm = new Annotation[alWidth];
180 Iterator<Float> vals = scr.getScores().iterator();
181 float m = 0f, x = 0f;
182 for (int i = 0; vals.hasNext(); i++)
184 float val = vals.next().floatValue();
202 // if we're at a gapped column then skip to next ungapped position
203 if (gapMap != null && gapMap.length > 0)
207 elm[i++] = new Annotation("", "", ' ', Float.NaN);
210 elm[i] = new Annotation("", "" + val, ' ', val);
213 annotation.annotations = elm;
214 annotation.belowAlignment = true;
220 annotation.graphMax = x;
221 annotation.graphMin = m;
222 annotation.validateRangeAndDisplay();