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 public SequenceAnnotationWSClient(AAConSettings fave,
185 AlignFrame alignFrame, boolean b)
187 super(alignFrame, fave.getPreset(), fave.getJobArgset());
188 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
189 fave.getPreset(), b);
195 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
196 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
198 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
199 final AlignFrame alignFrame)
201 if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
204 registerAAConWSInstance(wsmenu, service, alignFrame);
207 boolean hasparams = service.hasParameters();
208 // Assume name ends in WS
209 String calcName = service.serviceType.substring(0,
210 service.serviceType.length() - 2);
212 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
213 annotservice.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 new SequenceAnnotationWSClient(service, alignFrame, null, false);
222 wsmenu.add(annotservice);
225 // only add these menu options if the service has user-modifiable
227 annotservice = new JMenuItem("Edit settings and run ...");
229 .setToolTipText("View and change parameters before running calculation");
231 annotservice.addActionListener(new ActionListener()
233 public void actionPerformed(ActionEvent e)
235 new SequenceAnnotationWSClient(service, alignFrame, null, true);
238 wsmenu.add(annotservice);
239 List<WsParamSetI> presets = service.getParamStore().getPresets();
240 if (presets != null && presets.size() > 0)
242 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
244 for (final WsParamSetI preset : presets)
246 final JMenuItem methodR = new JMenuItem(preset.getName());
247 methodR.setToolTipText("<html><p>"
248 + JvSwingUtils.wrapTooltip("<strong>"
249 + (preset.isModifiable() ? "User Preset"
250 : "Service Preset") + "</strong><br/>"
251 + preset.getDescription() + "</p>") + "</html>");
252 methodR.addActionListener(new ActionListener()
254 public void actionPerformed(ActionEvent e)
256 new SequenceAnnotationWSClient(service, alignFrame, preset,
261 presetlist.add(methodR);
263 wsmenu.add(presetlist);
269 annotservice = new JMenuItem("View documentation");
270 if (service.docUrl != null)
272 annotservice.addActionListener(new ActionListener()
276 public void actionPerformed(ActionEvent arg0)
278 Desktop.instance.showUrl(service.docUrl);
281 annotservice.setToolTipText("<html>"
282 + JvSwingUtils.wrapTooltip("View <a href=\""
283 + service.docUrl + "\">" + service.docUrl + "</a>")
285 wsmenu.add(annotservice);
290 private final String AAconToggle = "AACon Calculations",
291 AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
292 AAeditSettings = "Change AACon Settings...",
293 AAeditSettingsTooltip = "Modify settings for AACon calculations.";
295 private void registerAAConWSInstance(final JMenu wsmenu,
296 final Jws2Instance service, final AlignFrame alignFrame)
298 // register this in the AACon settings set
299 JCheckBoxMenuItem _aaConEnabled = null;
300 for (int i = 0; i < wsmenu.getItemCount(); i++)
302 JMenuItem item = wsmenu.getItem(i);
303 if (item instanceof JCheckBoxMenuItem
304 && item.getText().equals(AAconToggle))
306 _aaConEnabled = (JCheckBoxMenuItem) item;
309 // is there an aaCon worker already present - if so, set it to use the
310 // given service handle
312 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
314 .getRegisteredWorkersOfClass(AAConClient.class);
315 if (aaconClient != null && aaconClient.size() > 0)
317 AAConClient worker = (AAConClient) aaconClient.get(0);
318 if (!worker.service.hosturl.equals(service.hosturl))
320 // javax.swing.SwingUtilities.invokeLater(new Runnable()
325 removeCurrentAAConWorkerFor(alignFrame);
326 buildCurrentAAConWorkerFor(alignFrame, service);
333 // is there a service already registered ? there shouldn't be if we are
334 // being called correctly
335 if (_aaConEnabled == null)
337 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
339 wsmenu.addMenuListener(new MenuListener()
343 public void menuSelected(MenuEvent arg0)
345 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
347 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
349 .getRegisteredWorkersOfClass(AAConClient.class);
350 if (aaconClient != null && aaconClient.size() > 0)
352 aaConEnabled.setSelected(true);
356 aaConEnabled.setSelected(false);
361 public void menuDeselected(MenuEvent arg0)
363 // TODO Auto-generated method stub
368 public void menuCanceled(MenuEvent arg0)
370 // TODO Auto-generated method stub
374 aaConEnabled.setToolTipText("<html><p>"
375 + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "</p>")
377 aaConEnabled.addActionListener(new ActionListener()
380 public void actionPerformed(ActionEvent arg0)
382 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
384 .getRegisteredWorkersOfClass(AAConClient.class);
385 if (aaconClient != null && aaconClient.size() > 0)
387 removeCurrentAAConWorkerFor(alignFrame);
391 buildCurrentAAConWorkerFor(alignFrame);
397 wsmenu.add(aaConEnabled);
398 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
399 modifyParams.setToolTipText("<html><p>"
400 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
402 modifyParams.addActionListener(new ActionListener()
406 public void actionPerformed(ActionEvent arg0)
408 showAAConAnnotationSettingsFor(alignFrame);
411 wsmenu.add(modifyParams);
416 private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
419 * preferred settings Whether AACon is automatically recalculated Which
420 * AACon server to use What parameters to use
422 // could actually do a class search for this too
423 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
424 .getCalcIdSettingsFor(AAConCalcId);
427 fave = createDefaultAAConSettings();
429 new SequenceAnnotationWSClient(fave, alignFrame, true);
433 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
435 buildCurrentAAConWorkerFor(alignFrame, null);
438 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
439 Jws2Instance service)
442 * preferred settings Whether AACon is automatically recalculated Which
443 * AACon server to use What parameters to use
445 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
446 .getCalcIdSettingsFor(AAConCalcId);
449 fave = createDefaultAAConSettings(service);
454 && !fave.getService().hosturl.equals(service.hosturl))
456 Cache.log.debug("Changing AACon service to " + service.hosturl
457 + " from " + fave.getService().hosturl);
458 fave.setService(service);
461 new SequenceAnnotationWSClient(fave, alignFrame, false);
464 private static AAConSettings createDefaultAAConSettings()
466 return createDefaultAAConSettings(null);
469 private static AAConSettings createDefaultAAConSettings(
470 Jws2Instance service)
474 if (!service.serviceType.toString().equals(
475 compbio.ws.client.Services.AAConWS.toString()))
478 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
479 + service.serviceType + ")");
484 // check service is actually in the list of currently avaialable
486 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
495 // get the default service for AACon
496 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
497 compbio.ws.client.Services.AAConWS.toString());
501 // TODO raise dialog box explaining error, and/or open the JABA
503 throw new Error("No AACon service found.");
505 return new AAConSettings(true, service, null, null);
508 private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
510 alignFrame.getViewport().getCalcManager()
511 .removeRegisteredWorkersOfClass(AAConClient.class);