- List<Option> newargs = new ArrayList<Option>();
- if (preset != null && preset instanceof JabaWsParamSet)
- {
- newargs.addAll(((JabaWsParamSet) preset).getjabaArguments());
- }
- if (arguments != null && arguments.size() > 0)
- {
- for (Argument rg : arguments)
- {
- if (Option.class.isAssignableFrom(rg.getClass()))
- {
- newargs.add((Option) rg);
- }
- }
- }
- return newargs;
- }
-
- @Override
- public void run()
- {
- if (aaservice == null)
- {
- return;
- }
-
- try
- {
- if (checkDone())
- {
- return;
- }
- List<compbio.data.sequence.FastaSequence> seqs = getInputSequences(alignViewport
- .getAlignment());
-
- if (seqs == null)
- {
- calcMan.workerComplete(this);
- return;
- }
-
- AlignmentAnnotation[] aa = alignViewport.getAlignment()
- .getAlignmentAnnotation();
-
- String rslt;
- if (preset == null)
- {
- rslt = aaservice.analize(seqs);
- }
- else
- {
- try
- {
- rslt = aaservice.customAnalize(seqs, getJabaArguments());
- } catch (WrongParameterException x)
- {
- throw new JobSubmissionException(
- "Invalid paremeter set. Check Jalview implementation.", x);
-
- }
- }
- boolean finished = false;
- long rpos = 0;
- do
- {
- JobStatus status = aaservice.getJobStatus(rslt);
- if (status.equals(JobStatus.FINISHED))
- {
- finished = true;
- }
- long cpos;
- ChunkHolder stats;
- do
- {
- cpos = rpos;
- try
- {
- stats = aaservice.pullExecStatistics(rslt, rpos);
- } catch (Exception x)
- {
-
- if (x.getMessage().contains(
- "Position in a file could not be negative!"))
- {
- // squash index out of bounds exception- seems to happen for
- // disorder predictors which don't (apparently) produce any
- // progress information and JABA server throws an exception
- // because progress length is -1.
- stats = null;
- }
- else
- {
- throw x;
- }
- }
- if (stats != null)
- {
- System.out.print(stats.getChunk());
- rpos = stats.getNextPosition();
- }
- } while (stats != null && rpos > cpos);
-
- if (!finished && status.equals(JobStatus.FAILED))
- {
- try
- {
- Thread.sleep(200);
- } catch (InterruptedException x)
- {
- }
- ;
- }
-
- } while (!finished);
- try
- {
- Thread.sleep(200);
- } catch (InterruptedException x)
- {
- }
- ;
- scoremanager = aaservice.getAnnotation(rslt);
- if (scoremanager != null)
- {
- updateResultAnnotation(true);
- }
- } catch (JobSubmissionException x)
- {
-
- System.err.println("submission error:");
- x.printStackTrace();
- calcMan.workerCannotRun(this);
- } catch (ResultNotAvailableException x)
- {
- System.err.println("collection error:");
- x.printStackTrace();
- calcMan.workerCannotRun(this);
-
- } catch (OutOfMemoryError error)
- {
- calcMan.workerCannotRun(this);
-
- // consensus = null;
- // hconsensus = null;
- ap.raiseOOMWarning(getServiceActionText(), error);
- } catch (Exception x)
- {
- calcMan.workerCannotRun(this);
-
- // consensus = null;
- // hconsensus = null;
- System.err
- .println("Blacklisting worker due to unexpected exception:");
- x.printStackTrace();
- } finally
- {
-
- calcMan.workerComplete(this);
- if (ap != null)
- {
- ap.paintAlignment(true);
- }
- }
-
- }
-
- public void updateAnnotation()
- {
- updateResultAnnotation(false);
- }
-
- public abstract void updateResultAnnotation(boolean immediate);
-
- public abstract String getServiceActionText();
-
- boolean submitGaps = true;
-
- boolean alignedSeqs = true;
-
- boolean nucleotidesAllowed = false;
-
- boolean proteinAllowed = false;
-
- /**
- * record sequences for mapping result back to afterwards
- */
- protected boolean bySequence = false;
-
- Map<String, SequenceI> seqNames;
-
- public List<FastaSequence> getInputSequences(AlignmentI alignment)
- {
-
- if (alignment == null || alignment.getWidth() <= 0
- || alignment.getSequences() == null
-// || (alignedSeqs && !alignment.isAligned() && !submitGaps)
- || alignment.isNucleotide() ? !nucleotidesAllowed
- : !proteinAllowed)
- {
- return null;
- }
- List<compbio.data.sequence.FastaSequence> seqs = new ArrayList<compbio.data.sequence.FastaSequence>();
-
- int minlen = 10;
- int ln=-1;
- if (bySequence)
- {
- seqNames = new HashMap<String, SequenceI>();
- }
- for (SequenceI sq : ((List<SequenceI>) alignment.getSequences()))
- {
-
- if (sq.getEnd() - sq.getStart() > minlen - 1)
- {
- String newname = SeqsetUtils.unique_name(seqs.size() + 1);
- // make new input sequence with or without gaps
- if (seqNames != null)
- {
- seqNames.put(newname, sq);
- }
- FastaSequence seq;
- seqs.add(seq=new compbio.data.sequence.FastaSequence(newname,
- (submitGaps) ? sq.getSequenceAsString() : AlignSeq
- .extractGaps(jalview.util.Comparison.GapChars,
- sq.getSequenceAsString())));
- if (seq.getSequence().length()>ln)
- {
- ln = seq.getSequence().length();
- }
- }
- }
- if (alignedSeqs && submitGaps)
- {
- // try real hard to return something submittable
- // TODO: some of AAcons measures need a minimum of two or three amino acids at each position, and aacons doesn't gracefully degrade.
- for (int p=0; p<seqs.size();p++)
- {
- FastaSequence sq=seqs.get(p);
- int l=sq.getSequence().length();
- if (l<ln)
- {
- char[] padded=new char[ln];
- System.arraycopy(sq.getSequence().toCharArray(),0,padded,0,sq.getSequence().length());
- while (l<ln)
- {
- padded[l++]='-';
- }
- seqs.set(p, new compbio.data.sequence.FastaSequence(sq.getId(), new String(padded)));
- }
- }
-
- }
- return seqs;
- }
-
- protected AlignmentAnnotation findOrCreate(String name, boolean autoCalc,
- SequenceI seqRef, SequenceGroup groupRef)
- {
- for (AlignmentAnnotation annot : alignViewport.getAlignment()
- .getAlignmentAnnotation())
- {
- if (annot.autoCalculated == autoCalc
- && annot.getCalcId().equals(name)
- && annot.sequenceRef == seqRef && annot.groupRef == groupRef)
- {
- return annot;
- }
- }
- AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
- new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
- annot.hasText = false;
- annot.setCalcId(new String(name));
- annot.autoCalculated = autoCalc;
- if (seqRef != null)
- {
- annot.setSequenceRef(seqRef);
- }
- annot.groupRef = groupRef;
- alignViewport.getAlignment().addAnnotation(annot);
-
- return annot;