package jalview.ws.jws2;
import jalview.analysis.AlignSeq;
+import jalview.analysis.AlignmentAnnotationUtils;
import jalview.analysis.SeqsetUtils;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureColourI;
import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.ContiguousI;
+import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
import jalview.gui.IProgressIndicator;
import jalview.gui.IProgressIndicatorHandler;
import jalview.gui.JvOptionPane;
+import jalview.gui.WebserviceInfo;
+import jalview.schemes.FeatureSettingsAdapter;
import jalview.schemes.ResidueProperties;
+import jalview.util.MapList;
import jalview.util.MessageManager;
import jalview.workers.AlignCalcWorker;
+import jalview.ws.JobStateSummary;
import jalview.ws.api.CancellableI;
+import jalview.ws.api.JalviewServiceEndpointProviderI;
import jalview.ws.api.JobId;
import jalview.ws.api.SequenceAnnotationServiceI;
+import jalview.ws.api.ServiceWithParameters;
import jalview.ws.api.WSAnnotationCalcManagerI;
import jalview.ws.gui.AnnotationWsJob;
import jalview.ws.jws2.dm.AAConSettings;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.WsParamSetI;
implements WSAnnotationCalcManagerI
{
- protected Jws2Instance service;
+ protected ServiceWithParameters service;
protected WsParamSetI preset;
super(alignViewport, alignPanel);
}
- public SeqAnnotationServiceCalcWorker(Jws2Instance service, AlignFrame alignFrame,
+ public SeqAnnotationServiceCalcWorker(ServiceWithParameters service,
+ AlignFrame alignFrame,
WsParamSetI preset, List<ArgumentI> paramset)
{
this(alignFrame.getCurrentView(), alignFrame.alignPanel);
this.service = service;
try
{
- annotService = (jalview.ws.api.SequenceAnnotationServiceI) service
+ annotService = (jalview.ws.api.SequenceAnnotationServiceI) ((JalviewServiceEndpointProviderI) service)
.getEndpoint();
} catch (ClassCastException cce)
{
}
// configure submission flags
- if (service.getAlignAnalysisUI() != null)
+ proteinAllowed = service.isProteinService();
+ nucleotidesAllowed = service.isNucleotideService();
+ alignedSeqs = service.isNeedsAlignedSequences();
+ bySequence = !service.isAlignmentAnalysis();
+ filterNonStandardResidues = service.isFilterSymbols();
+ min_valid_seqs = service.getMinimumInputSequences();
+ submitGaps = service.isAlignmentAnalysis();
+
+ if (service.isInteractiveUpdate())
{
- // instantaneous calculation. Right now that's either AACons or RNAAliFold
- proteinAllowed = service.getAlignAnalysisUI().isPr();
- nucleotidesAllowed = service.getAlignAnalysisUI().isNa();
- alignedSeqs = service.getAlignAnalysisUI().isNeedsAlignedSeqs();
- bySequence = !service.getAlignAnalysisUI().isAA();
- filterNonStandardResidues = service.getAlignAnalysisUI()
- .isFilterSymbols();
- min_valid_seqs = service.getAlignAnalysisUI().getMinimumSequences();
initViewportParams();
}
- else
- {
- // assume disorder prediction : per-sequence protein only no gaps
- // analysis.
- // TODO - move configuration to UIInfo base class for all these flags !
- alignedSeqs = false;
- bySequence = true;
- filterNonStandardResidues = true;
- nucleotidesAllowed = false;
- proteinAllowed = true;
- submitGaps = false;
- min_valid_seqs = 1;
- }
}
/**
@Override
public void run()
{
+ if (checkDone())
+ {
+ return;
+ }
if (!hasService())
{
+ calcMan.workerComplete(this);
return;
}
final boolean cancellable = CancellableI.class
.isAssignableFrom(annotService.getClass());
StringBuffer msg = new StringBuffer();
+ JobStateSummary job = new JobStateSummary();
+ WebserviceInfo info = new WebserviceInfo("foo", "bar", false);
try
{
- if (checkDone())
- {
- return;
- }
List<SequenceI> seqs = getInputSequences(
alignViewport.getAlignment(),
bySequence ? alignViewport.getSelectionGroup() : null);
return;
}
- AlignmentAnnotation[] aa = alignViewport.getAlignment()
- .getAlignmentAnnotation();
if (guiProgress != null)
{
guiProgress.setProgressBar(service.getActionText(),
return;
}
// TODO: handle job submission error reporting here.
-
+ Cache.log.debug("Service " + service.getUri() + "\nSubmitted job ID: "
+ + rslt);
+ ;
// ///
// otherwise, construct WsJob and any UI handlers
running = new AnnotationWsJob();
running.setSeqNames(seqNames);
running.setStartPos(start);
running.setSeqs(seqs);
-
+ job.updateJobPanelState(info, "", running);
if (guiProgress != null)
{
guiProgress.registerHandler(progressId,
// and poll for updates until job finishes, fails or becomes stale
boolean finished = false;
- long rpos = 0;
do
{
Cache.log.debug("Updating status for annotation service.");
annotService.updateStatus(running);
-
- if (running.isFinished())
+ job.updateJobPanelState(info, "", running);
+ if (running.isSubjobComplete())
{
- Cache.log.debug("Analysis service job reported finished.");
+ Cache.log.debug(
+ "Finished polling analysis service job: status reported is "
+ + running.getState());
finished = true;
}
else
if (cancellable
&& ((CancellableI) annotService).cancel(running))
{
- System.err.println("Cancelled AACon job: " + rslt);
+ System.err.println("Cancelled job: " + rslt);
}
else
{
- System.err.println("FAILED TO CANCEL AACon job: " + rslt);
+ System.err.println("FAILED TO CANCEL job: " + rslt);
}
} catch (Exception x)
}
} while (!finished);
+ Cache.log.debug("Job poll loop exited. Job is " + running.getState());
// TODO: need to poll/retry
if (serverErrorsLeft > 0)
{
{
}
}
- // configure job with the associated view's feature renderer, if one
- // exists.
- // TODO: here one would also grab the 'master feature renderer' in order
- // to enable/disable
- // features automatically according to user preferences
- running.setFeatureRenderer(
- ((jalview.gui.AlignmentPanel) ap).cloneFeatureRenderer());
- Cache.log.debug("retrieving job results.");
- List<AlignmentAnnotation> returnedAnnot = annotService
- .getAlignmentAnnotation(running, this);
- Cache.log.debug("Obtained " + (returnedAnnot == null ? "no rows"
- : ("" + returnedAnnot.size())));
- running.setAnnotation(returnedAnnot);
-
- if (running.hasResults())
+ if (running.isFinished())
{
- jalview.bin.Cache.log.debug("Updating result annotation from Job "
- + rslt + " at " + service.getUri());
- updateResultAnnotation(true);
- if (running.isTransferSequenceFeatures())
+ // expect there to be results to collect
+ // configure job with the associated view's feature renderer, if one
+ // exists.
+ // TODO: here one would also grab the 'master feature renderer' in order
+ // to enable/disable
+ // features automatically according to user preferences
+ running.setFeatureRenderer(
+ ((jalview.gui.AlignmentPanel) ap).cloneFeatureRenderer());
+ Cache.log.debug("retrieving job results.");
+ final Map<String, FeatureColourI> featureColours = new HashMap<>();
+ final Map<String, FeatureMatcherSetI> featureFilters = new HashMap<>();
+ List<AlignmentAnnotation> returnedAnnot = annotService
+ .getAnnotationResult(running.getJobHandle(), seqs,
+ featureColours, featureFilters);
+
+ Cache.log.debug("Obtained " + (returnedAnnot == null ? "no rows"
+ : ("" + returnedAnnot.size())));
+ Cache.log.debug("There were " + featureColours.size()
+ + " feature colours and " + featureFilters.size()
+ + " filters defined.");
+
+ // TODO
+ // copy over each annotation row reurned and also defined on each
+ // sequence, excluding regions not annotated due to gapMap/column
+ // visibility
+
+ // update calcId if it is not already set on returned annotation
+ if (returnedAnnot != null)
{
- jalview.bin.Cache.log.debug(
- "Updating feature display settings and transferring features from Job "
- + rslt + " at " + service.getUri());
- ((jalview.gui.AlignmentPanel) ap)
- .updateFeatureRendererFrom(running.getFeatureRenderer());
- // TODO: JAL-1150 - create sequence feature settings API for defining
- // styles and enabling/disabling feature overlay on alignment panel
-
- if (alignFrame.alignPanel == ap)
+ for (AlignmentAnnotation aa : returnedAnnot)
{
- // only do this if the alignFrame is currently showing this view.
- Desktop.getAlignFrameFor(alignViewport)
- .setShowSeqFeatures(true);
+ // assume that any CalcIds already set
+ if (getCalcId() != null && aa.getCalcId() == null
+ || "".equals(aa.getCalcId()))
+ {
+ aa.setCalcId(getCalcId());
+ }
+ // autocalculated annotation are created by interactive alignment
+ // analysis services
+ aa.autoCalculated = service.isAlignmentAnalysis()
+ && service.isInteractiveUpdate();
+ }
+ }
+
+ running.setAnnotation(returnedAnnot);
+
+ if (running.hasResults())
+ {
+ jalview.bin.Cache.log.debug("Updating result annotation from Job "
+ + rslt + " at " + service.getUri());
+ updateResultAnnotation(true);
+ if (running.isTransferSequenceFeatures())
+ {
+ // TODO
+ // look at each sequence and lift over any features, excluding
+ // regions
+ // not annotated due to gapMap/column visibility
+
+ jalview.bin.Cache.log.debug(
+ "Updating feature display settings and transferring features from Job "
+ + rslt + " at " + service.getUri());
+ // TODO: consider merge rather than apply here
+ alignViewport.applyFeaturesStyle(new FeatureSettingsAdapter()
+ {
+ @Override
+ public FeatureColourI getFeatureColour(String type)
+ {
+ return featureColours.get(type);
+ }
+
+ @Override
+ public FeatureMatcherSetI getFeatureFilters(String type)
+ {
+ return featureFilters.get(type);
+ }
+
+ @Override
+ public boolean isFeatureDisplayed(String type)
+ {
+ return featureColours.containsKey(type);
+ }
+
+ });
+ // TODO: JAL-1150 - create sequence feature settings API for
+ // defining
+ // styles and enabling/disabling feature overlay on alignment panel
+
+ if (alignFrame.alignPanel == ap)
+ {
+ alignViewport.setShowSequenceFeatures(true);
+ alignFrame.setMenusForViewport();
+ }
}
+ ap.adjustAnnotationHeight();
}
- ap.adjustAnnotationHeight();
}
Cache.log.debug("Annotation Service Worker thread finished.");
}
calcMan.workerComplete(this);
if (ap != null)
{
- calcMan.workerComplete(this);
if (guiProgress != null && progressId != -1)
{
guiProgress.setProgressBar("", progressId);
if ((immediate || !calcMan.isWorking(this)) && running != null
&& running.hasResults())
{
- List<AlignmentAnnotation> ourAnnot = running.getAnnotation();
- updateOurAnnots(ourAnnot);
+ List<AlignmentAnnotation> ourAnnot = running.getAnnotation(),
+ newAnnots = new ArrayList<>();
+ //
+ // update graphGroup for all annotation
+ //
+ /**
+ * find a graphGroup greater than any existing ones this could be a method
+ * provided by alignment Alignment.getNewGraphGroup() - returns next
+ * unused graph group
+ */
+ int graphGroup = 1;
+ if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
+ {
+ for (AlignmentAnnotation ala : alignViewport.getAlignment()
+ .getAlignmentAnnotation())
+ {
+ if (ala.graphGroup > graphGroup)
+ {
+ graphGroup = ala.graphGroup;
+ }
+ }
+ }
+ /**
+ * update graphGroup in the annotation rows returned from service
+ */
+ // TODO: look at sequence annotation rows and update graph groups in the
+ // case of reference annotation.
+ for (AlignmentAnnotation ala : ourAnnot)
+ {
+ if (ala.graphGroup > 0)
+ {
+ ala.graphGroup += graphGroup;
+ }
+ SequenceI aseq = null;
+
+ /**
+ * transfer sequence refs and adjust gapmap
+ */
+ if (ala.sequenceRef != null)
+ {
+ SequenceI seq = running.getSeqNames()
+ .get(ala.sequenceRef.getName());
+ aseq = seq;
+ while (seq.getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ }
+ Annotation[] resAnnot = ala.annotations,
+ gappedAnnot = new Annotation[Math.max(
+ alignViewport.getAlignment().getWidth(),
+ gapMap.length)];
+ for (int p = 0, ap = start; ap < gappedAnnot.length; ap++)
+ {
+ if (gapMap != null && gapMap.length > ap && !gapMap[ap])
+ {
+ gappedAnnot[ap] = new Annotation("", "", ' ', Float.NaN);
+ }
+ else if (p < resAnnot.length)
+ {
+ gappedAnnot[ap] = resAnnot[p++];
+ }
+ }
+ ala.sequenceRef = aseq;
+ ala.annotations = gappedAnnot;
+ AlignmentAnnotation newAnnot = getAlignViewport().getAlignment()
+ .updateFromOrCopyAnnotation(ala);
+ if (aseq != null)
+ {
+
+ aseq.addAlignmentAnnotation(newAnnot);
+ newAnnot.adjustForAlignment();
+
+ AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(
+ newAnnot, newAnnot.label, newAnnot.getCalcId());
+ }
+ newAnnots.add(newAnnot);
+
+ }
+ for (SequenceI sq : running.getSeqs())
+ {
+ if (!sq.getFeatures().hasFeatures()
+ && (sq.getDBRefs() == null || sq.getDBRefs().length == 0))
+ {
+ continue;
+ }
+ running.setTransferSequenceFeatures(true);
+ SequenceI seq = running.getSeqNames().get(sq.getName());
+ SequenceI dseq;
+ ContiguousI seqRange = seq.findPositions(start, end);
+
+ while ((dseq = seq).getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ List<ContiguousI> sourceRange = new ArrayList();
+ if (gapMap != null && gapMap.length >= end)
+ {
+ int lastcol = start, col = start;
+ do
+ {
+ if (col == end || !gapMap[col])
+ {
+ if (lastcol <= (col - 1))
+ {
+ seqRange = seq.findPositions(lastcol, col);
+ sourceRange.add(seqRange);
+ }
+ lastcol = col + 1;
+ }
+ } while (++col <= end);
+ }
+ else
+ {
+ sourceRange.add(seq.findPositions(start, end));
+ }
+ int i = 0;
+ int source_startend[] = new int[sourceRange.size() * 2];
+
+ for (ContiguousI range : sourceRange)
+ {
+ source_startend[i++] = range.getBegin();
+ source_startend[i++] = range.getEnd();
+ }
+ Mapping mp = new Mapping(
+ new MapList(source_startend, new int[]
+ { seq.getStart(), seq.getEnd() }, 1, 1));
+ dseq.transferAnnotation(sq, mp);
+
+ }
+ updateOurAnnots(newAnnots);
}
}
}
}
our.clear();
- // validate rows and update Alignmment state
- for (AlignmentAnnotation an : ourAnnots)
- {
- alignViewport.getAlignment().validateAnnotation(an);
- }
- // TODO: may need a menu refresh after this
- // af.setMenusForViewport();
- ap.adjustAnnotationHeight();
}
+
+ // validate rows and update Alignmment state
+ for (AlignmentAnnotation an : ourAnnots)
+ {
+ alignViewport.getAlignment().validateAnnotation(an);
+ }
+ // TODO: may need a menu refresh after this
+ // af.setMenusForViewport();
+ ap.adjustAnnotationHeight();
+
}
public SequenceAnnotationServiceI getService()