2d46c9fb62938269489025bb930c5cac7fc4fab4
[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     {
48       // clustalo menu entry
49       JMenuItem noParamMenuItem = new JMenuItem("ClustalO with defaults");
50       SlivkaWSInstance clustalo;
51       try
52       {
53         clustalo = new SlivkaWSInstance(client, client.getService("clustalo"));
54       } catch (IOException e)
55       {
56         throw new IOError(e);
57       }
58       noParamMenuItem.addActionListener((ActionEvent e) -> {
59         AlignmentView msa = alignFrame.gatherSequencesForAlignment();
60         if (msa != null)
61         {
62           new MsaWSClient(
63               clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(),
64               alignFrame
65           );
66         }
67       });
68       submenu.add(noParamMenuItem);
69
70       JMenuItem parametrisedMenuItem = new JMenuItem("ClustalO with custom parameters");
71       parametrisedMenuItem.addActionListener((ActionEvent evt) -> {
72         AlignmentView msa = alignFrame.gatherSequencesForAlignment();
73         if (msa != null)
74         {
75           try
76           {
77             SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService());
78             new MsaWSClient(
79                 clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true,
80                 alignFrame.getViewport().getAlignment().getDataset(), alignFrame
81             );
82           } catch (IOException e)
83           {
84             e.printStackTrace();
85           }
86         }
87       });
88       submenu.add(parametrisedMenuItem);
89     }
90
91     {
92       // clustalw2 menu entry
93       JMenuItem noParamMenuItem = new JMenuItem("ClustalW2 with defaults");
94       SlivkaWSInstance clustalo;
95       try
96       {
97         clustalo = new SlivkaWSInstance(client, client.getService("clustalw"));
98       } catch (IOException e)
99       {
100         throw new IOError(e);
101       }
102       noParamMenuItem.addActionListener((ActionEvent e) -> {
103         AlignmentView msa = alignFrame.gatherSequencesForAlignment();
104         if (msa != null)
105         {
106           new MsaWSClient(
107               clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(),
108               alignFrame
109           );
110         }
111       });
112       submenu.add(noParamMenuItem);
113
114       JMenuItem parametrisedMenuItem = new JMenuItem("ClustalW2 with custom parameters");
115       parametrisedMenuItem.addActionListener((ActionEvent evt) -> {
116         AlignmentView msa = alignFrame.gatherSequencesForAlignment();
117         if (msa != null)
118         {
119           try
120           {
121             SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService());
122             new MsaWSClient(
123                 clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true,
124                 alignFrame.getViewport().getAlignment().getDataset(), alignFrame
125             );
126           } catch (IOException e)
127           {
128             e.printStackTrace();
129           }
130         }
131       });
132       submenu.add(parametrisedMenuItem);
133     }
134
135     wsmenu.add(submenu);
136   }
137
138   @Override
139   public void run()
140   {
141
142   }
143 }