JAL-3066 Sequence annotation services.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 1 Oct 2019 16:30:08 +0000 (17:30 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 1 Oct 2019 16:30:08 +0000 (17:30 +0100)
src/jalview/ws/jws2/Jws2ClientFactory.java
src/jalview/ws/jws2/MsaWSClient.java
src/jalview/ws/jws2/SequenceAnnotationWSClient.java
src/jalview/ws/params/simple/BooleanOption.java
src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java
src/jalview/ws/slivkaws/SlivkaDatastore.java
src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java
src/jalview/ws/slivkaws/SlivkaWSInstance.java

index 99edbec..6a177dd 100644 (file)
@@ -5,7 +5,6 @@ import jalview.bin.Cache;
 import jalview.gui.AlignFrame;
 import jalview.gui.JvSwingUtils;
 import jalview.util.MessageManager;
-import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.dm.AAConSettings;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.uimodel.AlignAnalysisUIText;
@@ -23,10 +22,9 @@ import javax.swing.event.MenuListener;
 public class Jws2ClientFactory
 {
   static boolean registerAAConWSInstance(final JMenu wsmenu,
-          final ServiceWithParameters service, final AlignFrame alignFrame)
+      final Jws2Instance service, final AlignFrame alignFrame)
   {
-    Jws2Instance jaba_service = (Jws2Instance) service;
-    final AlignAnalysisUIText aaui = jaba_service.getAlignAnalysisUI(); // null
+    final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null
                                                                         // ; //
     // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
     if (aaui == null)
@@ -65,7 +63,7 @@ public class Jws2ClientFactory
             // public void run()
             {
               removeCurrentAAConWorkerFor(aaui, alignFrame);
-              buildCurrentAAConWorkerFor(aaui, alignFrame, jaba_service);
+              buildCurrentAAConWorkerFor(aaui, alignFrame, service);
             }
           } // );
         }
index 3c57ca8..3f0cc8e 100644 (file)
@@ -32,6 +32,7 @@ import jalview.ws.api.JalviewServiceEndpointProviderI;
 import jalview.ws.api.MultipleSequenceAlignmentI;
 import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.gui.MsaWSThread;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.WsParamSetI;
 
@@ -236,8 +237,8 @@ public class MsaWSClient extends Jws2Client implements WSMenuEntryProviderI
   public void attachWSMenuEntry(JMenu rmsawsmenu,
           final ServiceWithParameters service, final AlignFrame alignFrame)
   {
-    if (Jws2ClientFactory.registerAAConWSInstance(rmsawsmenu, service,
-            alignFrame))
+    if (service instanceof Jws2Instance
+        && Jws2ClientFactory.registerAAConWSInstance(rmsawsmenu, (Jws2Instance) service, alignFrame))
     {
       // Alignment dependent analysis calculation WS gui
       return;
index 7163974..a2038f0 100644 (file)
@@ -52,7 +52,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
     // TODO Auto-generated constructor stub
   }
 
-  public SequenceAnnotationWSClient(final Jws2Instance sh,
+  public SequenceAnnotationWSClient(final ServiceWithParameters sh,
           AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
   {
     super(alignFrame, preset, null);
@@ -139,7 +139,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
         worker.updateParameters(this.preset, paramset);
       }
     }
-    if (sh.getAction().toLowerCase().contains("disorder"))
+    if (!sh.isInteractiveUpdate())
     {
       // build IUPred style client. take sequences, returns annotation per
       // sequence.
@@ -172,16 +172,19 @@ public class SequenceAnnotationWSClient extends Jws2Client
           final ServiceWithParameters service,
           final AlignFrame alignFrame)
   {
-    if (Jws2ClientFactory.registerAAConWSInstance(wsmenu, service,
-            alignFrame))
+    if (service instanceof Jws2Instance
+        && Jws2ClientFactory.registerAAConWSInstance(wsmenu, (Jws2Instance) service, alignFrame))
     {
       // Alignment dependent analysis calculation WS gui
       return;
     }
     boolean hasparams = service.hasParameters();
-    // Assume name ends in WS
-    String calcName = service.getName().substring(0,
-            service.getName().length() - 2);
+    String calcName = service.getName();
+    if (calcName.endsWith("WS"))
+    {
+      // Remove "WS" suffix
+      calcName = calcName.substring(0, calcName.length() - 2);
+    }
 
     JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage(
             "label.calcname_with_default_settings", new String[]
@@ -192,7 +195,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        new SequenceAnnotationWSClient((Jws2Instance) service, alignFrame,
+        new SequenceAnnotationWSClient(service, alignFrame,
                 null, false);
       }
     });
@@ -211,7 +214,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
         @Override
         public void actionPerformed(ActionEvent e)
         {
-          new SequenceAnnotationWSClient((Jws2Instance) service, alignFrame,
+          new SequenceAnnotationWSClient(service, alignFrame,
                   null, true);
         }
       });
@@ -237,7 +240,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
             @Override
             public void actionPerformed(ActionEvent e)
             {
-              new SequenceAnnotationWSClient((Jws2Instance) service,
+              new SequenceAnnotationWSClient(service,
                       alignFrame, preset,
                       false);
             }
index 05abc3a..650b72d 100644 (file)
@@ -27,10 +27,9 @@ public class BooleanOption extends Option
 {
 
   public BooleanOption(String name, String descr, boolean required,
-          boolean defVal, boolean val, URL link)
+      Boolean defVal, Boolean val, URL link)
   {
-    super(name, descr, required, (defVal ? name : null),
-            (val ? name : null),
+    super(name, descr, required, (defVal != null && defVal ? name : null), (val != null && val ? name : null),
             Arrays.asList(name), link);
   }
 
index 184ca2d..4aaae6a 100644 (file)
@@ -6,6 +6,8 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.io.AnnotationFile;
+import jalview.io.DataSourceType;
+import jalview.io.FeaturesFile;
 import jalview.ws.api.JobId;
 import jalview.ws.api.SequenceAnnotationServiceI;
 import jalview.ws.params.ArgumentI;
@@ -99,9 +101,12 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements
       throw new IOError(e);
     }
     Alignment aln = new Alignment(seqs.toArray(new SequenceI[0]));
-    BufferedReader in = new BufferedReader(new InputStreamReader(annotFile.getContent()));
-    AnnotationFile f = new AnnotationFile();
-    f.parseAnnotationFrom(aln, null, in);
+    BufferedReader readerIn = new BufferedReader(new InputStreamReader(annotFile.getContent()));
+    new AnnotationFile().parseAnnotationFrom(aln, null, readerIn);
+    if (featFile != null)
+    {
+      new FeaturesFile(featFile.getURL().toString(), DataSourceType.URL).parse(aln, featureColours, true);
+    }
     return Arrays.asList(aln.getAlignmentAnnotation());
   }
 }
index ef10006..0922d13 100644 (file)
@@ -17,7 +17,6 @@ public class SlivkaDatastore implements ParamDatastoreI
 
   SlivkaDatastore(SlivkaService service) throws IOException {
     defaultPreset = new SlivkaParamSet(service);
-    presets.add(defaultPreset);
   }
 
   @Override
@@ -48,7 +47,14 @@ public class SlivkaDatastore implements ParamDatastoreI
   @Override
   public boolean presetExists(String name)
   {
-    return name.equals(defaultPreset.getName());
+    for (WsParamSetI preset : presets)
+    {
+      if (preset.getName().equals(name))
+      {
+        return true;
+      }
+    }
+    return false;
   }
 
   @Override
index 6b3856a..56f7b9f 100644 (file)
@@ -1,18 +1,15 @@
 package jalview.ws.slivkaws;
 
-import jalview.datamodel.AlignmentView;
 import jalview.gui.AlignFrame;
 import jalview.ws.WSMenuEntryProviderI;
 import jalview.ws.jws2.MsaWSClient;
 import jalview.ws.jws2.SequenceAnnotationWSClient;
 
-import java.awt.event.ActionEvent;
 import java.io.IOError;
 import java.io.IOException;
 import java.net.URISyntaxException;
 
 import javax.swing.JMenu;
-import javax.swing.JMenuItem;
 
 import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
 import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
@@ -21,13 +18,13 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
 {
   private static SlivkaWSDiscoverer instance = null;
 
-  private SlivkaClient client;
+  private SlivkaClient slivkaClient;
 
   private SlivkaWSDiscoverer()
   {
     try
     {
-      client = new SlivkaClient("gjb-www-1.cluster.lifesci.dundee.ac.uk", 3203);
+      slivkaClient = new SlivkaClient("gjb-www-1.cluster.lifesci.dundee.ac.uk", 3203);
     } catch (URISyntaxException e)
     {
       throw new RuntimeException(e);
@@ -53,7 +50,7 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
     slivkaMenu.add(alignmentMenu);
     try
     {
-      for (SlivkaService service : client.getServices())
+      for (SlivkaService service : slivkaClient.getServices())
       {
         msaClassifier:
         {
@@ -66,36 +63,9 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
           }
           continue;
         }
-        SlivkaMsaServiceInstance instance = new SlivkaMsaServiceInstance(client, service);
-        JMenuItem defaultEntry = new JMenuItem(String.format("%s with defaults", service.label));
-        defaultEntry.addActionListener((ActionEvent evt) -> {
-          AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-          if (msa != null)
-          {
-            new MsaWSClient(instance, alignFrame.getTitle(), msa, false, true,
-                alignFrame.getViewport().getAlignment().getDataset(), alignFrame);
-          }
-        });
-        alignmentMenu.add(defaultEntry);
-
-        JMenuItem customEntry = new JMenuItem(String.format("%s with custom parameters", service.label));
-        customEntry.addActionListener((ActionEvent evt) -> {
-          AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-          if (msa != null)
-          {
-            try
-            {
-              SlivkaParamSet paramSet = new SlivkaParamSet(service);
-              new MsaWSClient(instance, paramSet, null, true, alignFrame.getTitle(), msa, false, true,
-                  alignFrame.getViewport().getAlignment().getDataset(), alignFrame);
-            } catch (IOException exc)
-            {
-              throw new IOError(exc);
-            }
-          }
-        });
-        alignmentMenu.add(customEntry);
-
+        SlivkaMsaServiceInstance instance = new SlivkaMsaServiceInstance(slivkaClient, service);
+        MsaWSClient client = new MsaWSClient();
+        client.attachWSMenuEntry(alignmentMenu, instance, alignFrame);
         alignmentMenu.addSeparator();
       }
     } catch (IOException e)
@@ -108,7 +78,7 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
     slivkaMenu.add(disorderMenu);
     try
     {
-      for (SlivkaService service : client.getServices())
+      for (SlivkaService service : slivkaClient.getServices())
       {
         msaClassifier:
         {
@@ -121,21 +91,10 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
           }
           continue;
         }
-        JMenuItem menuEntry = new JMenuItem(String.format("%s with custom parameters", service.label));
-        disorderMenu.add(menuEntry);
-        SlivkaAnnotationServiceInstance serviceInstance = new SlivkaAnnotationServiceInstance(client, service);
-        menuEntry.addActionListener((ActionEvent evt) -> {
-          try
-          {
-            SlivkaParamSet paramSet = new SlivkaParamSet(service);
-            SequenceAnnotationWSClient client = new SequenceAnnotationWSClient();
-            client.initSequenceAnnotationWSClient(serviceInstance, alignFrame, paramSet, true);
-          } catch (IOException e)
-          {
-            throw new IOError(e);
-          }
-
-        });
+        SlivkaAnnotationServiceInstance serviceInstance = new SlivkaAnnotationServiceInstance(slivkaClient, service);
+        SequenceAnnotationWSClient client = new SequenceAnnotationWSClient();
+        client.attachWSMenuEntry(disorderMenu, serviceInstance, alignFrame);
+        disorderMenu.addSeparator();
       }
     } catch (IOException e)
     {
index 751637c..9aae388 100644 (file)
@@ -124,6 +124,10 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters
   @Override
   public final ParamDatastoreI getParamStore()
   {
+    if (store == null)
+    {
+      initParamStore(null);
+    }
     return store;
   }