2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.jws2;
21 import jalview.api.AlignCalcWorkerI;
22 import jalview.bin.Cache;
23 import jalview.gui.AlignFrame;
24 import jalview.gui.Desktop;
25 import jalview.gui.JvSwingUtils;
26 import jalview.util.MessageManager;
27 import jalview.ws.jws2.dm.AAConSettings;
28 import jalview.ws.jws2.jabaws2.Jws2Instance;
29 import jalview.ws.params.WsParamSetI;
30 import jalview.ws.uimodel.AlignAnalysisUIText;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.util.List;
36 import javax.swing.JCheckBoxMenuItem;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuItem;
39 import javax.swing.JOptionPane;
40 import javax.swing.event.MenuEvent;
41 import javax.swing.event.MenuListener;
47 public class SequenceAnnotationWSClient extends Jws2Client
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 AlignAnalysisUIText aaui = sh.getAlignAnalysisUI();
81 Class clientClass = aaui.getClient();
83 // Build an AACon style client - take alignment, return annotation for
86 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
88 .getRegisteredWorkersOfClass(clientClass);
89 JabawsAlignCalcWorker worker;
90 if (clnts == null || clnts.size() == 0)
92 if (!processParams(sh, editParams))
97 worker = (JabawsAlignCalcWorker) (clientClass.getConstructor(
98 new Class[] { Jws2Instance.class,
99 AlignFrame.class, WsParamSetI.class,
100 List.class }).newInstance(new Object[] { sh, alignFrame, this.preset, paramset}));
101 } catch (Exception x)
104 throw new Error("Implementation error",x);
111 alignFrame.getViewport().getCalcManager().startWorker(worker);
116 worker = (JabawsAlignCalcWorker) clnts.get(0);
119 paramset = worker.getArguments();
120 preset = worker.getPreset();
123 if (!processParams(sh, editParams, true))
127 // reinstate worker if it was blacklisted (might have happened due to
128 // invalid parameters)
129 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
130 worker.updateParameters(this.preset, paramset);
133 if (sh.action.toLowerCase().contains("disorder"))
135 // build IUPred style client. take sequences, returns annotation per
137 if (!processParams(sh, editParams))
146 new AADisorderClient(sh, alignFrame, preset, paramset));
150 public SequenceAnnotationWSClient(AAConSettings fave,
151 AlignFrame alignFrame, boolean b)
153 super(alignFrame, fave.getPreset(), fave.getJobArgset());
154 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
155 fave.getPreset(), b);
161 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
162 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
164 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
165 final AlignFrame alignFrame)
167 if (registerAAConWSInstance(wsmenu, service, alignFrame)) {
168 // Alignment dependent analysis calculation WS gui
171 boolean hasparams = service.hasParameters();
172 // Assume name ends in WS
173 String calcName = service.serviceType.substring(0,
174 service.serviceType.length() - 2);
176 JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage("label.calcname_with_default_settings", new String[]{calcName}));
177 annotservice.addActionListener(new ActionListener()
181 public void actionPerformed(ActionEvent e)
183 new SequenceAnnotationWSClient(service, alignFrame, null, false);
186 wsmenu.add(annotservice);
189 // only add these menu options if the service has user-modifiable
191 annotservice = new JMenuItem(MessageManager.getString("label.edit_settings_and_run"));
193 .setToolTipText(MessageManager.getString("label.view_and_change_parameters_before_running_calculation"));
195 annotservice.addActionListener(new ActionListener()
197 public void actionPerformed(ActionEvent e)
199 new SequenceAnnotationWSClient(service, alignFrame, null, true);
202 wsmenu.add(annotservice);
203 List<WsParamSetI> presets = service.getParamStore().getPresets();
204 if (presets != null && presets.size() > 0)
206 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
208 for (final WsParamSetI preset : presets)
210 final JMenuItem methodR = new JMenuItem(preset.getName());
211 methodR.setToolTipText("<html><p>"
212 + JvSwingUtils.wrapTooltip("<strong>"
213 + (preset.isModifiable() ? "User Preset"
214 : "Service Preset") + "</strong><br/>"
215 + preset.getDescription() + "</p>") + "</html>");
216 methodR.addActionListener(new ActionListener()
218 public void actionPerformed(ActionEvent e)
220 new SequenceAnnotationWSClient(service, alignFrame, preset,
225 presetlist.add(methodR);
227 wsmenu.add(presetlist);
233 annotservice = new JMenuItem(MessageManager.getString("label.view_documentation"));
234 if (service.docUrl != null)
236 annotservice.addActionListener(new ActionListener()
240 public void actionPerformed(ActionEvent arg0)
242 Desktop.instance.showUrl(service.docUrl);
245 annotservice.setToolTipText("<html>"
246 + JvSwingUtils.wrapTooltip("View <a href=\""
247 + service.docUrl + "\">" + service.docUrl + "</a>")
249 wsmenu.add(annotservice);
255 private boolean registerAAConWSInstance(final JMenu wsmenu,
256 final Jws2Instance service, final AlignFrame alignFrame)
258 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
261 // not an instantaneous calculation GUI type service
264 // create the instaneous calculation GUI bits and update state if existing GUI elements already present
266 JCheckBoxMenuItem _aaConEnabled = null;
267 for (int i = 0; i < wsmenu.getItemCount(); i++)
269 JMenuItem item = wsmenu.getItem(i);
270 if (item instanceof JCheckBoxMenuItem
271 && item.getText().equals(aaui.getAAconToggle()))
273 _aaConEnabled = (JCheckBoxMenuItem) item;
276 // is there an aaCon worker already present - if so, set it to use the
277 // given service handle
279 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
281 .getRegisteredWorkersOfClass(aaui.getClient());
282 if (aaconClient != null && aaconClient.size() > 0)
284 JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient.get(0);
285 if (!worker.service.hosturl.equals(service.hosturl))
287 // javax.swing.SwingUtilities.invokeLater(new Runnable()
292 removeCurrentAAConWorkerFor(aaui, alignFrame);
293 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
300 // is there a service already registered ? there shouldn't be if we are
301 // being called correctly
302 if (_aaConEnabled == null)
304 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
305 aaui.getAAconToggle());
307 aaConEnabled.setToolTipText("<html><p>"
308 + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "</p>")
310 aaConEnabled.addActionListener(new ActionListener()
313 public void actionPerformed(ActionEvent arg0)
315 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
317 .getRegisteredWorkersOfClass(aaui.getClient());
318 if (aaconClient != null && aaconClient.size() > 0)
320 removeCurrentAAConWorkerFor(aaui, alignFrame);
324 buildCurrentAAConWorkerFor(aaui, alignFrame);
330 wsmenu.add(aaConEnabled);
331 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
332 modifyParams.setToolTipText("<html><p>"
333 + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "</p>")
335 modifyParams.addActionListener(new ActionListener()
339 public void actionPerformed(ActionEvent arg0)
341 showAAConAnnotationSettingsFor(aaui, alignFrame);
344 wsmenu.add(modifyParams);
345 wsmenu.addMenuListener(new MenuListener()
349 public void menuSelected(MenuEvent arg0)
351 // TODO: refactor to the implementing class.
352 if (alignFrame.getViewport().getAlignment()
353 .isNucleotide() ? aaui.isNa() : aaui.isPr()) {
354 aaConEnabled.setEnabled(true);
355 modifyParams.setEnabled(true);
358 aaConEnabled.setEnabled(false);
359 modifyParams.setEnabled(false);
361 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
363 .getRegisteredWorkersOfClass(aaui.getClient());
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
393 private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
396 * preferred settings Whether AACon is automatically recalculated Which
397 * AACon server to use What parameters to use
399 // could actually do a class search for this too
400 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
401 .getCalcIdSettingsFor(aaui.getCalcId());
404 fave = createDefaultAAConSettings(aaui);
406 new SequenceAnnotationWSClient(fave, alignFrame, true);
410 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
412 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
415 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame,
416 Jws2Instance service)
419 * preferred settings Whether AACon is automatically recalculated Which
420 * AACon server to use What parameters to use
422 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
423 .getCalcIdSettingsFor(aaui.getCalcId());
426 fave = createDefaultAAConSettings(aaui, service);
431 && !fave.getService().hosturl.equals(service.hosturl))
433 Cache.log.debug("Changing AACon service to " + service.hosturl
434 + " from " + fave.getService().hosturl);
435 fave.setService(service);
438 new SequenceAnnotationWSClient(fave, alignFrame, false);
441 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui)
443 return createDefaultAAConSettings(aaui, null);
446 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui,
447 Jws2Instance service)
451 if (!service.serviceType.toString().equals(
452 compbio.ws.client.Services.AAConWS.toString()))
455 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
456 + service.serviceType + ")");
461 // check service is actually in the list of currently avaialable
463 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
472 // get the default service for AACon
473 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
474 aaui.getServiceType());
478 // TODO raise dialog box explaining error, and/or open the JABA
480 throw new Error("No AACon service found.");
482 return new AAConSettings(true, service, null, null);
485 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame)
487 alignFrame.getViewport().getCalcManager()
488 .removeRegisteredWorkersOfClass(aaui.getClient());