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;
28 import jalview.ws.uimodel.AlignAnalysisUIText;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.util.List;
34 import javax.swing.JCheckBoxMenuItem;
35 import javax.swing.JMenu;
36 import javax.swing.JMenuItem;
37 import javax.swing.JOptionPane;
38 import javax.swing.event.MenuEvent;
39 import javax.swing.event.MenuListener;
45 public class SequenceAnnotationWSClient extends Jws2Client
48 * initialise a client so its attachWSMenuEntry method can be called.
50 public SequenceAnnotationWSClient()
52 // TODO Auto-generated constructor stub
55 public SequenceAnnotationWSClient(final Jws2Instance sh,
56 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
58 super(alignFrame, preset, null);
59 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
62 // dan think. Do I need to change this method to run RNAalifold through the GUI
64 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
65 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
67 // dan changed! dan test. comment out if conditional
68 // if (alignFrame.getViewport().getAlignment().isNucleotide())
70 // JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
71 // + " can only be used\nfor amino acid alignments.",
72 // "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
76 AlignAnalysisUIText aaui = sh.getAlignAnalysisUI();
79 Class clientClass = aaui.getClient();
81 // Build an AACon style client - take alignment, return annotation for
84 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
86 .getRegisteredWorkersOfClass(clientClass);
87 JabawsAlignCalcWorker worker;
88 if (clnts == null || clnts.size() == 0)
90 if (!processParams(sh, editParams))
95 worker = (JabawsAlignCalcWorker) (clientClass.getConstructor(
96 new Class[] { Jws2Instance.class,
97 AlignFrame.class, WsParamSetI.class,
98 List.class }).newInstance(new Object[] { sh, alignFrame, this.preset, paramset}));
102 throw new Error("Implementation error",x);
109 alignFrame.getViewport().getCalcManager().startWorker(worker);
114 worker = (JabawsAlignCalcWorker) clnts.get(0);
117 paramset = worker.getArguments();
118 preset = worker.getPreset();
121 if (!processParams(sh, editParams, true))
125 // reinstate worker if it was blacklisted (might have happened due to
126 // invalid parameters)
127 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
128 worker.updateParameters(this.preset, paramset);
131 if (sh.action.toLowerCase().contains("disorder"))
133 // build IUPred style client. take sequences, returns annotation per
135 if (!processParams(sh, editParams))
144 new AADisorderClient(sh, alignFrame, preset, paramset));
148 public SequenceAnnotationWSClient(AAConSettings fave,
149 AlignFrame alignFrame, boolean b)
151 super(alignFrame, fave.getPreset(), fave.getJobArgset());
152 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
153 fave.getPreset(), b);
159 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
160 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
162 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
163 final AlignFrame alignFrame)
165 if (registerAAConWSInstance(wsmenu, service, alignFrame)) {
166 // Alignment dependent analysis calculation WS gui
169 boolean hasparams = service.hasParameters();
170 // Assume name ends in WS
171 String calcName = service.serviceType.substring(0,
172 service.serviceType.length() - 2);
174 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
175 annotservice.addActionListener(new ActionListener()
179 public void actionPerformed(ActionEvent e)
181 new SequenceAnnotationWSClient(service, alignFrame, null, false);
184 wsmenu.add(annotservice);
187 // only add these menu options if the service has user-modifiable
189 annotservice = new JMenuItem("Edit settings and run ...");
191 .setToolTipText("View and change parameters before running calculation");
193 annotservice.addActionListener(new ActionListener()
195 public void actionPerformed(ActionEvent e)
197 new SequenceAnnotationWSClient(service, alignFrame, null, true);
200 wsmenu.add(annotservice);
201 List<WsParamSetI> presets = service.getParamStore().getPresets();
202 if (presets != null && presets.size() > 0)
204 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
206 for (final WsParamSetI preset : presets)
208 final JMenuItem methodR = new JMenuItem(preset.getName());
209 methodR.setToolTipText("<html><p>"
210 + JvSwingUtils.wrapTooltip("<strong>"
211 + (preset.isModifiable() ? "User Preset"
212 : "Service Preset") + "</strong><br/>"
213 + preset.getDescription() + "</p>") + "</html>");
214 methodR.addActionListener(new ActionListener()
216 public void actionPerformed(ActionEvent e)
218 new SequenceAnnotationWSClient(service, alignFrame, preset,
223 presetlist.add(methodR);
225 wsmenu.add(presetlist);
231 annotservice = new JMenuItem("View documentation");
232 if (service.docUrl != null)
234 annotservice.addActionListener(new ActionListener()
238 public void actionPerformed(ActionEvent arg0)
240 Desktop.instance.showUrl(service.docUrl);
243 annotservice.setToolTipText("<html>"
244 + JvSwingUtils.wrapTooltip("View <a href=\""
245 + service.docUrl + "\">" + service.docUrl + "</a>")
247 wsmenu.add(annotservice);
253 private boolean registerAAConWSInstance(final JMenu wsmenu,
254 final Jws2Instance service, final AlignFrame alignFrame)
256 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
259 // not an instantaneous calculation GUI type service
262 // create the instaneous calculation GUI bits and update state if existing GUI elements already present
264 JCheckBoxMenuItem _aaConEnabled = null;
265 for (int i = 0; i < wsmenu.getItemCount(); i++)
267 JMenuItem item = wsmenu.getItem(i);
268 if (item instanceof JCheckBoxMenuItem
269 && item.getText().equals(aaui.getAAconToggle()))
271 _aaConEnabled = (JCheckBoxMenuItem) item;
274 // is there an aaCon worker already present - if so, set it to use the
275 // given service handle
277 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
279 .getRegisteredWorkersOfClass(aaui.getClient());
280 if (aaconClient != null && aaconClient.size() > 0)
282 JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient.get(0);
283 if (!worker.service.hosturl.equals(service.hosturl))
285 // javax.swing.SwingUtilities.invokeLater(new Runnable()
290 removeCurrentAAConWorkerFor(aaui, alignFrame);
291 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
298 // is there a service already registered ? there shouldn't be if we are
299 // being called correctly
300 if (_aaConEnabled == null)
302 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
303 aaui.getAAconToggle());
304 wsmenu.addMenuListener(new MenuListener()
308 public void menuSelected(MenuEvent arg0)
310 // TODO: refactor to the implementing class.
311 wsmenu.setEnabled((alignFrame.getViewport().getAlignment()
312 .isNucleotide() ? aaui.isNa() : aaui.isPr()));
313 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
315 .getRegisteredWorkersOfClass(aaui.getClient());
316 if (aaconClient != null && aaconClient.size() > 0)
318 aaConEnabled.setSelected(true);
322 aaConEnabled.setSelected(false);
327 public void menuDeselected(MenuEvent arg0)
329 // TODO Auto-generated method stub
334 public void menuCanceled(MenuEvent arg0)
336 // TODO Auto-generated method stub
340 aaConEnabled.setToolTipText("<html><p>"
341 + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "</p>")
343 aaConEnabled.addActionListener(new ActionListener()
346 public void actionPerformed(ActionEvent arg0)
348 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
350 .getRegisteredWorkersOfClass(aaui.getClient());
351 if (aaconClient != null && aaconClient.size() > 0)
353 removeCurrentAAConWorkerFor(aaui, alignFrame);
357 buildCurrentAAConWorkerFor(aaui, alignFrame);
363 wsmenu.add(aaConEnabled);
364 JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
365 modifyParams.setToolTipText("<html><p>"
366 + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "</p>")
368 modifyParams.addActionListener(new ActionListener()
372 public void actionPerformed(ActionEvent arg0)
374 showAAConAnnotationSettingsFor(aaui, alignFrame);
377 wsmenu.add(modifyParams);
383 private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
386 * preferred settings Whether AACon is automatically recalculated Which
387 * AACon server to use What parameters to use
389 // could actually do a class search for this too
390 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
391 .getCalcIdSettingsFor(aaui.getCalcId());
394 fave = createDefaultAAConSettings(aaui);
396 new SequenceAnnotationWSClient(fave, alignFrame, true);
400 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
402 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
405 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame,
406 Jws2Instance service)
409 * preferred settings Whether AACon is automatically recalculated Which
410 * AACon server to use What parameters to use
412 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
413 .getCalcIdSettingsFor(aaui.getCalcId());
416 fave = createDefaultAAConSettings(aaui, service);
421 && !fave.getService().hosturl.equals(service.hosturl))
423 Cache.log.debug("Changing AACon service to " + service.hosturl
424 + " from " + fave.getService().hosturl);
425 fave.setService(service);
428 new SequenceAnnotationWSClient(fave, alignFrame, false);
431 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui)
433 return createDefaultAAConSettings(aaui, null);
436 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui,
437 Jws2Instance service)
441 if (!service.serviceType.toString().equals(
442 compbio.ws.client.Services.AAConWS.toString()))
445 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
446 + service.serviceType + ")");
451 // check service is actually in the list of currently avaialable
453 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
462 // get the default service for AACon
463 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
464 aaui.getServiceType());
468 // TODO raise dialog box explaining error, and/or open the JABA
470 throw new Error("No AACon service found.");
472 return new AAConSettings(true, service, null, null);
475 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame)
477 alignFrame.getViewport().getCalcManager()
478 .removeRegisteredWorkersOfClass(aaui.getClient());