1 package jalview.ws.jws2;
3 import jalview.analysis.AlignSeq;
4 import jalview.analysis.SeqsetUtils;
5 import jalview.api.AlignViewportI;
6 import jalview.api.AlignmentViewPanel;
7 import jalview.datamodel.AlignmentAnnotation;
8 import jalview.datamodel.AlignmentI;
9 import jalview.datamodel.Annotation;
10 import jalview.datamodel.SequenceGroup;
11 import jalview.datamodel.SequenceI;
12 import jalview.gui.AlignFrame;
13 import jalview.workers.AlignCalcWorker;
14 import jalview.ws.jws2.dm.JabaWsParamSet;
15 import jalview.ws.jws2.jabaws2.Jws2Instance;
16 import jalview.ws.params.WsParamSetI;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
23 import com.sun.xml.internal.ws.developer.ServerSideException;
24 import compbio.data.msa.SequenceAnnotation;
25 import compbio.data.sequence.FastaSequence;
26 import compbio.data.sequence.ScoreManager;
27 import compbio.metadata.Argument;
28 import compbio.metadata.ChunkHolder;
29 import compbio.metadata.JobStatus;
30 import compbio.metadata.JobSubmissionException;
31 import compbio.metadata.Option;
32 import compbio.metadata.ResultNotAvailableException;
33 import compbio.metadata.WrongParameterException;
35 public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
38 @SuppressWarnings("unchecked")
39 protected SequenceAnnotation aaservice;
41 protected ScoreManager scoremanager;
43 protected WsParamSetI preset;
45 protected List<Argument> arguments;
47 public JabawsAlignCalcWorker(AlignViewportI alignViewport,
48 AlignmentViewPanel alignPanel)
50 super(alignViewport, alignPanel);
53 public JabawsAlignCalcWorker(Jws2Instance service, AlignFrame alignFrame,
54 WsParamSetI preset, List<Argument> paramset)
56 this(alignFrame.getCurrentView(), alignFrame.alignPanel);
58 this.arguments = paramset;
59 aaservice = (SequenceAnnotation) service.service;
63 public WsParamSetI getPreset()
68 public List<Argument> getArguments()
74 * reconfigure and restart the AAConsClient. This method will spawn a new
75 * thread that will wait until any current jobs are finished, modify the
76 * parameters and restart the conservation calculation with the new values.
81 public void updateParameters(final WsParamSetI newpreset,
82 final List<Argument> newarguments)
84 if (calcMan.isWorking(this))
86 new Thread(new Runnable()
95 } catch (InterruptedException x)
99 updateParameters(newpreset, newarguments);
106 arguments = newarguments;
107 calcMan.startWorker(this);
111 public List<Option> getJabaArguments()
113 List<Option> newargs = new ArrayList<Option>();
114 if (preset != null && preset instanceof JabaWsParamSet)
116 newargs.addAll(((JabaWsParamSet) preset).getjabaArguments());
118 if (arguments != null && arguments.size() > 0)
120 for (Argument rg : arguments)
122 if (Option.class.isAssignableFrom(rg.getClass()))
124 newargs.add((Option) rg);
134 if (aaservice == null)
145 List<compbio.data.sequence.FastaSequence> seqs = getInputSequences(alignViewport
150 calcMan.workerComplete(this);
154 AlignmentAnnotation[] aa = alignViewport.getAlignment()
155 .getAlignmentAnnotation();
160 rslt = aaservice.analize(seqs);
166 rslt = aaservice.customAnalize(seqs, getJabaArguments());
167 } catch (WrongParameterException x)
169 throw new JobSubmissionException(
170 "Invalid paremeter set. Check Jalview implementation.", x);
174 boolean finished = false;
178 JobStatus status = aaservice.getJobStatus(rslt);
179 if (status.equals(JobStatus.FINISHED))
190 stats = aaservice.pullExecStatistics(rslt, rpos);
191 } catch (Exception x)
194 if (x.getCause() instanceof ServerSideException)
196 if (x.getMessage().contains("Position in a file could not be negative!"))
198 // squash index out of bounds exception- seems to happen for
199 // disorder predictors which don't (apparently) produce any
200 // progress information and JABA server throws an exception
201 // because progress length is -1.
216 System.out.print(stats.getChunk());
217 rpos = stats.getNextPosition();
219 } while (stats != null && rpos > cpos);
221 if (!finished && status.equals(JobStatus.FAILED))
226 } catch (InterruptedException x)
236 } catch (InterruptedException x)
240 scoremanager = aaservice.getAnnotation(rslt);
241 if (scoremanager != null)
243 updateResultAnnotation(true);
245 } catch (JobSubmissionException x)
248 System.err.println("submission error:");
250 calcMan.workerCannotRun(this);
251 } catch (ResultNotAvailableException x)
253 System.err.println("collection error:");
255 calcMan.workerCannotRun(this);
257 } catch (OutOfMemoryError error)
259 calcMan.workerCannotRun(this);
262 // hconsensus = null;
263 ap.raiseOOMWarning(getServiceActionText(), error);
264 } catch (Exception x)
266 calcMan.workerCannotRun(this);
269 // hconsensus = null;
271 .println("Blacklisting worker due to unexpected exception:");
276 calcMan.workerComplete(this);
279 ap.paintAlignment(true);
285 public void updateAnnotation()
287 updateResultAnnotation(false);
290 public abstract void updateResultAnnotation(boolean immediate);
292 public abstract String getServiceActionText();
294 boolean submitGaps = true;
296 boolean alignedSeqs = true;
298 boolean nucleotidesAllowed = false;
300 boolean proteinAllowed = false;
303 * record sequences for mapping result back to afterwards
305 protected boolean bySequence=false;
307 Map<String,SequenceI> seqNames;
308 public List<FastaSequence> getInputSequences(AlignmentI alignment)
311 if (alignment == null || alignment.getWidth() <= 0
312 || alignment.getSequences() == null
313 || (alignedSeqs && !alignment.isAligned())
314 || alignment.isNucleotide() ? !nucleotidesAllowed
319 List<compbio.data.sequence.FastaSequence> seqs = new ArrayList<compbio.data.sequence.FastaSequence>();
324 seqNames=new HashMap<String,SequenceI>();
326 for (SequenceI sq : ((List<SequenceI>) alignment.getSequences()))
329 if (sq.getEnd() - sq.getStart() > minlen - 1)
331 String newname = SeqsetUtils.unique_name(seqs.size() + 1);
332 // make new input sequence with or without gaps
333 if (seqNames!=null) {
334 seqNames.put(newname,sq);
336 seqs.add(new compbio.data.sequence.FastaSequence(newname,
337 (submitGaps) ? sq.getSequenceAsString() : AlignSeq
338 .extractGaps(jalview.util.Comparison.GapChars,
339 sq.getSequenceAsString())));
345 protected AlignmentAnnotation findOrCreate(String name, boolean autoCalc,
346 SequenceI seqRef, SequenceGroup groupRef)
348 for (AlignmentAnnotation annot : alignViewport.getAlignment()
349 .getAlignmentAnnotation())
351 if (annot.autoCalculated == autoCalc
352 && annot.getCalcId().equals(name)
353 && annot.sequenceRef == seqRef && annot.groupRef == groupRef)
358 AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
359 new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
360 annot.hasText = false;
361 annot.setCalcId(new String(name));
362 annot.autoCalculated = autoCalc;
365 annot.setSequenceRef(seqRef);
367 annot.groupRef = groupRef;
368 alignViewport.getAlignment().addAnnotation(annot);
374 * notify manager that we have started, and wait for a free calculation slot
376 * @return true if slot is obtained and work still valid, false if another
377 * thread has done our work for us.
381 calcMan.notifyStart(this);
382 // ap.paintAlignment(false);
383 while (!calcMan.notifyWorking(this))
385 if (calcMan.isWorking(this))
393 ap.paintAlignment(false);
397 } catch (Exception ex)
399 ex.printStackTrace();
402 if (alignViewport.isClosed())