4 package jalview.ws.jws2;
6 import jalview.api.AlignCalcWorkerI;
7 import jalview.bin.Cache;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.Desktop;
10 import jalview.gui.JvSwingUtils;
11 import jalview.ws.jws2.dm.AAConSettings;
12 import jalview.ws.jws2.jabaws2.Jws2Instance;
13 import jalview.ws.params.WsParamSetI;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.util.List;
19 import javax.swing.JCheckBoxMenuItem;
20 import javax.swing.JMenu;
21 import javax.swing.JMenuItem;
22 import javax.swing.JOptionPane;
23 import javax.swing.event.MenuEvent;
24 import javax.swing.event.MenuListener;
30 public class SequenceAnnotationWSClient extends Jws2Client
33 public static final String AAConCalcId = "jabaws2.AACon";
36 * initialise a client so its attachWSMenuEntry method can be called.
38 public SequenceAnnotationWSClient()
40 // TODO Auto-generated constructor stub
43 public SequenceAnnotationWSClient(final Jws2Instance sh,
44 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
46 super(alignFrame, preset, null);
47 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
50 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
51 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
53 if (alignFrame.getViewport().getAlignment().isNucleotide())
55 JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
56 + " can only be used\nfor amino acid alignments.",
57 "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
61 if (sh.action.toLowerCase().contains("conservation"))
63 // Build an AACon style client - take alignment, return annotation for
66 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
68 .getRegisteredWorkersOfClass(AAConClient.class);
69 if (clnts == null || clnts.size() == 0)
71 if (!processParams(sh, editParams))
80 worker = new AAConClient(sh, alignFrame,
81 this.preset, paramset));
82 alignFrame.getViewport().getCalcManager().startWorker(worker);
87 AAConClient worker = (AAConClient) clnts.get(0);
90 paramset = worker.getArguments();
91 preset = worker.getPreset();
94 if (!processParams(sh, editParams, true))
98 // reinstate worker if it was blacklisted (might have happened due to
99 // invalid parameters)
100 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
101 worker.updateParameters(this.preset, paramset);
105 if (sh.action.toLowerCase().contains("disorder"))
107 // build IUPred style client. take sequences, returns annotation per
109 if (!processParams(sh, editParams))
118 new AADisorderClient(sh, alignFrame, preset, paramset));
123 public SequenceAnnotationWSClient(AAConSettings fave,
124 AlignFrame alignFrame, boolean b)
126 super(alignFrame, fave.getPreset(), fave.getJobArgset());
127 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
128 fave.getPreset(), b);
134 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
135 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
137 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
138 final AlignFrame alignFrame)
140 if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
143 registerAAConWSInstance(wsmenu, service, alignFrame);
146 boolean hasparams = service.hasParameters();
147 // Assume name ends in WS
148 String calcName = service.serviceType.substring(0,
149 service.serviceType.length() - 2);
151 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
152 annotservice.addActionListener(new ActionListener()
156 public void actionPerformed(ActionEvent e)
158 new SequenceAnnotationWSClient(service, alignFrame, null, false);
161 wsmenu.add(annotservice);
164 // only add these menu options if the service has user-modifiable
166 annotservice = new JMenuItem("Edit settings and run ...");
167 annotservice.setToolTipText("View and change parameters before running calculation");
169 annotservice.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent e)
173 new SequenceAnnotationWSClient(service, alignFrame, null, true);
176 wsmenu.add(annotservice);
177 List<WsParamSetI> presets = service.getParamStore().getPresets();
178 if (presets != null && presets.size() > 0)
180 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
182 for (final WsParamSetI preset : presets)
184 final JMenuItem methodR = new JMenuItem(preset.getName());
185 methodR.setToolTipText("<html><p>"
186 + JvSwingUtils.wrapTooltip("<strong>"
187 + (preset.isModifiable() ? "User Preset"
188 : "Service Preset") + "</strong><br/>"
189 + preset.getDescription() + "</p>") + "</html>");
190 methodR.addActionListener(new ActionListener()
192 public void actionPerformed(ActionEvent e)
194 new SequenceAnnotationWSClient(service, alignFrame, preset,
199 presetlist.add(methodR);
201 wsmenu.add(presetlist);
205 annotservice = new JMenuItem("View documentation");
206 if (service.docUrl!=null)
208 annotservice.addActionListener(new ActionListener()
212 public void actionPerformed(ActionEvent arg0)
214 Desktop.instance.showUrl(service.docUrl);
217 annotservice.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("View <a href=\""+service.docUrl+"\">"+service.docUrl+"</a>")+"</html>");
218 wsmenu.add(annotservice);
223 private final String AAconToggle = "AACon Calculations",
224 AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
225 AAeditSettings = "Change AACon Settings...",
226 AAeditSettingsTooltip = "Modify settings for AACon calculations.";
228 private void registerAAConWSInstance(final JMenu wsmenu,
229 final Jws2Instance service, final AlignFrame alignFrame)
231 // register this in the AACon settings set
232 JCheckBoxMenuItem _aaConEnabled = null;
233 for (int i = 0; i < wsmenu.getItemCount(); i++)
235 JMenuItem item = wsmenu.getItem(i);
236 if (item instanceof JCheckBoxMenuItem
237 && item.getText().equals(AAconToggle))
239 _aaConEnabled = (JCheckBoxMenuItem) item;
242 // is there an aaCon worker already present - if so, set it to use the
243 // given service handle
245 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
247 .getRegisteredWorkersOfClass(AAConClient.class);
248 if (aaconClient != null && aaconClient.size() > 0)
250 AAConClient worker = (AAConClient) aaconClient.get(0);
251 if (!worker.service.hosturl.equals(service.hosturl))
253 // javax.swing.SwingUtilities.invokeLater(new Runnable()
258 removeCurrentAAConWorkerFor(alignFrame);
259 buildCurrentAAConWorkerFor(alignFrame, service);
266 // is there a service already registered ? there shouldn't be if we are
267 // being called correctly
268 if (_aaConEnabled == null)
270 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
272 wsmenu.addMenuListener(new MenuListener()
276 public void menuSelected(MenuEvent arg0)
278 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
280 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
282 .getRegisteredWorkersOfClass(AAConClient.class);
283 if (aaconClient != null && aaconClient.size() > 0)
285 aaConEnabled.setSelected(true);
289 aaConEnabled.setSelected(false);
294 public void menuDeselected(MenuEvent arg0)
296 // TODO Auto-generated method stub
301 public void menuCanceled(MenuEvent arg0)
303 // TODO Auto-generated method stub
307 aaConEnabled.setToolTipText("<html><p>"
308 + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "</p>")
310 aaConEnabled.addActionListener(new ActionListener()
313 public void actionPerformed(ActionEvent arg0)
315 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
317 .getRegisteredWorkersOfClass(AAConClient.class);
318 if (aaconClient != null && aaconClient.size() > 0)
320 removeCurrentAAConWorkerFor(alignFrame);
324 buildCurrentAAConWorkerFor(alignFrame);
330 wsmenu.add(aaConEnabled);
331 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
332 modifyParams.setToolTipText("<html><p>"
333 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
335 modifyParams.addActionListener(new ActionListener()
339 public void actionPerformed(ActionEvent arg0)
341 showAAConAnnotationSettingsFor(alignFrame);
344 wsmenu.add(modifyParams);
349 private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
352 * preferred settings Whether AACon is automatically recalculated Which
353 * AACon server to use What parameters to use
355 // could actually do a class search for this too
356 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
357 .getCalcIdSettingsFor(AAConCalcId);
360 fave = createDefaultAAConSettings();
362 new SequenceAnnotationWSClient(fave, alignFrame, true);
366 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
368 buildCurrentAAConWorkerFor(alignFrame, null);
371 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
372 Jws2Instance service)
375 * preferred settings Whether AACon is automatically recalculated Which
376 * AACon server to use What parameters to use
378 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
379 .getCalcIdSettingsFor(AAConCalcId);
382 fave = createDefaultAAConSettings(service);
387 && !fave.getService().hosturl.equals(service.hosturl))
389 Cache.log.debug("Changing AACon service to " + service.hosturl
390 + " from " + fave.getService().hosturl);
391 fave.setService(service);
394 new SequenceAnnotationWSClient(fave, alignFrame, false);
397 private static AAConSettings createDefaultAAConSettings()
399 return createDefaultAAConSettings(null);
402 private static AAConSettings createDefaultAAConSettings(
403 Jws2Instance service)
407 if (!service.serviceType.toString().equals(
408 compbio.ws.client.Services.AAConWS.toString()))
411 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
412 + service.serviceType + ")");
417 // check service is actually in the list of currently avaialable
419 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
428 // get the default service for AACon
429 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
430 compbio.ws.client.Services.AAConWS.toString());
434 // TODO raise dialog box explaining error, and/or open the JABA
436 throw new Error("No AACon service found.");
438 return new AAConSettings(true, service, null, null);
441 private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
443 alignFrame.getViewport().getCalcManager()
444 .removeRegisteredWorkersOfClass(AAConClient.class);