JAL-1601 Implement JPred4 WS client and discoverer
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 13 Oct 2023 12:37:12 +0000 (14:37 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 13 Oct 2023 12:37:43 +0000 (14:37 +0200)
j11lib/jpred-client-1.0-SNAPSHOT.jar
src/jalview/ws2/client/jpred4/JPred4WSClient.java
src/jalview/ws2/client/jpred4/JPred4WSDiscoverer.java

index 826f028..0e7aacf 100644 (file)
Binary files a/j11lib/jpred-client-1.0-SNAPSHOT.jar and b/j11lib/jpred-client-1.0-SNAPSHOT.jar differ
index 36cc6c2..db1a6e4 100644 (file)
@@ -23,8 +23,14 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI
 {
   final JPredClient client;
 
-  JPred4WSClient(JPredClient client)
+  private final JPredRequest.Mode mode;
+
+  private final JPredRequest.Format format;
+
+  JPred4WSClient(JPredClient client, boolean msaMode)
   {
+    this.mode = msaMode ? JPredRequest.Mode.MSA : JPredRequest.Mode.SINGLE;
+    this.format = msaMode ? JPredRequest.Format.FASTA : JPredRequest.Format.SEQ;
     this.client = client;
   }
 
@@ -44,13 +50,16 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI
   public WebServiceJobHandle submit(List<SequenceI> sequences,
       List<ArgumentI> args, Credentials credentials) throws IOException
   {
-    var input = FileFormat.Fasta
-        .getWriter(null)
-        .print(sequences.toArray(SequenceI[]::new), false);
+    var input = mode == JPredRequest.Mode.MSA
+        ? FileFormat.Fasta
+            .getWriter(null)
+            .print(sequences.toArray(SequenceI[]::new), false)
+        : sequences.get(0).getSequenceAsString();
+
     JPredRequest request = JPredRequest
         .newBuilder()
-        .mode(JPredRequest.Mode.MSA)
-        .format(JPredRequest.Format.FASTA)
+        .mode(mode)
+        .format(format)
         .input(input)
         .build();
     var jobId = client.submit(request);
@@ -63,6 +72,8 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI
     var status = client.getStatus(job.getJobId());
     switch (status)
     {
+    case PENDING:
+      return JobStatus.QUEUED;
     case RUNNING:
       return JobStatus.RUNNING;
     case FINISHED:
@@ -96,16 +107,16 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI
   public void cancel(WebServiceJobHandle job)
       throws IOException, UnsupportedOperationException
   {
-    
+
   }
-  
+
   @Override
   public AlignFile getAlignmentFile(WebServiceJobHandle job) throws IOException
   {
     var url = client.getResultURL(job.getJobId(), ResultTypes.PSIBLAST_ALIGN);
     return new FastaFile(url.toString(), DataSourceType.URL);
   }
-  
+
   @Override
   public JPredFile getPredictionFile(WebServiceJobHandle job) throws IOException
   {
index 99c3f28..6cb1576 100644 (file)
@@ -86,11 +86,17 @@ public class JPred4WSDiscoverer extends AbstractWebServiceDiscoverer
     wsBuilder.actionClass(SecStructPredAction.class);
     var webService = wsBuilder.build();
 
-    var wsClient = new JPred4WSClient(client);
-    var actionBuilder = SecStructPredAction.newBuilder(wsClient);
+    var actionBuilder = SecStructPredAction.newBuilder(
+        new JPred4WSClient(client, false));
     actionBuilder.webService(webService);
-    actionBuilder.name("");
+    actionBuilder.name("JPred4");
     webService.addAction(actionBuilder.build());
+    
+    var actionBuilderMsa = SecStructPredAction.newBuilder(
+        new JPred4WSClient(client, true));
+    actionBuilderMsa.webService(webService);
+    actionBuilderMsa.name("JPred4 (MSA)");
+    webService.addAction(actionBuilderMsa.build());
 
     return List.of(webService);
   }