2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws2;
20 import jalview.api.AlignCalcWorkerI;
21 import jalview.bin.Cache;
22 import jalview.gui.AlignFrame;
23 import jalview.gui.Desktop;
24 import jalview.gui.JvSwingUtils;
25 import jalview.ws.jws2.dm.AAConSettings;
26 import jalview.ws.jws2.jabaws2.Jws2Instance;
27 import jalview.ws.params.WsParamSetI;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.util.List;
33 import javax.swing.JCheckBoxMenuItem;
34 import javax.swing.JMenu;
35 import javax.swing.JMenuItem;
36 import javax.swing.JOptionPane;
37 import javax.swing.event.MenuEvent;
38 import javax.swing.event.MenuListener;
44 public class SequenceAnnotationWSClient extends Jws2Client
47 public static final String AAConCalcId = "jabaws2.AACon";
50 * initialise a client so its attachWSMenuEntry method can be called.
52 public SequenceAnnotationWSClient()
54 // TODO Auto-generated constructor stub
57 public SequenceAnnotationWSClient(final Jws2Instance sh,
58 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
60 super(alignFrame, preset, null);
61 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
64 // dan think. Do I need to change this method to run RNAalifold through the GUI
66 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
67 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
69 // dan changed! dan test. comment out if conditional
70 // if (alignFrame.getViewport().getAlignment().isNucleotide())
72 // JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
73 // + " can only be used\nfor amino acid alignments.",
74 // "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
78 if (sh.action.toLowerCase().contains("conservation"))
80 // Build an AACon style client - take alignment, return annotation for
83 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
85 .getRegisteredWorkersOfClass(AAConClient.class);
86 if (clnts == null || clnts.size() == 0)
88 if (!processParams(sh, editParams))
97 worker = new AAConClient(sh, alignFrame,
98 this.preset, paramset));
99 alignFrame.getViewport().getCalcManager().startWorker(worker);
104 AAConClient worker = (AAConClient) clnts.get(0);
107 paramset = worker.getArguments();
108 preset = worker.getPreset();
111 if (!processParams(sh, editParams, true))
115 // reinstate worker if it was blacklisted (might have happened due to
116 // invalid parameters)
117 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
118 worker.updateParameters(this.preset, paramset);
122 if (sh.action.toLowerCase().contains("disorder"))
124 // build IUPred style client. take sequences, returns annotation per
126 if (!processParams(sh, editParams))
135 new AADisorderClient(sh, alignFrame, preset, paramset));
139 // dan test dan changed!
140 if (sh.action.toLowerCase().contains("rna structure prediction"))
143 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
145 .getRegisteredWorkersOfClass(RNAalifoldClient.class);
146 if (clnts == null || clnts.size() == 0)
148 if (!processParams(sh, editParams))
152 RNAalifoldClient worker;
157 worker = new RNAalifoldClient(sh, alignFrame,
158 this.preset, paramset));
159 alignFrame.getViewport().getCalcManager().startWorker(worker);
163 RNAalifoldClient worker = (RNAalifoldClient) clnts.get(0);
166 paramset = worker.getArguments();
167 preset = worker.getPreset();
170 if (!processParams(sh, editParams, true))
175 // reinstate worker if it was blacklisted (might have happened due to
176 // invalid parameters)
177 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
178 worker.updateParameters(this.preset, paramset);
184 // if (!processParams(sh, editParams, true))
193 // new RNAalifoldClient(sh, alignFrame, preset, paramset));
198 public SequenceAnnotationWSClient(AAConSettings fave,
199 AlignFrame alignFrame, boolean b)
201 super(alignFrame, fave.getPreset(), fave.getJobArgset());
202 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
203 fave.getPreset(), b);
209 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
210 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
212 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
213 final AlignFrame alignFrame)
215 if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
218 registerAAConWSInstance(wsmenu, service, alignFrame);
221 boolean hasparams = service.hasParameters();
222 // Assume name ends in WS
223 String calcName = service.serviceType.substring(0,
224 service.serviceType.length() - 2);
226 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
227 annotservice.addActionListener(new ActionListener()
231 public void actionPerformed(ActionEvent e)
233 new SequenceAnnotationWSClient(service, alignFrame, null, false);
236 wsmenu.add(annotservice);
239 // only add these menu options if the service has user-modifiable
241 annotservice = new JMenuItem("Edit settings and run ...");
243 .setToolTipText("View and change parameters before running calculation");
245 annotservice.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
249 new SequenceAnnotationWSClient(service, alignFrame, null, true);
252 wsmenu.add(annotservice);
253 List<WsParamSetI> presets = service.getParamStore().getPresets();
254 if (presets != null && presets.size() > 0)
256 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
258 for (final WsParamSetI preset : presets)
260 final JMenuItem methodR = new JMenuItem(preset.getName());
261 methodR.setToolTipText("<html><p>"
262 + JvSwingUtils.wrapTooltip("<strong>"
263 + (preset.isModifiable() ? "User Preset"
264 : "Service Preset") + "</strong><br/>"
265 + preset.getDescription() + "</p>") + "</html>");
266 methodR.addActionListener(new ActionListener()
268 public void actionPerformed(ActionEvent e)
270 new SequenceAnnotationWSClient(service, alignFrame, preset,
275 presetlist.add(methodR);
277 wsmenu.add(presetlist);
283 annotservice = new JMenuItem("View documentation");
284 if (service.docUrl != null)
286 annotservice.addActionListener(new ActionListener()
290 public void actionPerformed(ActionEvent arg0)
292 Desktop.instance.showUrl(service.docUrl);
295 annotservice.setToolTipText("<html>"
296 + JvSwingUtils.wrapTooltip("View <a href=\""
297 + service.docUrl + "\">" + service.docUrl + "</a>")
299 wsmenu.add(annotservice);
304 private final String AAconToggle = "AACon Calculations",
305 AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
306 AAeditSettings = "Change AACon Settings...",
307 AAeditSettingsTooltip = "Modify settings for AACon calculations.";
309 private void registerAAConWSInstance(final JMenu wsmenu,
310 final Jws2Instance service, final AlignFrame alignFrame)
312 // register this in the AACon settings set
313 JCheckBoxMenuItem _aaConEnabled = null;
314 for (int i = 0; i < wsmenu.getItemCount(); i++)
316 JMenuItem item = wsmenu.getItem(i);
317 if (item instanceof JCheckBoxMenuItem
318 && item.getText().equals(AAconToggle))
320 _aaConEnabled = (JCheckBoxMenuItem) item;
323 // is there an aaCon worker already present - if so, set it to use the
324 // given service handle
326 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
328 .getRegisteredWorkersOfClass(AAConClient.class);
329 if (aaconClient != null && aaconClient.size() > 0)
331 AAConClient worker = (AAConClient) aaconClient.get(0);
332 if (!worker.service.hosturl.equals(service.hosturl))
334 // javax.swing.SwingUtilities.invokeLater(new Runnable()
339 removeCurrentAAConWorkerFor(alignFrame);
340 buildCurrentAAConWorkerFor(alignFrame, service);
347 // is there a service already registered ? there shouldn't be if we are
348 // being called correctly
349 if (_aaConEnabled == null)
351 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
353 wsmenu.addMenuListener(new MenuListener()
357 public void menuSelected(MenuEvent arg0)
359 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
361 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
363 .getRegisteredWorkersOfClass(AAConClient.class);
364 if (aaconClient != null && aaconClient.size() > 0)
366 aaConEnabled.setSelected(true);
370 aaConEnabled.setSelected(false);
375 public void menuDeselected(MenuEvent arg0)
377 // TODO Auto-generated method stub
382 public void menuCanceled(MenuEvent arg0)
384 // TODO Auto-generated method stub
388 aaConEnabled.setToolTipText("<html><p>"
389 + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "</p>")
391 aaConEnabled.addActionListener(new ActionListener()
394 public void actionPerformed(ActionEvent arg0)
396 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
398 .getRegisteredWorkersOfClass(AAConClient.class);
399 if (aaconClient != null && aaconClient.size() > 0)
401 removeCurrentAAConWorkerFor(alignFrame);
405 buildCurrentAAConWorkerFor(alignFrame);
411 wsmenu.add(aaConEnabled);
412 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
413 modifyParams.setToolTipText("<html><p>"
414 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
416 modifyParams.addActionListener(new ActionListener()
420 public void actionPerformed(ActionEvent arg0)
422 showAAConAnnotationSettingsFor(alignFrame);
425 wsmenu.add(modifyParams);
430 private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
433 * preferred settings Whether AACon is automatically recalculated Which
434 * AACon server to use What parameters to use
436 // could actually do a class search for this too
437 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
438 .getCalcIdSettingsFor(AAConCalcId);
441 fave = createDefaultAAConSettings();
443 new SequenceAnnotationWSClient(fave, alignFrame, true);
447 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
449 buildCurrentAAConWorkerFor(alignFrame, null);
452 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
453 Jws2Instance service)
456 * preferred settings Whether AACon is automatically recalculated Which
457 * AACon server to use What parameters to use
459 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
460 .getCalcIdSettingsFor(AAConCalcId);
463 fave = createDefaultAAConSettings(service);
468 && !fave.getService().hosturl.equals(service.hosturl))
470 Cache.log.debug("Changing AACon service to " + service.hosturl
471 + " from " + fave.getService().hosturl);
472 fave.setService(service);
475 new SequenceAnnotationWSClient(fave, alignFrame, false);
478 private static AAConSettings createDefaultAAConSettings()
480 return createDefaultAAConSettings(null);
483 private static AAConSettings createDefaultAAConSettings(
484 Jws2Instance service)
488 if (!service.serviceType.toString().equals(
489 compbio.ws.client.Services.AAConWS.toString()))
492 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
493 + service.serviceType + ")");
498 // check service is actually in the list of currently avaialable
500 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
509 // get the default service for AACon
510 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
511 compbio.ws.client.Services.AAConWS.toString());
515 // TODO raise dialog box explaining error, and/or open the JABA
517 throw new Error("No AACon service found.");
519 return new AAConSettings(true, service, null, null);
522 private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
524 alignFrame.getViewport().getCalcManager()
525 .removeRegisteredWorkersOfClass(AAConClient.class);