Add the remaining msa services to the Discoverer
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 16 Sep 2019 12:16:43 +0000 (13:16 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 16 Sep 2019 12:16:43 +0000 (13:16 +0100)
src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java
src/jalview/ws/slivkaws/SlivkaWSInstance.java

index 2d46c9f..fc90a69 100644 (file)
@@ -44,92 +44,56 @@ public class SlivkaWSDiscoverer
   {
     JMenu submenu = new JMenu("Slivka");
 
+    String[] services = { "clustalo", "clustalw", "probcons", "muscle", "mafft", "tcoffee" };
+    String[] names = { "ClustalO", "ClustalW2", "Probcons", "Muscle", "Mafft", "TCoffe" };
+
+    for (int i = 0; i < services.length; i++)
     {
-      // clustalo menu entry
-      JMenuItem noParamMenuItem = new JMenuItem("ClustalO with defaults");
-      SlivkaWSInstance clustalo;
       try
       {
-        clustalo = new SlivkaWSInstance(client, client.getService("clustalo"));
-      } catch (IOException e)
-      {
-        throw new IOError(e);
-      }
-      noParamMenuItem.addActionListener((ActionEvent e) -> {
-        AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-        if (msa != null)
-        {
-          new MsaWSClient(
-              clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(),
-              alignFrame
-          );
-        }
-      });
-      submenu.add(noParamMenuItem);
-
-      JMenuItem parametrisedMenuItem = new JMenuItem("ClustalO with custom parameters");
-      parametrisedMenuItem.addActionListener((ActionEvent evt) -> {
-        AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-        if (msa != null)
-        {
-          try
-          {
-            SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService());
-            new MsaWSClient(
-                clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true,
-                alignFrame.getViewport().getAlignment().getDataset(), alignFrame
-            );
-          } catch (IOException e)
+        SlivkaWSInstance instance = new SlivkaWSInstance(client,
+            client.getService(services[i]));
+
+        JMenuItem defaultMenuItem = new JMenuItem(
+            String.format("%s with defaults", names[i]));
+        defaultMenuItem.addActionListener((ActionEvent e) -> {
+          AlignmentView msa = alignFrame.gatherSequencesForAlignment();
+          if (msa != null)
           {
-            e.printStackTrace();
+            new MsaWSClient(instance, alignFrame.getTitle(), msa, false, true,
+                alignFrame.getViewport().getAlignment().getDataset(),
+                alignFrame);
           }
-        }
-      });
-      submenu.add(parametrisedMenuItem);
-    }
+        });
+        submenu.add(defaultMenuItem);
 
-    {
-      // clustalw2 menu entry
-      JMenuItem noParamMenuItem = new JMenuItem("ClustalW2 with defaults");
-      SlivkaWSInstance clustalo;
-      try
-      {
-        clustalo = new SlivkaWSInstance(client, client.getService("clustalw"));
+        JMenuItem customMenuItem = new JMenuItem(
+            String.format("%s with custom parameters", names[i]));
+        customMenuItem.addActionListener((ActionEvent e) -> {
+          AlignmentView msa = alignFrame.gatherSequencesForAlignment();
+          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)
+            {
+              throw new IOError(e1);
+            }
+
+          }
+        });
+        submenu.add(customMenuItem);
       } catch (IOException e)
       {
-        throw new IOError(e);
+        // TODO Auto-generated catch block
+        e.printStackTrace();
       }
-      noParamMenuItem.addActionListener((ActionEvent e) -> {
-        AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-        if (msa != null)
-        {
-          new MsaWSClient(
-              clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(),
-              alignFrame
-          );
-        }
-      });
-      submenu.add(noParamMenuItem);
-
-      JMenuItem parametrisedMenuItem = new JMenuItem("ClustalW2 with custom parameters");
-      parametrisedMenuItem.addActionListener((ActionEvent evt) -> {
-        AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-        if (msa != null)
-        {
-          try
-          {
-            SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService());
-            new MsaWSClient(
-                clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true,
-                alignFrame.getViewport().getAlignment().getDataset(), alignFrame
-            );
-          } catch (IOException e)
-          {
-            e.printStackTrace();
-          }
-        }
-      });
-      submenu.add(parametrisedMenuItem);
     }
 
     wsmenu.add(submenu);
index d5456a6..8bb554a 100644 (file)
@@ -157,6 +157,10 @@ public class SlivkaWSInstance extends ServiceWithParameters
         {
           return new FormatAdapter().readFile(f.getURL().toString(), DataSourceType.URL, FileFormat.Clustal);
         }
+        else if (f.getMimeType().equals("application/fasta"))
+        {
+          return new FormatAdapter().readFile(f.getURL().toString(), DataSourceType.URL, FileFormat.Fasta);
+        }
       }
     } catch (IOException e)
     {