fc90a69cc49e8b50bc9999be118dd016f937fc14
[jalview.git] / src / jalview / ws / slivkaws / SlivkaWSDiscoverer.java
1 package jalview.ws.slivkaws;
2
3 import jalview.datamodel.AlignmentView;
4 import jalview.gui.AlignFrame;
5 import jalview.ws.WSMenuEntryProviderI;
6 import jalview.ws.jws2.MsaWSClient;
7
8 import java.awt.event.ActionEvent;
9 import java.io.IOError;
10 import java.io.IOException;
11 import java.net.URISyntaxException;
12
13 import javax.swing.JMenu;
14 import javax.swing.JMenuItem;
15
16 import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
17
18 public class SlivkaWSDiscoverer
19   implements Runnable, WSMenuEntryProviderI
20 {
21   private static SlivkaWSDiscoverer instance = null;
22   private SlivkaClient client;
23
24   private SlivkaWSDiscoverer() {
25     try
26     {
27       client = new SlivkaClient("gjb-www-1.cluster.lifesci.dundee.ac.uk", 3203);
28     } catch (URISyntaxException e)
29     {
30       throw new RuntimeException(e);
31     }
32   }
33
34   public static SlivkaWSDiscoverer getInstance()
35   {
36     if (instance == null) {
37                 instance = new SlivkaWSDiscoverer();
38         }
39     return instance;
40   }
41
42   @Override
43   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
44   {
45     JMenu submenu = new JMenu("Slivka");
46
47     String[] services = { "clustalo", "clustalw", "probcons", "muscle", "mafft", "tcoffee" };
48     String[] names = { "ClustalO", "ClustalW2", "Probcons", "Muscle", "Mafft", "TCoffe" };
49
50     for (int i = 0; i < services.length; i++)
51     {
52       try
53       {
54         SlivkaWSInstance instance = new SlivkaWSInstance(client,
55             client.getService(services[i]));
56
57         JMenuItem defaultMenuItem = new JMenuItem(
58             String.format("%s with defaults", names[i]));
59         defaultMenuItem.addActionListener((ActionEvent e) -> {
60           AlignmentView msa = alignFrame.gatherSequencesForAlignment();
61           if (msa != null)
62           {
63             new MsaWSClient(instance, alignFrame.getTitle(), msa, false, true,
64                 alignFrame.getViewport().getAlignment().getDataset(),
65                 alignFrame);
66           }
67         });
68         submenu.add(defaultMenuItem);
69
70         JMenuItem customMenuItem = new JMenuItem(
71             String.format("%s with custom parameters", names[i]));
72         customMenuItem.addActionListener((ActionEvent e) -> {
73           AlignmentView msa = alignFrame.gatherSequencesForAlignment();
74           if (msa != null)
75           {
76             try
77             {
78               SlivkaParamSet paramSet = new SlivkaParamSet(
79                   instance.getService());
80               new MsaWSClient(instance, paramSet, null, true,
81                   alignFrame.getTitle(), msa, false, true,
82                   alignFrame.getViewport().getAlignment().getDataset(),
83                   alignFrame);
84             } catch (IOException e1)
85             {
86               throw new IOError(e1);
87             }
88
89           }
90         });
91         submenu.add(customMenuItem);
92       } catch (IOException e)
93       {
94         // TODO Auto-generated catch block
95         e.printStackTrace();
96       }
97     }
98
99     wsmenu.add(submenu);
100   }
101
102   @Override
103   public void run()
104   {
105
106   }
107 }