JAL-3878 Add dataset and viewport arguments to ResultSupplier.
[jalview.git] / src / jalview / ws2 / operations / AlignmentOperation.java
index e882101..b70678a 100644 (file)
@@ -82,6 +82,12 @@ public class AlignmentOperation implements Operation
   }
 
   @Override
+  public String getHostName()
+  {
+    return service.getHostName();
+  }
+
+  @Override
   public int getMinSequences()
   {
     return 2;
@@ -113,6 +119,12 @@ public class AlignmentOperation implements Operation
   }
 
   @Override
+  public boolean isInteractive()
+  {
+    return false;
+  }
+
+  @Override
   public MenuEntryProviderI getMenuBuilder()
   {
     return this::buildMenu;
@@ -144,9 +156,6 @@ public class AlignmentOperation implements Operation
     final String action = submitGaps ? "Align" : "Realign";
     final var calcName = service.getName();
 
-    final AlignmentView msa = frame.gatherSequencesForAlignment();
-    final AlignViewport viewport = frame.getViewport();
-    final AlignmentI alignment = frame.getViewport().getAlignment();
     String title = frame.getTitle();
     WebServiceExecutor executor = frame.getViewport().getWSExecutor();
     {
@@ -155,11 +164,14 @@ public class AlignmentOperation implements Operation
       item.setToolTipText(MessageManager
               .formatMessage("label.action_with_default_settings", action));
       item.addActionListener((event) -> {
+        final AlignmentView msa = frame.gatherSequencesForAlignment();
+        final AlignViewport viewport = frame.getViewport();
+        final AlignmentI alignment = frame.getViewport().getAlignment();
         if (msa != null)
         {
           WebServiceWorkerI worker = new AlignmentWorker(msa,
-                  Collections.emptyList(), title, submitGaps, true,
-                  alignment, viewport);
+              Collections.emptyList(), title, submitGaps, true,
+              alignment, viewport);
           executor.submit(worker);
         }
       });
@@ -173,18 +185,21 @@ public class AlignmentOperation implements Operation
       item.setToolTipText(MessageManager.getString(
               "label.view_and_change_parameters_before_alignment"));
       item.addActionListener((event) -> {
+        final AlignmentView msa = frame.gatherSequencesForAlignment();
+        final AlignViewport viewport = frame.getViewport();
+        final AlignmentI alignment = frame.getViewport().getAlignment();
         if (msa != null)
         {
           openEditParamsDialog(service, null, null)
-                  .thenAcceptAsync((arguments) -> {
-                    if (arguments != null)
-                    {
-                      WebServiceWorkerI worker = new AlignmentWorker(msa,
-                              arguments, title, submitGaps, true, alignment,
-                              viewport);
-                      executor.submit(worker);
-                    }
-                  });
+              .thenAcceptAsync((arguments) -> {
+                if (arguments != null)
+                {
+                  WebServiceWorkerI worker = new AlignmentWorker(msa,
+                      arguments, title, submitGaps, true, alignment,
+                      viewport);
+                  executor.submit(worker);
+                }
+              });
         }
       });
       parent.add(item);
@@ -223,11 +238,14 @@ public class AlignmentOperation implements Operation
                         preset.getDescription()));
         item.setToolTipText(tooltip);
         item.addActionListener((event) -> {
+          final AlignmentView msa = frame.gatherSequencesForAlignment();
+          final AlignViewport viewport = frame.getViewport();
+          final AlignmentI alignment = frame.getViewport().getAlignment();
           if (msa != null)
           {
             WebServiceWorkerI worker = new AlignmentWorker(msa,
-                    preset.getArguments(), title, submitGaps, true,
-                    alignment, viewport);
+                preset.getArguments(), title, submitGaps, true,
+                alignment, viewport);
             executor.submit(worker);
           }
         });
@@ -284,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();
@@ -319,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",
@@ -348,6 +369,7 @@ public class AlignmentOperation implements Operation
     @Override
     public void startJobs() throws IOException
     {
+      Cache.log.info(format("Starting new %s job.", service.getName()));
       String outputHeader = String.format("%s of %s%nJob details%n",
               submitGaps ? "Re-alignment" : "Alignment", alnTitle);
       SequenceI[][] conmsa = msa.getVisibleContigs('-');
@@ -364,7 +386,7 @@ public class AlignmentOperation implements Operation
         WSJob job = new WSJob(service.getProviderName(), service.getName(),
                 service.getHostName());
         job.setJobNum(wsInfo.addJobPane());
-        if (conmsa.length > 0)
+        if (conmsa.length > 1)
         {
           wsInfo.setProgressName(String.format("region %d", i),
                   job.getJobNum());
@@ -430,7 +452,7 @@ public class AlignmentOperation implements Operation
       boolean done = true;
       for (WSJob job : getJobs())
       {
-        if (!job.getStatus().isDone())
+        if (!job.getStatus().isDone() && !job.getStatus().isFailed())
         {
           Cache.log.debug(format("Polling job %s.", job));
           try
@@ -461,7 +483,7 @@ public class AlignmentOperation implements Operation
           Cache.log.debug(
                   format("Job %s status is %s", job, job.getStatus()));
         }
-        done &= job.getStatus().isDone();
+        done &= job.getStatus().isDone() || job.getStatus().isFailed();
       }
       updateWSInfoGlobalStatus();
       return done;
@@ -505,9 +527,11 @@ public class AlignmentOperation implements Operation
       Map<Long, AlignmentI> results = new LinkedHashMap<>();
       for (WSJob job : getJobs())
       {
+        if (job.getStatus().isFailed())
+          continue;
         try
         {
-          AlignmentI alignment = supplier.getResult(job);
+          AlignmentI alignment = supplier.getResult(job, dataset.getSequences(), viewport);
           if (alignment != null)
           {
             results.put(job.getUid(), alignment);
@@ -771,8 +795,8 @@ public class AlignmentOperation implements Operation
         }
         else
         {
-          String seqString = null;
-          if (seq.getEnd() >= seq.getStart()) // is it ever false?
+          String seqString = "";
+          if (seq.getEnd() >= seq.getStart())  // true if gaps only
           {
             seqString = seq.getSequenceAsString();
             if (!submitGaps)