JAL-3954 create primitive gui handler for search service
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Sat, 20 May 2023 21:57:52 +0000 (23:57 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 30 May 2023 15:39:12 +0000 (17:39 +0200)
j11lib/hmmer-client-1.0-SNAPSHOT.jar
src/jalview/ws2/actions/BaseJob.java
src/jalview/ws2/client/ebi/PhmmerWSClient.java
src/jalview/ws2/gui/SearchServiceGuiHandler.java [new file with mode: 0644]
src/jalview/ws2/gui/WebServicesMenuManager.java

index 879f5b3..1efea10 100644 (file)
Binary files a/j11lib/hmmer-client-1.0-SNAPSHOT.jar and b/j11lib/hmmer-client-1.0-SNAPSHOT.jar differ
index 945c7b0..6a4a600 100644 (file)
@@ -25,6 +25,7 @@ import jalview.ws2.api.WebServiceJobHandle;
  * 
  * @author mmwarowny
  */
+// TODO: make class non-abstract by removing isInputValid()
 public abstract class BaseJob implements JobI
 {
   protected final long internalId = MathUtils.getUID();
@@ -70,6 +71,7 @@ public abstract class BaseJob implements JobI
    * 
    * @return {@code true} if the input is valid.
    */
+  // FIXME: method not necessary, may incorporate into task#prepare()
   public abstract boolean isInputValid();
 
   /**
index 5a51fcc..9c79644 100644 (file)
@@ -2,10 +2,14 @@ package jalview.ws2.client.ebi;
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.net.URI;
 import java.util.List;
 
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
+import jalview.io.FormatAdapter;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.simple.BooleanOption;
 import jalview.ws.params.simple.DoubleParameter;
@@ -13,13 +17,14 @@ import jalview.ws.params.simple.IntegerParameter;
 import jalview.ws2.api.Credentials;
 import jalview.ws2.api.JobStatus;
 import jalview.ws2.api.WebServiceJobHandle;
+import jalview.ws2.client.api.AlignmentWebServiceClientI;
 import jalview.ws2.client.api.WebServiceClientI;
 import uk.ac.dundee.compbio.hmmerclient.PhmmerClient;
 import uk.ac.dundee.compbio.hmmerclient.PhmmerRequest;
 import uk.ac.dundee.compbio.hmmerclient.PhmmerRequest.SequenceDatabase;
 import uk.ac.dundee.compbio.hmmerclient.PhmmerRequest.SubstitutionMatrix;
 
-public class PhmmerWSClient implements WebServiceClientI
+public class PhmmerWSClient implements AlignmentWebServiceClientI
 {
 
   final PhmmerClient client;
@@ -229,4 +234,13 @@ public class PhmmerWSClient implements WebServiceClientI
             "ebi job dispatcher does not support job cancellation");
   }
 
+  /**
+   * FIXME: Temporary hack
+   */
+  @Override
+  public AlignmentI getAlignment(WebServiceJobHandle job) throws IOException
+  {
+    URI url = client.getResultURL(job.getJobId(), "sto");
+    return new FormatAdapter().readFile(url.toString(), DataSourceType.URL, FileFormat.Stockholm);
+  }
 }
diff --git a/src/jalview/ws2/gui/SearchServiceGuiHandler.java b/src/jalview/ws2/gui/SearchServiceGuiHandler.java
new file mode 100644 (file)
index 0000000..b3ae5c1
--- /dev/null
@@ -0,0 +1,95 @@
+package jalview.ws2.gui;
+
+import java.util.List;
+
+import jalview.bin.Console;
+import jalview.datamodel.AlignmentI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.ws2.actions.api.JobI;
+import jalview.ws2.actions.api.TaskEventListener;
+import jalview.ws2.actions.api.TaskI;
+import jalview.ws2.api.JobStatus;
+
+public class SearchServiceGuiHandler implements TaskEventListener<AlignmentI>
+{
+  private final AlignFrame parentFrame;
+  
+  public SearchServiceGuiHandler(AlignFrame parentFrame)
+  {
+    this.parentFrame = parentFrame;
+  }
+
+  @Override
+  public void taskStarted(TaskI<AlignmentI> source,
+          List<? extends JobI> subJobs)
+  {
+    Console.info("task started with " + subJobs.size() + " jobs");
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void taskStatusChanged(TaskI<AlignmentI> source, JobStatus status)
+  {
+    Console.info("task status " + status);
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void taskCompleted(TaskI<AlignmentI> source, AlignmentI result)
+  {
+    Console.info("task completed");
+    displayResultsNewFrame(result);
+  }
+
+  @Override
+  public void taskException(TaskI<AlignmentI> source, Exception e)
+  {
+    Console.info("task failed", e);
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void taskRestarted(TaskI<AlignmentI> source)
+  {
+    Console.info("task restarted");
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void subJobStatusChanged(TaskI<AlignmentI> source, JobI job,
+          JobStatus status)
+  {
+    Console.info("sub-job " + job.getInternalId() + " status " + status);
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void subJobLogChanged(TaskI<AlignmentI> source, JobI job,
+          String log)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void subJobErrorLogChanged(TaskI<AlignmentI> source, JobI job,
+          String log)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  private void displayResultsNewFrame(AlignmentI aln)
+  {
+    AlignFrame frame = new AlignFrame(aln, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+    frame.getFeatureRenderer().transferSettings(
+            parentFrame.getFeatureRenderer().getSettings());
+    Desktop.addInternalFrame(frame, "title", AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+  }
+}
index 8f48690..8e2dcee 100644 (file)
@@ -39,6 +39,7 @@ import jalview.ws2.actions.annotation.AnnotationAction;
 import jalview.ws2.actions.api.ActionI;
 import jalview.ws2.actions.api.TaskEventListener;
 import jalview.ws2.actions.api.TaskI;
+import jalview.ws2.actions.hmmer.PhmmerAction;
 import jalview.ws2.api.Credentials;
 import jalview.ws2.api.WebService;
 import jalview.ws2.client.api.WebServiceProviderI;
@@ -470,6 +471,12 @@ public class WebServicesMenuManager
       var handler = new AnnotationServiceGuiHandler(_action, frame);
       return _action.perform(viewport, args, credentials, handler);
     }
+    if (action instanceof PhmmerAction)
+    {
+      var _action = (PhmmerAction) action;
+      var handler = new SearchServiceGuiHandler(frame);
+      return _action.perform(viewport, args, credentials, handler);
+    }
     Console.warn(String.format(
             "No known handler for action type %s. All output will be discarded.",
             action.getClass().getName()));