JAL-3066 Auto discover multiple sequence alignment services
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 19 Sep 2019 13:35:46 +0000 (14:35 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 19 Sep 2019 13:36:01 +0000 (14:36 +0100)
j11lib/slivka-client.jar
src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java

index 9efae32..12cc028 100644 (file)
Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ
index fc90a69..009e388 100644 (file)
@@ -14,6 +14,7 @@ import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 
 import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
+import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
 
 public class SlivkaWSDiscoverer
   implements Runnable, WSMenuEntryProviderI
@@ -42,61 +43,61 @@ public class SlivkaWSDiscoverer
   @Override
   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
   {
-    JMenu submenu = new JMenu("Slivka");
+    JMenu slivkaMenu = new JMenu("Slivka");
+    wsmenu.add(slivkaMenu);
+    JMenu categoryMenu = new JMenu("Alignment");
+    slivkaMenu.add(categoryMenu);
 
-    String[] services = { "clustalo", "clustalw", "probcons", "muscle", "mafft", "tcoffee" };
-    String[] names = { "ClustalO", "ClustalW2", "Probcons", "Muscle", "Mafft", "TCoffe" };
-
-    for (int i = 0; i < services.length; i++)
+    try
     {
-      try
-      {
-        SlivkaWSInstance instance = new SlivkaWSInstance(client,
-            client.getService(services[i]));
-
-        JMenuItem defaultMenuItem = new JMenuItem(
-            String.format("%s with defaults", names[i]));
-        defaultMenuItem.addActionListener((ActionEvent e) -> {
+      for (SlivkaService service: client.getServices()) {
+        msaClassifier: {
+          for (String classifier: service.classifiers) {
+            if (classifier.contains("Multiple sequence alignment")) {
+              break msaClassifier;
+            }
+          }
+          continue;
+        }
+        SlivkaWSInstance instance = new SlivkaWSInstance(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,
+          if (msa != null) {
+            new MsaWSClient(
+                instance, alignFrame.getTitle(), msa, false, true,
                 alignFrame.getViewport().getAlignment().getDataset(),
-                alignFrame);
+                alignFrame
+            );
           }
         });
-        submenu.add(defaultMenuItem);
-
-        JMenuItem customMenuItem = new JMenuItem(
-            String.format("%s with custom parameters", names[i]));
-        customMenuItem.addActionListener((ActionEvent e) -> {
+        categoryMenu.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)
-          {
+          if (msa != null) {
             try
             {
-              SlivkaParamSet paramSet = new SlivkaParamSet(
-                  instance.getService());
-              new MsaWSClient(instance, paramSet, null, true,
-                  alignFrame.getTitle(), msa, false, true,
-                  alignFrame.getViewport().getAlignment().getDataset(),
-                  alignFrame);
-            } catch (IOException e1)
+            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(e1);
+              throw new IOError(exc);
             }
-
           }
         });
-        submenu.add(customMenuItem);
-      } catch (IOException e)
-      {
-        // TODO Auto-generated catch block
-        e.printStackTrace();
+        categoryMenu.add(customEntry);
+        
+        categoryMenu.addSeparator();
       }
+    } catch (IOException e)
+    {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
     }
-
-    wsmenu.add(submenu);
   }
 
   @Override