1 package jalview.ws2.actions.secstructpred;
3 import java.io.IOException;
6 import jalview.analysis.AlignmentAnnotationUtils;
7 import jalview.api.AlignViewportI;
8 import jalview.bin.Console;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentAnnotation;
11 import jalview.datamodel.AlignmentI;
12 import jalview.datamodel.AlignmentView;
13 import jalview.io.AlignFile;
14 import jalview.io.JPredFile;
15 import jalview.io.JnetAnnotationMaker;
16 import jalview.util.Comparison;
17 import jalview.ws.params.ArgumentI;
18 import jalview.ws2.actions.BaseJob;
19 import jalview.ws2.actions.BaseTask;
20 import jalview.ws2.actions.ServiceInputInvalidException;
21 import jalview.ws2.api.Credentials;
22 import jalview.ws2.api.JobStatus;
23 import jalview.ws2.client.api.SecStructPredWebServiceClientI;
25 public class SecStructPredTask extends BaseTask<BaseJob, AlignmentI>
27 private final SecStructPredWebServiceClientI client;
29 private final AlignmentView alignmentView;
31 private final AlignmentI currentView;
33 private final char gapChar;
35 SecStructPredTask(SecStructPredWebServiceClientI client, List<ArgumentI> args,
36 Credentials credentials, AlignViewportI viewport)
38 super(client, args, credentials);
40 this.alignmentView = viewport.getAlignmentView(true);
41 this.currentView = viewport.getAlignment();
42 this.gapChar = viewport.getGapCharacter();
46 protected List<BaseJob> prepareJobs() throws ServiceInputInvalidException
48 AlignmentI alignment = alignmentView
49 .getVisibleAlignment(Comparison.GAP_DASH);
50 var job = new BaseJob(alignment.getSequences())
53 public boolean isInputValid()
58 job.setStatus(JobStatus.READY);
63 protected AlignmentI collectResult(List<BaseJob> jobs) throws IOException
65 var job = jobs.get(0); // There shouldn't be more than one job
66 var status = job.getStatus();
69 .format("sec str pred job \"%s\" finished with status %s",
70 job.getServerJob().getJobId(), status));
71 if (status != JobStatus.COMPLETED)
73 JPredFile predictionFile = client.getPredictionFile(job.getServerJob());
74 AlignFile alignmentFile = client.getAlignmentFile(job.getServerJob());
75 // Object[] alnAndHiddenCols =
76 // alignmentView.getAlignmentAndHiddenColumns(gapChar);
77 // SequenceI[] sequences = (SequenceI[]) alnAndHiddenCols[0];
78 var sequences = alignmentFile.getSeqsAsArray();
79 // HiddenColumns hiddenCols = (HiddenColumns) alnAndHiddenCols[1];
80 var aln = new Alignment(sequences);
82 aln.setDataset(currentView.getDataset());
85 JnetAnnotationMaker.add_annotation(predictionFile, aln, firstSeq, false);
88 throw new IOException(e);
91 for (AlignmentAnnotation alnAnnot : aln.getAlignmentAnnotation())
93 if (alnAnnot.sequenceRef != null)
95 AlignmentAnnotationUtils
96 .replaceAnnotationOnAlignmentWith(alnAnnot, alnAnnot.label,
97 getClass().getSimpleName());
100 aln.setSeqrep(aln.getSequenceAt(firstSeq));