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;
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 public static final String AAConCalcId = "jabaws2.AACon";
51 * initialise a client so its attachWSMenuEntry method can be called.
53 public SequenceAnnotationWSClient()
55 // TODO Auto-generated constructor stub
58 public SequenceAnnotationWSClient(final Jws2Instance sh,
59 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
61 super(alignFrame, preset, null);
62 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
65 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
66 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
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 if (sh.action.toLowerCase().contains("conservation"))
78 // Build an AACon style client - take alignment, return annotation for
81 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
83 .getRegisteredWorkersOfClass(AAConClient.class);
84 if (clnts == null || clnts.size() == 0)
86 if (!processParams(sh, editParams))
95 worker = new AAConClient(sh, alignFrame,
96 this.preset, paramset));
97 alignFrame.getViewport().getCalcManager().startWorker(worker);
102 AAConClient worker = (AAConClient) clnts.get(0);
105 paramset = worker.getArguments();
106 preset = worker.getPreset();
109 if (!processParams(sh, editParams, true))
113 // reinstate worker if it was blacklisted (might have happened due to
114 // invalid parameters)
115 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
116 worker.updateParameters(this.preset, paramset);
120 if (sh.action.toLowerCase().contains("disorder"))
122 // build IUPred style client. take sequences, returns annotation per
124 if (!processParams(sh, editParams))
133 new AADisorderClient(sh, alignFrame, preset, paramset));
138 public SequenceAnnotationWSClient(AAConSettings fave,
139 AlignFrame alignFrame, boolean b)
141 super(alignFrame, fave.getPreset(), fave.getJobArgset());
142 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
143 fave.getPreset(), b);
149 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
150 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
152 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
153 final AlignFrame alignFrame)
155 if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
158 registerAAConWSInstance(wsmenu, service, alignFrame);
161 boolean hasparams = service.hasParameters();
162 // Assume name ends in WS
163 String calcName = service.serviceType.substring(0,
164 service.serviceType.length() - 2);
166 JMenuItem annotservice = new JMenuItem(calcName + " Defaults");
167 annotservice.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent e)
173 new SequenceAnnotationWSClient(service, alignFrame, null, false);
176 wsmenu.add(annotservice);
179 // only add these menu options if the service has user-modifiable
181 annotservice = new JMenuItem("Edit settings and run ...");
183 .setToolTipText("View and change parameters before running calculation");
185 annotservice.addActionListener(new ActionListener()
187 public void actionPerformed(ActionEvent e)
189 new SequenceAnnotationWSClient(service, alignFrame, null, true);
192 wsmenu.add(annotservice);
193 List<WsParamSetI> presets = service.getParamStore().getPresets();
194 if (presets != null && presets.size() > 0)
196 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
198 for (final WsParamSetI preset : presets)
200 final JMenuItem methodR = new JMenuItem(preset.getName());
201 methodR.setToolTipText("<html><p>"
202 + JvSwingUtils.wrapTooltip("<strong>"
203 + (preset.isModifiable() ? "User Preset"
204 : "Service Preset") + "</strong><br/>"
205 + preset.getDescription() + "</p>") + "</html>");
206 methodR.addActionListener(new ActionListener()
208 public void actionPerformed(ActionEvent e)
210 new SequenceAnnotationWSClient(service, alignFrame, preset,
215 presetlist.add(methodR);
217 wsmenu.add(presetlist);
223 annotservice = new JMenuItem("View documentation");
224 if (service.docUrl != null)
226 annotservice.addActionListener(new ActionListener()
230 public void actionPerformed(ActionEvent arg0)
232 Desktop.instance.showUrl(service.docUrl);
235 annotservice.setToolTipText("<html>"
236 + JvSwingUtils.wrapTooltip("View <a href=\""
237 + service.docUrl + "\">" + service.docUrl + "</a>")
239 wsmenu.add(annotservice);
244 private final String AAconToggle = "AACon Calculations",
245 AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
246 AAeditSettings = "Change AACon Settings...",
247 AAeditSettingsTooltip = "Modify settings for AACon calculations.";
249 private void registerAAConWSInstance(final JMenu wsmenu,
250 final Jws2Instance service, final AlignFrame alignFrame)
252 // register this in the AACon settings set
253 JCheckBoxMenuItem _aaConEnabled = null;
254 for (int i = 0; i < wsmenu.getItemCount(); i++)
256 JMenuItem item = wsmenu.getItem(i);
257 if (item instanceof JCheckBoxMenuItem
258 && item.getText().equals(AAconToggle))
260 _aaConEnabled = (JCheckBoxMenuItem) item;
263 // is there an aaCon worker already present - if so, set it to use the
264 // given service handle
266 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
268 .getRegisteredWorkersOfClass(AAConClient.class);
269 if (aaconClient != null && aaconClient.size() > 0)
271 AAConClient worker = (AAConClient) aaconClient.get(0);
272 if (!worker.service.hosturl.equals(service.hosturl))
274 // javax.swing.SwingUtilities.invokeLater(new Runnable()
279 removeCurrentAAConWorkerFor(alignFrame);
280 buildCurrentAAConWorkerFor(alignFrame, service);
287 // is there a service already registered ? there shouldn't be if we are
288 // being called correctly
289 if (_aaConEnabled == null)
291 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
293 wsmenu.addMenuListener(new MenuListener()
297 public void menuSelected(MenuEvent arg0)
299 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
301 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
303 .getRegisteredWorkersOfClass(AAConClient.class);
304 if (aaconClient != null && aaconClient.size() > 0)
306 aaConEnabled.setSelected(true);
310 aaConEnabled.setSelected(false);
315 public void menuDeselected(MenuEvent arg0)
317 // TODO Auto-generated method stub
322 public void menuCanceled(MenuEvent arg0)
324 // TODO Auto-generated method stub
328 aaConEnabled.setToolTipText("<html><p>"
329 + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "</p>")
331 aaConEnabled.addActionListener(new ActionListener()
334 public void actionPerformed(ActionEvent arg0)
336 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
338 .getRegisteredWorkersOfClass(AAConClient.class);
339 if (aaconClient != null && aaconClient.size() > 0)
341 removeCurrentAAConWorkerFor(alignFrame);
345 buildCurrentAAConWorkerFor(alignFrame);
351 wsmenu.add(aaConEnabled);
352 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
353 modifyParams.setToolTipText("<html><p>"
354 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
356 modifyParams.addActionListener(new ActionListener()
360 public void actionPerformed(ActionEvent arg0)
362 showAAConAnnotationSettingsFor(alignFrame);
365 wsmenu.add(modifyParams);
370 private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
373 * preferred settings Whether AACon is automatically recalculated Which
374 * AACon server to use What parameters to use
376 // could actually do a class search for this too
377 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
378 .getCalcIdSettingsFor(AAConCalcId);
381 fave = createDefaultAAConSettings();
383 new SequenceAnnotationWSClient(fave, alignFrame, true);
387 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
389 buildCurrentAAConWorkerFor(alignFrame, null);
392 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
393 Jws2Instance service)
396 * preferred settings Whether AACon is automatically recalculated Which
397 * AACon server to use What parameters to use
399 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
400 .getCalcIdSettingsFor(AAConCalcId);
403 fave = createDefaultAAConSettings(service);
408 && !fave.getService().hosturl.equals(service.hosturl))
410 Cache.log.debug("Changing AACon service to " + service.hosturl
411 + " from " + fave.getService().hosturl);
412 fave.setService(service);
415 new SequenceAnnotationWSClient(fave, alignFrame, false);
418 private static AAConSettings createDefaultAAConSettings()
420 return createDefaultAAConSettings(null);
423 private static AAConSettings createDefaultAAConSettings(
424 Jws2Instance service)
428 if (!service.serviceType.toString().equals(
429 compbio.ws.client.Services.AAConWS.toString()))
432 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
433 + service.serviceType + ")");
438 // check service is actually in the list of currently avaialable
440 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
449 // get the default service for AACon
450 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
451 compbio.ws.client.Services.AAConWS.toString());
455 // TODO raise dialog box explaining error, and/or open the JABA
457 throw new Error("No AACon service found.");
459 return new AAConSettings(true, service, null, null);
462 private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
464 alignFrame.getViewport().getCalcManager()
465 .removeRegisteredWorkersOfClass(AAConClient.class);