2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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.ws.jws2.dm.AAConSettings;
27 import jalview.ws.jws2.jabaws2.Jws2Instance;
28 import jalview.ws.params.WsParamSetI;
29 import jalview.ws.uimodel.AlignAnalysisUIText;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.util.List;
35 import javax.swing.JCheckBoxMenuItem;
36 import javax.swing.JMenu;
37 import javax.swing.JMenuItem;
38 import javax.swing.JOptionPane;
39 import javax.swing.event.MenuEvent;
40 import javax.swing.event.MenuListener;
46 public class SequenceAnnotationWSClient extends Jws2Client
49 * initialise a client so its attachWSMenuEntry method can be called.
51 public SequenceAnnotationWSClient()
53 // TODO Auto-generated constructor stub
56 public SequenceAnnotationWSClient(final Jws2Instance sh,
57 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
59 super(alignFrame, preset, null);
60 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
63 // dan think. Do I need to change this method to run RNAalifold through the GUI
65 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
66 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
68 // dan changed! dan test. comment out if conditional
69 // if (alignFrame.getViewport().getAlignment().isNucleotide())
71 // JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
72 // + " can only be used\nfor amino acid alignments.",
73 // "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
77 AlignAnalysisUIText aaui = sh.getAlignAnalysisUI();
80 Class clientClass = aaui.getClient();
82 // Build an AACon style client - take alignment, return annotation for
85 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
87 .getRegisteredWorkersOfClass(clientClass);
88 JabawsAlignCalcWorker worker;
89 if (clnts == null || clnts.size() == 0)
91 if (!processParams(sh, editParams))
96 worker = (JabawsAlignCalcWorker) (clientClass.getConstructor(
97 new Class[] { Jws2Instance.class,
98 AlignFrame.class, WsParamSetI.class,
99 List.class }).newInstance(new Object[] { sh, alignFrame, this.preset, paramset}));
100 } catch (Exception x)
103 throw new Error("Implementation error",x);
110 alignFrame.getViewport().getCalcManager().startWorker(worker);
115 worker = (JabawsAlignCalcWorker) clnts.get(0);
118 paramset = worker.getArguments();
119 preset = worker.getPreset();
122 if (!processParams(sh, editParams, true))
126 // reinstate worker if it was blacklisted (might have happened due to
127 // invalid parameters)
128 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
129 worker.updateParameters(this.preset, paramset);
132 if (sh.action.toLowerCase().contains("disorder"))
134 // build IUPred style client. take sequences, returns annotation per
136 if (!processParams(sh, editParams))
145 new AADisorderClient(sh, alignFrame, preset, paramset));
149 public SequenceAnnotationWSClient(AAConSettings fave,
150 AlignFrame alignFrame, boolean b)
152 super(alignFrame, fave.getPreset(), fave.getJobArgset());
153 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
154 fave.getPreset(), b);
160 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
161 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
163 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
164 final AlignFrame alignFrame)
166 if (registerAAConWSInstance(wsmenu, service, alignFrame)) {
167 // Alignment dependent analysis calculation WS gui
170 boolean hasparams = service.hasParameters();
171 // Assume name ends in WS
172 String calcName = service.serviceType.substring(0,
173 service.serviceType.length() - 2);
175 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
176 annotservice.addActionListener(new ActionListener()
180 public void actionPerformed(ActionEvent e)
182 new SequenceAnnotationWSClient(service, alignFrame, null, false);
185 wsmenu.add(annotservice);
188 // only add these menu options if the service has user-modifiable
190 annotservice = new JMenuItem("Edit settings and run ...");
192 .setToolTipText("View and change parameters before running calculation");
194 annotservice.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 new SequenceAnnotationWSClient(service, alignFrame, null, true);
201 wsmenu.add(annotservice);
202 List<WsParamSetI> presets = service.getParamStore().getPresets();
203 if (presets != null && presets.size() > 0)
205 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
207 for (final WsParamSetI preset : presets)
209 final JMenuItem methodR = new JMenuItem(preset.getName());
210 methodR.setToolTipText("<html><p>"
211 + JvSwingUtils.wrapTooltip("<strong>"
212 + (preset.isModifiable() ? "User Preset"
213 : "Service Preset") + "</strong><br/>"
214 + preset.getDescription() + "</p>") + "</html>");
215 methodR.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 new SequenceAnnotationWSClient(service, alignFrame, preset,
224 presetlist.add(methodR);
226 wsmenu.add(presetlist);
232 annotservice = new JMenuItem("View documentation");
233 if (service.docUrl != null)
235 annotservice.addActionListener(new ActionListener()
239 public void actionPerformed(ActionEvent arg0)
241 Desktop.instance.showUrl(service.docUrl);
244 annotservice.setToolTipText("<html>"
245 + JvSwingUtils.wrapTooltip("View <a href=\""
246 + service.docUrl + "\">" + service.docUrl + "</a>")
248 wsmenu.add(annotservice);
254 private boolean registerAAConWSInstance(final JMenu wsmenu,
255 final Jws2Instance service, final AlignFrame alignFrame)
257 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
260 // not an instantaneous calculation GUI type service
263 // create the instaneous calculation GUI bits and update state if existing GUI elements already present
265 JCheckBoxMenuItem _aaConEnabled = null;
266 for (int i = 0; i < wsmenu.getItemCount(); i++)
268 JMenuItem item = wsmenu.getItem(i);
269 if (item instanceof JCheckBoxMenuItem
270 && item.getText().equals(aaui.getAAconToggle()))
272 _aaConEnabled = (JCheckBoxMenuItem) item;
275 // is there an aaCon worker already present - if so, set it to use the
276 // given service handle
278 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
280 .getRegisteredWorkersOfClass(aaui.getClient());
281 if (aaconClient != null && aaconClient.size() > 0)
283 JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient.get(0);
284 if (!worker.service.hosturl.equals(service.hosturl))
286 // javax.swing.SwingUtilities.invokeLater(new Runnable()
291 removeCurrentAAConWorkerFor(aaui, alignFrame);
292 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
299 // is there a service already registered ? there shouldn't be if we are
300 // being called correctly
301 if (_aaConEnabled == null)
303 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
304 aaui.getAAconToggle());
306 aaConEnabled.setToolTipText("<html><p>"
307 + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "</p>")
309 aaConEnabled.addActionListener(new ActionListener()
312 public void actionPerformed(ActionEvent arg0)
314 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
316 .getRegisteredWorkersOfClass(aaui.getClient());
317 if (aaconClient != null && aaconClient.size() > 0)
319 removeCurrentAAConWorkerFor(aaui, alignFrame);
323 buildCurrentAAConWorkerFor(aaui, alignFrame);
329 wsmenu.add(aaConEnabled);
330 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
331 modifyParams.setToolTipText("<html><p>"
332 + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "</p>")
334 modifyParams.addActionListener(new ActionListener()
338 public void actionPerformed(ActionEvent arg0)
340 showAAConAnnotationSettingsFor(aaui, alignFrame);
343 wsmenu.add(modifyParams);
344 wsmenu.addMenuListener(new MenuListener()
348 public void menuSelected(MenuEvent arg0)
350 // TODO: refactor to the implementing class.
351 if (alignFrame.getViewport().getAlignment()
352 .isNucleotide() ? aaui.isNa() : aaui.isPr()) {
353 aaConEnabled.setEnabled(true);
354 modifyParams.setEnabled(true);
357 aaConEnabled.setEnabled(false);
358 modifyParams.setEnabled(false);
360 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
362 .getRegisteredWorkersOfClass(aaui.getClient());
363 if (aaconClient != null && aaconClient.size() > 0)
365 aaConEnabled.setSelected(true);
369 aaConEnabled.setSelected(false);
374 public void menuDeselected(MenuEvent arg0)
376 // TODO Auto-generated method stub
381 public void menuCanceled(MenuEvent arg0)
383 // TODO Auto-generated method stub
392 private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
395 * preferred settings Whether AACon is automatically recalculated Which
396 * AACon server to use What parameters to use
398 // could actually do a class search for this too
399 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
400 .getCalcIdSettingsFor(aaui.getCalcId());
403 fave = createDefaultAAConSettings(aaui);
405 new SequenceAnnotationWSClient(fave, alignFrame, true);
409 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
411 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
414 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame,
415 Jws2Instance service)
418 * preferred settings Whether AACon is automatically recalculated Which
419 * AACon server to use What parameters to use
421 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
422 .getCalcIdSettingsFor(aaui.getCalcId());
425 fave = createDefaultAAConSettings(aaui, service);
430 && !fave.getService().hosturl.equals(service.hosturl))
432 Cache.log.debug("Changing AACon service to " + service.hosturl
433 + " from " + fave.getService().hosturl);
434 fave.setService(service);
437 new SequenceAnnotationWSClient(fave, alignFrame, false);
440 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui)
442 return createDefaultAAConSettings(aaui, null);
445 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui,
446 Jws2Instance service)
450 if (!service.serviceType.toString().equals(
451 compbio.ws.client.Services.AAConWS.toString()))
454 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
455 + service.serviceType + ")");
460 // check service is actually in the list of currently avaialable
462 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
471 // get the default service for AACon
472 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
473 aaui.getServiceType());
477 // TODO raise dialog box explaining error, and/or open the JABA
479 throw new Error("No AACon service found.");
481 return new AAConSettings(true, service, null, null);
484 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame)
486 alignFrame.getViewport().getCalcManager()
487 .removeRegisteredWorkersOfClass(aaui.getClient());