JAL-1601 Create SecStructPredTask class
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 13 Oct 2023 13:05:20 +0000 (15:05 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 13 Oct 2023 13:47:48 +0000 (15:47 +0200)
src/jalview/datamodel/AlignmentView.java
src/jalview/ws2/actions/secstructpred/SecStructPredJob.java [new file with mode: 0644]
src/jalview/ws2/actions/secstructpred/SecStructPredTask.java

index 2841152..6f68bcb 100644 (file)
@@ -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 (file)
index 0000000..506b8a5
--- /dev/null
@@ -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<String, SequenceInfo> seqNames;
+
+  SecStructPredJob(List<SequenceI> sequences, SequenceI refSeq, int[] delMap,
+      Map<String, SequenceInfo> seqNames)
+  {
+    super(sequences);
+    this.refSeq = refSeq;
+    this.delMap = delMap;
+    this.seqNames = seqNames;
+  }
+
+  @Override
+  public boolean isInputValid()
+  {
+    return true;
+  }
+}
index 1bbd494..1c53904 100644 (file)
@@ -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<BaseJob, AlignmentI>
   @Override
   protected List<BaseJob> 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<SequenceI> filterEmptySequences(SequenceI[] seqs)
+  {
+    var filtered = new ArrayList<SequenceI>();
+    for (var seq : seqs)
+      if (seq.getEnd() - seq.getStart() > 0)
+        filtered.add(seq);
+    return filtered;
+  }
+
   @Override
   protected AlignmentI collectResult(List<BaseJob> jobs) throws IOException
   {