From: Mateusz Warowny Date: Thu, 5 Oct 2023 13:12:55 +0000 (+0200) Subject: JAL-1601 Create action and task for sec. str. pred. jobs X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=589fd82e772d0f17cdb49eb995f6a45603d87176;p=jalview.git JAL-1601 Create action and task for sec. str. pred. jobs --- diff --git a/src/jalview/ws2/actions/secstructpred/SecStructPredAction.java b/src/jalview/ws2/actions/secstructpred/SecStructPredAction.java new file mode 100644 index 0000000..a74965e --- /dev/null +++ b/src/jalview/ws2/actions/secstructpred/SecStructPredAction.java @@ -0,0 +1,58 @@ +package jalview.ws2.actions.secstructpred; + +import java.util.List; +import java.util.Objects; + +import jalview.api.AlignViewportI; +import jalview.datamodel.AlignmentI; +import jalview.viewmodel.AlignmentViewport; +import jalview.ws.params.ArgumentI; +import jalview.ws2.actions.BaseAction; +import jalview.ws2.api.Credentials; +import jalview.ws2.client.api.SecStructPredWebServiceClientI; +import jalview.ws2.client.api.WebServiceClientI; + +public class SecStructPredAction extends BaseAction +{ + public static class Builder extends BaseAction.Builder + { + protected SecStructPredWebServiceClientI client; + + private Builder(SecStructPredWebServiceClientI client) + { + super(); + Objects.requireNonNull(client); + this.client = client; + } + + public SecStructPredAction build() + { + return new SecStructPredAction(this); + } + } + + public static Builder newBuilder(SecStructPredWebServiceClientI client) + { + return new Builder(client); + } + + protected final SecStructPredWebServiceClientI client; + + public SecStructPredAction(Builder builder) + { + super(builder); + client = builder.client; + } + + public SecStructPredTask createTask(AlignViewportI viewport, + List args, Credentials credentials) + { + return new SecStructPredTask(client, args, credentials, viewport); + } + + @Override + public boolean isActive(AlignmentViewport viewport) + { + return false; + } +} diff --git a/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java b/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java new file mode 100644 index 0000000..1bbd494 --- /dev/null +++ b/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java @@ -0,0 +1,104 @@ +package jalview.ws2.actions.secstructpred; + +import java.io.IOException; +import java.util.List; + +import jalview.analysis.AlignmentAnnotationUtils; +import jalview.api.AlignViewportI; +import jalview.bin.Console; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AlignmentView; +import jalview.io.AlignFile; +import jalview.io.JPredFile; +import jalview.io.JnetAnnotationMaker; +import jalview.util.Comparison; +import jalview.ws.params.ArgumentI; +import jalview.ws2.actions.BaseJob; +import jalview.ws2.actions.BaseTask; +import jalview.ws2.actions.ServiceInputInvalidException; +import jalview.ws2.api.Credentials; +import jalview.ws2.api.JobStatus; +import jalview.ws2.client.api.SecStructPredWebServiceClientI; + +public class SecStructPredTask extends BaseTask +{ + private final SecStructPredWebServiceClientI client; + + private final AlignmentView alignmentView; + + private final AlignmentI currentView; + + private final char gapChar; + + SecStructPredTask(SecStructPredWebServiceClientI client, List args, + Credentials credentials, AlignViewportI viewport) + { + super(client, args, credentials); + this.client = client; + this.alignmentView = viewport.getAlignmentView(true); + this.currentView = viewport.getAlignment(); + this.gapChar = viewport.getGapCharacter(); + } + + @Override + protected List prepareJobs() throws ServiceInputInvalidException + { + AlignmentI alignment = alignmentView + .getVisibleAlignment(Comparison.GAP_DASH); + var job = new BaseJob(alignment.getSequences()) + { + @Override + public boolean isInputValid() + { + return true; + } + }; + job.setStatus(JobStatus.READY); + return List.of(job); + } + + @Override + protected AlignmentI collectResult(List jobs) throws IOException + { + var job = jobs.get(0); // There shouldn't be more than one job + var status = job.getStatus(); + Console + .info(String + .format("sec str pred job \"%s\" finished with status %s", + job.getServerJob().getJobId(), status)); + if (status != JobStatus.COMPLETED) + return null; + JPredFile predictionFile = client.getPredictionFile(job.getServerJob()); + AlignFile alignmentFile = client.getAlignmentFile(job.getServerJob()); + // Object[] alnAndHiddenCols = + // alignmentView.getAlignmentAndHiddenColumns(gapChar); + // SequenceI[] sequences = (SequenceI[]) alnAndHiddenCols[0]; + var sequences = alignmentFile.getSeqsAsArray(); + // HiddenColumns hiddenCols = (HiddenColumns) alnAndHiddenCols[1]; + var aln = new Alignment(sequences); + int firstSeq = 0; + aln.setDataset(currentView.getDataset()); + try + { + JnetAnnotationMaker.add_annotation(predictionFile, aln, firstSeq, false); + } catch (Exception e) + { + throw new IOException(e); + } + + for (AlignmentAnnotation alnAnnot : aln.getAlignmentAnnotation()) + { + if (alnAnnot.sequenceRef != null) + { + AlignmentAnnotationUtils + .replaceAnnotationOnAlignmentWith(alnAnnot, alnAnnot.label, + getClass().getSimpleName()); + } + } + aln.setSeqrep(aln.getSequenceAt(firstSeq)); + return aln; + } + +}