JAL-3878 Add dataset and viewport arguments to ResultSupplier.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 7 Oct 2021 13:31:07 +0000 (15:31 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 7 Oct 2021 13:31:07 +0000 (15:31 +0200)
src/jalview/ws2/ResultSupplier.java
src/jalview/ws2/operations/AlignmentOperation.java
src/jalview/ws2/slivka/SlivkaWebService.java

index e691b80..3642d8e 100644 (file)
@@ -1,9 +1,14 @@
 package jalview.ws2;
 
 import java.io.IOException;
+import java.util.List;
+
+import jalview.api.AlignViewportI;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
 
 @FunctionalInterface
 public interface ResultSupplier<T>
 {
-  public T getResult(WSJob job) throws IOException;
+  public T getResult(WSJob job, List<SequenceI> dataset, AlignViewportI viewport) throws IOException;
 }
index f836c91..b70678a 100644 (file)
@@ -302,6 +302,8 @@ public class AlignmentOperation implements Operation
 
     private final AlignmentI dataset;
 
+    private final AlignViewport viewport;
+
     private final List<AlignedCodonFrame> codonFrame = new ArrayList<>();
 
     private List<ArgumentI> args = Collections.emptyList();
@@ -337,6 +339,7 @@ public class AlignmentOperation implements Operation
       this.alnTitle = alnTitle;
       this.submitGaps = submitGaps;
       this.preserveOrder = preserveOrder;
+      this.viewport = viewport;
       this.gapCharacter = viewport.getGapCharacter();
 
       String panelInfo = String.format("%s using service hosted at %s%n%s",
@@ -528,7 +531,7 @@ public class AlignmentOperation implements Operation
           continue;
         try
         {
-          AlignmentI alignment = supplier.getResult(job);
+          AlignmentI alignment = supplier.getResult(job, dataset.getSequences(), viewport);
           if (alignment != null)
           {
             results.put(job.getUid(), alignment);
index aee6b73..82a2ba9 100644 (file)
@@ -12,7 +12,10 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import jalview.api.AlignViewportI;
 import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.io.AnnotationFile;
@@ -234,7 +237,8 @@ public class SlivkaWebService implements WebServiceI
     return false;
   }
 
-  public AlignmentI getAlignment(WSJob job) throws IOException
+  public AlignmentI getAlignment(WSJob job, List<SequenceI> dataset,
+      AlignViewportI viewport) throws IOException
   {
     Collection<RemoteFile> files;
     var slivkaJob = client.getJob(job.getJobId());
@@ -255,7 +259,8 @@ public class SlivkaWebService implements WebServiceI
     return null;
   }
 
-  public FeaturesFile getFeaturesFile(WSJob job) throws IOException
+  public FeaturesFile getFeaturesFile(WSJob job,
+      List<SequenceI> dataset, AlignViewportI viewport) throws IOException
   {
     var slivkaJob = client.getJob(job.getJobId());
     Collection<RemoteFile> files = slivkaJob.getResults();
@@ -269,7 +274,8 @@ public class SlivkaWebService implements WebServiceI
     return null;
   }
 
-  public AnnotationFile getAnnotationFile(WSJob job) throws IOException
+  public List<AlignmentAnnotation> getAnnotationFile(WSJob job,
+      List<SequenceI> dataset, AlignViewportI viewport) throws IOException
   {
     var slivkaJob = client.getJob(job.getJobId());
     Collection<RemoteFile> files = slivkaJob.getResults();
@@ -277,7 +283,19 @@ public class SlivkaWebService implements WebServiceI
     {
       if (f.getMediaType().equals("application/jalview-annotations"))
       {
-        // return new AnnorationFile(...);
+        Alignment aln = new Alignment(dataset.toArray(new SequenceI[0]));
+        AnnotationFile af = new AnnotationFile();
+        boolean valid = af.readAnnotationFileWithCalcId(aln, service.getId(),
+            f.getContentUrl().toString(), DataSourceType.URL);
+        if (valid)
+        {
+          return Arrays.asList(aln.getAlignmentAnnotation());
+        }
+        else
+        {
+          throw new IOException("Unable to read annotations from file " +
+              f.getContentUrl().toString());
+        }
       }
     }
     return null;