2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws2;
23 import jalview.api.AlignCalcWorkerI;
24 import jalview.bin.Cache;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.Desktop;
27 import jalview.gui.JvSwingUtils;
28 import jalview.util.MessageManager;
29 import jalview.ws.jws2.dm.AAConSettings;
30 import jalview.ws.jws2.jabaws2.Jws2Instance;
31 import jalview.ws.params.WsParamSetI;
32 import jalview.ws.uimodel.AlignAnalysisUIText;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.util.List;
38 import javax.swing.JCheckBoxMenuItem;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuItem;
41 import javax.swing.JOptionPane;
42 import javax.swing.event.MenuEvent;
43 import javax.swing.event.MenuListener;
49 public class SequenceAnnotationWSClient extends Jws2Client
52 * initialise a client so its attachWSMenuEntry method can be called.
54 public SequenceAnnotationWSClient()
56 // TODO Auto-generated constructor stub
59 public SequenceAnnotationWSClient(final Jws2Instance sh,
60 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
62 super(alignFrame, preset, null);
63 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
66 // dan think. Do I need to change this method to run RNAalifold through the GUI
68 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
69 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
71 // dan changed! dan test. comment out if conditional
72 // if (alignFrame.getViewport().getAlignment().isNucleotide())
74 // JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
75 // + " can only be used\nfor amino acid alignments.",
76 // "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
80 AlignAnalysisUIText aaui = sh.getAlignAnalysisUI();
83 Class clientClass = aaui.getClient();
85 // Build an AACon style client - take alignment, return annotation for
88 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
90 .getRegisteredWorkersOfClass(clientClass);
91 JabawsAlignCalcWorker worker;
92 if (clnts == null || clnts.size() == 0)
94 if (!processParams(sh, editParams))
99 worker = (JabawsAlignCalcWorker) (clientClass.getConstructor(
100 new Class[] { Jws2Instance.class,
101 AlignFrame.class, WsParamSetI.class,
102 List.class }).newInstance(new Object[] { sh, alignFrame, this.preset, paramset}));
103 } catch (Exception x)
106 throw new Error("Implementation error",x);
113 alignFrame.getViewport().getCalcManager().startWorker(worker);
118 worker = (JabawsAlignCalcWorker) clnts.get(0);
121 paramset = worker.getArguments();
122 preset = worker.getPreset();
125 if (!processParams(sh, editParams, true))
129 // reinstate worker if it was blacklisted (might have happened due to
130 // invalid parameters)
131 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
132 worker.updateParameters(this.preset, paramset);
135 if (sh.action.toLowerCase().contains("disorder"))
137 // build IUPred style client. take sequences, returns annotation per
139 if (!processParams(sh, editParams))
148 new AADisorderClient(sh, alignFrame, preset, paramset));
152 public SequenceAnnotationWSClient(AAConSettings fave,
153 AlignFrame alignFrame, boolean b)
155 super(alignFrame, fave.getPreset(), fave.getJobArgset());
156 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
157 fave.getPreset(), b);
163 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
164 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
166 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
167 final AlignFrame alignFrame)
169 if (registerAAConWSInstance(wsmenu, service, alignFrame)) {
170 // Alignment dependent analysis calculation WS gui
173 boolean hasparams = service.hasParameters();
174 // Assume name ends in WS
175 String calcName = service.serviceType.substring(0,
176 service.serviceType.length() - 2);
178 JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage("label.calcname_with_default_settings", new String[]{calcName}));
179 annotservice.addActionListener(new ActionListener()
183 public void actionPerformed(ActionEvent e)
185 new SequenceAnnotationWSClient(service, alignFrame, null, false);
188 wsmenu.add(annotservice);
191 // only add these menu options if the service has user-modifiable
193 annotservice = new JMenuItem(MessageManager.getString("label.edit_settings_and_run"));
195 .setToolTipText(MessageManager.getString("label.view_and_change_parameters_before_running_calculation"));
197 annotservice.addActionListener(new ActionListener()
199 public void actionPerformed(ActionEvent e)
201 new SequenceAnnotationWSClient(service, alignFrame, null, true);
204 wsmenu.add(annotservice);
205 List<WsParamSetI> presets = service.getParamStore().getPresets();
206 if (presets != null && presets.size() > 0)
208 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
210 for (final WsParamSetI preset : presets)
212 final JMenuItem methodR = new JMenuItem(preset.getName());
213 methodR.setToolTipText("<html><p>"
214 + JvSwingUtils.wrapTooltip("<strong>"
215 + (preset.isModifiable() ? "User Preset"
216 : "Service Preset") + "</strong><br/>"
217 + preset.getDescription() + "</p>") + "</html>");
218 methodR.addActionListener(new ActionListener()
220 public void actionPerformed(ActionEvent e)
222 new SequenceAnnotationWSClient(service, alignFrame, preset,
227 presetlist.add(methodR);
229 wsmenu.add(presetlist);
235 annotservice = new JMenuItem(MessageManager.getString("label.view_documentation"));
236 if (service.docUrl != null)
238 annotservice.addActionListener(new ActionListener()
242 public void actionPerformed(ActionEvent arg0)
244 Desktop.instance.showUrl(service.docUrl);
247 annotservice.setToolTipText("<html>"
248 + JvSwingUtils.wrapTooltip("View <a href=\""
249 + service.docUrl + "\">" + service.docUrl + "</a>")
251 wsmenu.add(annotservice);
257 private boolean registerAAConWSInstance(final JMenu wsmenu,
258 final Jws2Instance service, final AlignFrame alignFrame)
260 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
263 // not an instantaneous calculation GUI type service
266 // create the instaneous calculation GUI bits and update state if existing GUI elements already present
268 JCheckBoxMenuItem _aaConEnabled = null;
269 for (int i = 0; i < wsmenu.getItemCount(); i++)
271 JMenuItem item = wsmenu.getItem(i);
272 if (item instanceof JCheckBoxMenuItem
273 && item.getText().equals(aaui.getAAconToggle()))
275 _aaConEnabled = (JCheckBoxMenuItem) item;
278 // is there an aaCon worker already present - if so, set it to use the
279 // given service handle
281 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
283 .getRegisteredWorkersOfClass(aaui.getClient());
284 if (aaconClient != null && aaconClient.size() > 0)
286 JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient.get(0);
287 if (!worker.service.hosturl.equals(service.hosturl))
289 // javax.swing.SwingUtilities.invokeLater(new Runnable()
294 removeCurrentAAConWorkerFor(aaui, alignFrame);
295 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
302 // is there a service already registered ? there shouldn't be if we are
303 // being called correctly
304 if (_aaConEnabled == null)
306 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
307 aaui.getAAconToggle());
309 aaConEnabled.setToolTipText("<html><p>"
310 + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "</p>")
312 aaConEnabled.addActionListener(new ActionListener()
315 public void actionPerformed(ActionEvent arg0)
317 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
319 .getRegisteredWorkersOfClass(aaui.getClient());
320 if (aaconClient != null && aaconClient.size() > 0)
322 removeCurrentAAConWorkerFor(aaui, alignFrame);
326 buildCurrentAAConWorkerFor(aaui, alignFrame);
332 wsmenu.add(aaConEnabled);
333 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
334 modifyParams.setToolTipText("<html><p>"
335 + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "</p>")
337 modifyParams.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent arg0)
343 showAAConAnnotationSettingsFor(aaui, alignFrame);
346 wsmenu.add(modifyParams);
347 wsmenu.addMenuListener(new MenuListener()
351 public void menuSelected(MenuEvent arg0)
353 // TODO: refactor to the implementing class.
354 if (alignFrame.getViewport().getAlignment()
355 .isNucleotide() ? aaui.isNa() : aaui.isPr()) {
356 aaConEnabled.setEnabled(true);
357 modifyParams.setEnabled(true);
360 aaConEnabled.setEnabled(false);
361 modifyParams.setEnabled(false);
363 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
365 .getRegisteredWorkersOfClass(aaui.getClient());
366 if (aaconClient != null && aaconClient.size() > 0)
368 aaConEnabled.setSelected(true);
372 aaConEnabled.setSelected(false);
377 public void menuDeselected(MenuEvent arg0)
379 // TODO Auto-generated method stub
384 public void menuCanceled(MenuEvent arg0)
386 // TODO Auto-generated method stub
395 private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
398 * preferred settings Whether AACon is automatically recalculated Which
399 * AACon server to use What parameters to use
401 // could actually do a class search for this too
402 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
403 .getCalcIdSettingsFor(aaui.getCalcId());
406 fave = createDefaultAAConSettings(aaui);
408 new SequenceAnnotationWSClient(fave, alignFrame, true);
412 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
414 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
417 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame,
418 Jws2Instance service)
421 * preferred settings Whether AACon is automatically recalculated Which
422 * AACon server to use What parameters to use
424 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
425 .getCalcIdSettingsFor(aaui.getCalcId());
428 fave = createDefaultAAConSettings(aaui, service);
433 && !fave.getService().hosturl.equals(service.hosturl))
435 Cache.log.debug("Changing AACon service to " + service.hosturl
436 + " from " + fave.getService().hosturl);
437 fave.setService(service);
440 new SequenceAnnotationWSClient(fave, alignFrame, false);
443 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui)
445 return createDefaultAAConSettings(aaui, null);
448 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui,
449 Jws2Instance service)
453 if (!service.serviceType.toString().equals(
454 compbio.ws.client.Services.AAConWS.toString()))
457 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
458 + service.serviceType + ")");
463 // check service is actually in the list of currently avaialable
465 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
474 // get the default service for AACon
475 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
476 aaui.getServiceType());
480 // TODO raise dialog box explaining error, and/or open the JABA
482 throw new Error("No AACon service found.");
484 return new AAConSettings(true, service, null, null);
487 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame)
489 alignFrame.getViewport().getCalcManager()
490 .removeRegisteredWorkersOfClass(aaui.getClient());