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 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
65 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
67 if (alignFrame.getViewport().getAlignment().isNucleotide())
69 JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
70 + " can only be used\nfor amino acid alignments.",
71 "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
75 if (sh.action.toLowerCase().contains("conservation"))
77 // Build an AACon style client - take alignment, return annotation for
80 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
82 .getRegisteredWorkersOfClass(AAConClient.class);
83 if (clnts == null || clnts.size() == 0)
85 if (!processParams(sh, editParams))
94 worker = new AAConClient(sh, alignFrame,
95 this.preset, paramset));
96 alignFrame.getViewport().getCalcManager().startWorker(worker);
101 AAConClient worker = (AAConClient) clnts.get(0);
104 paramset = worker.getArguments();
105 preset = worker.getPreset();
108 if (!processParams(sh, editParams, true))
112 // reinstate worker if it was blacklisted (might have happened due to
113 // invalid parameters)
114 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
115 worker.updateParameters(this.preset, paramset);
119 if (sh.action.toLowerCase().contains("disorder"))
121 // build IUPred style client. take sequences, returns annotation per
123 if (!processParams(sh, editParams))
132 new AADisorderClient(sh, alignFrame, preset, paramset));
137 public SequenceAnnotationWSClient(AAConSettings fave,
138 AlignFrame alignFrame, boolean b)
140 super(alignFrame, fave.getPreset(), fave.getJobArgset());
141 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
142 fave.getPreset(), b);
148 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
149 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
151 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
152 final AlignFrame alignFrame)
154 if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
157 registerAAConWSInstance(wsmenu, service, alignFrame);
160 boolean hasparams = service.hasParameters();
161 // Assume name ends in WS
162 String calcName = service.serviceType.substring(0,
163 service.serviceType.length() - 2);
165 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
166 annotservice.addActionListener(new ActionListener()
170 public void actionPerformed(ActionEvent e)
172 new SequenceAnnotationWSClient(service, alignFrame, null, false);
175 wsmenu.add(annotservice);
178 // only add these menu options if the service has user-modifiable
180 annotservice = new JMenuItem("Edit settings and run ...");
182 .setToolTipText("View and change parameters before running calculation");
184 annotservice.addActionListener(new ActionListener()
186 public void actionPerformed(ActionEvent e)
188 new SequenceAnnotationWSClient(service, alignFrame, null, true);
191 wsmenu.add(annotservice);
192 List<WsParamSetI> presets = service.getParamStore().getPresets();
193 if (presets != null && presets.size() > 0)
195 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
197 for (final WsParamSetI preset : presets)
199 final JMenuItem methodR = new JMenuItem(preset.getName());
200 methodR.setToolTipText("<html><p>"
201 + JvSwingUtils.wrapTooltip("<strong>"
202 + (preset.isModifiable() ? "User Preset"
203 : "Service Preset") + "</strong><br/>"
204 + preset.getDescription() + "</p>") + "</html>");
205 methodR.addActionListener(new ActionListener()
207 public void actionPerformed(ActionEvent e)
209 new SequenceAnnotationWSClient(service, alignFrame, preset,
214 presetlist.add(methodR);
216 wsmenu.add(presetlist);
222 annotservice = new JMenuItem("View documentation");
223 if (service.docUrl != null)
225 annotservice.addActionListener(new ActionListener()
229 public void actionPerformed(ActionEvent arg0)
231 Desktop.instance.showUrl(service.docUrl);
234 annotservice.setToolTipText("<html>"
235 + JvSwingUtils.wrapTooltip("View <a href=\""
236 + service.docUrl + "\">" + service.docUrl + "</a>")
238 wsmenu.add(annotservice);
243 private final String AAconToggle = "AACon Calculations",
244 AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
245 AAeditSettings = "Change AACon Settings...",
246 AAeditSettingsTooltip = "Modify settings for AACon calculations.";
248 private void registerAAConWSInstance(final JMenu wsmenu,
249 final Jws2Instance service, final AlignFrame alignFrame)
251 // register this in the AACon settings set
252 JCheckBoxMenuItem _aaConEnabled = null;
253 for (int i = 0; i < wsmenu.getItemCount(); i++)
255 JMenuItem item = wsmenu.getItem(i);
256 if (item instanceof JCheckBoxMenuItem
257 && item.getText().equals(AAconToggle))
259 _aaConEnabled = (JCheckBoxMenuItem) item;
262 // is there an aaCon worker already present - if so, set it to use the
263 // given service handle
265 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
267 .getRegisteredWorkersOfClass(AAConClient.class);
268 if (aaconClient != null && aaconClient.size() > 0)
270 AAConClient worker = (AAConClient) aaconClient.get(0);
271 if (!worker.service.hosturl.equals(service.hosturl))
273 // javax.swing.SwingUtilities.invokeLater(new Runnable()
278 removeCurrentAAConWorkerFor(alignFrame);
279 buildCurrentAAConWorkerFor(alignFrame, service);
286 // is there a service already registered ? there shouldn't be if we are
287 // being called correctly
288 if (_aaConEnabled == null)
290 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
292 wsmenu.addMenuListener(new MenuListener()
296 public void menuSelected(MenuEvent arg0)
298 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
300 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
302 .getRegisteredWorkersOfClass(AAConClient.class);
303 if (aaconClient != null && aaconClient.size() > 0)
305 aaConEnabled.setSelected(true);
309 aaConEnabled.setSelected(false);
314 public void menuDeselected(MenuEvent arg0)
316 // TODO Auto-generated method stub
321 public void menuCanceled(MenuEvent arg0)
323 // TODO Auto-generated method stub
327 aaConEnabled.setToolTipText("<html><p>"
328 + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "</p>")
330 aaConEnabled.addActionListener(new ActionListener()
333 public void actionPerformed(ActionEvent arg0)
335 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
337 .getRegisteredWorkersOfClass(AAConClient.class);
338 if (aaconClient != null && aaconClient.size() > 0)
340 removeCurrentAAConWorkerFor(alignFrame);
344 buildCurrentAAConWorkerFor(alignFrame);
350 wsmenu.add(aaConEnabled);
351 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
352 modifyParams.setToolTipText("<html><p>"
353 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
355 modifyParams.addActionListener(new ActionListener()
359 public void actionPerformed(ActionEvent arg0)
361 showAAConAnnotationSettingsFor(alignFrame);
364 wsmenu.add(modifyParams);
369 private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
372 * preferred settings Whether AACon is automatically recalculated Which
373 * AACon server to use What parameters to use
375 // could actually do a class search for this too
376 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
377 .getCalcIdSettingsFor(AAConCalcId);
380 fave = createDefaultAAConSettings();
382 new SequenceAnnotationWSClient(fave, alignFrame, true);
386 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
388 buildCurrentAAConWorkerFor(alignFrame, null);
391 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
392 Jws2Instance service)
395 * preferred settings Whether AACon is automatically recalculated Which
396 * AACon server to use What parameters to use
398 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
399 .getCalcIdSettingsFor(AAConCalcId);
402 fave = createDefaultAAConSettings(service);
407 && !fave.getService().hosturl.equals(service.hosturl))
409 Cache.log.debug("Changing AACon service to " + service.hosturl
410 + " from " + fave.getService().hosturl);
411 fave.setService(service);
414 new SequenceAnnotationWSClient(fave, alignFrame, false);
417 private static AAConSettings createDefaultAAConSettings()
419 return createDefaultAAConSettings(null);
422 private static AAConSettings createDefaultAAConSettings(
423 Jws2Instance service)
427 if (!service.serviceType.toString().equals(
428 compbio.ws.client.Services.AAConWS.toString()))
431 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
432 + service.serviceType + ")");
437 // check service is actually in the list of currently avaialable
439 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
448 // get the default service for AACon
449 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
450 compbio.ws.client.Services.AAConWS.toString());
454 // TODO raise dialog box explaining error, and/or open the JABA
456 throw new Error("No AACon service found.");
458 return new AAConSettings(true, service, null, null);
461 private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
463 alignFrame.getViewport().getCalcManager()
464 .removeRegisteredWorkersOfClass(AAConClient.class);