From d01453133dd3b6247e4d0a12a6dd6886d6053a6c Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Fri, 13 Oct 2023 15:05:20 +0200 Subject: [PATCH] JAL-1601 Create SecStructPredTask class --- src/jalview/datamodel/AlignmentView.java | 2 +- .../actions/secstructpred/SecStructPredJob.java | 32 +++++++++++++++++ .../actions/secstructpred/SecStructPredTask.java | 38 ++++++++++++++------ 3 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/jalview/ws2/actions/secstructpred/SecStructPredJob.java diff --git a/src/jalview/datamodel/AlignmentView.java b/src/jalview/datamodel/AlignmentView.java index 2841152..6f68bcb 100644 --- a/src/jalview/datamodel/AlignmentView.java +++ b/src/jalview/datamodel/AlignmentView.java @@ -563,7 +563,7 @@ public class AlignmentView * @param n * @return */ - private String getASequenceString(char c, int n) + public String getASequenceString(char c, int n) { String sqn; String fullseq = sequences[n].getSequenceString(c); diff --git a/src/jalview/ws2/actions/secstructpred/SecStructPredJob.java b/src/jalview/ws2/actions/secstructpred/SecStructPredJob.java new file mode 100644 index 0000000..506b8a5 --- /dev/null +++ b/src/jalview/ws2/actions/secstructpred/SecStructPredJob.java @@ -0,0 +1,32 @@ +package jalview.ws2.actions.secstructpred; + +import java.util.List; +import java.util.Map; + +import jalview.analysis.SeqsetUtils.SequenceInfo; +import jalview.datamodel.SequenceI; +import jalview.ws2.actions.BaseJob; + +public class SecStructPredJob extends BaseJob +{ + private final int[] delMap; + + private final SequenceI refSeq; + + final Map seqNames; + + SecStructPredJob(List sequences, SequenceI refSeq, int[] delMap, + Map seqNames) + { + super(sequences); + this.refSeq = refSeq; + this.delMap = delMap; + this.seqNames = seqNames; + } + + @Override + public boolean isInputValid() + { + return true; + } +} diff --git a/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java b/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java index 1bbd494..1c53904 100644 --- a/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java +++ b/src/jalview/ws2/actions/secstructpred/SecStructPredTask.java @@ -1,15 +1,19 @@ package jalview.ws2.actions.secstructpred; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import jalview.analysis.AlignmentAnnotationUtils; +import jalview.analysis.SeqsetUtils; 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.datamodel.SeqCigar; +import jalview.datamodel.SequenceI; import jalview.io.AlignFile; import jalview.io.JPredFile; import jalview.io.JnetAnnotationMaker; @@ -45,20 +49,34 @@ public class SecStructPredTask extends BaseTask @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; - } - }; + SeqCigar[] msf = alignmentView.getSequences(); + SequenceI referenceSeq = msf[0].getSeq('-'); + int[] delMap = alignmentView.getVisibleContigMapFor(referenceSeq.gapMap()); + + // TODO: assume MSA for now + SequenceI[] sequences = new SequenceI[msf.length]; + for (int i = 0; i < msf.length; i++) + sequences[i] = msf[i].getSeq('-'); + var sequenceInfo = SeqsetUtils.uniquify(sequences, true); + referenceSeq.setSequence(alignmentView.getASequenceString('-', 0)); + for (int i = 0; i < sequences.length; i++) + sequences[i].setSequence(alignmentView.getASequenceString('-', i)); + var sequencesList = filterEmptySequences(sequences); + var job = new SecStructPredJob(sequencesList, referenceSeq, delMap, + sequenceInfo); job.setStatus(JobStatus.READY); return List.of(job); } + private static List filterEmptySequences(SequenceI[] seqs) + { + var filtered = new ArrayList(); + for (var seq : seqs) + if (seq.getEnd() - seq.getStart() > 0) + filtered.add(seq); + return filtered; + } + @Override protected AlignmentI collectResult(List jobs) throws IOException { -- 1.7.10.2