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());
305 aaConEnabled.setToolTipText("<html><p>"
306 + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "</p>")
308 aaConEnabled.addActionListener(new ActionListener()
311 public void actionPerformed(ActionEvent arg0)
313 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
315 .getRegisteredWorkersOfClass(aaui.getClient());
316 if (aaconClient != null && aaconClient.size() > 0)
318 removeCurrentAAConWorkerFor(aaui, alignFrame);
322 buildCurrentAAConWorkerFor(aaui, alignFrame);
328 wsmenu.add(aaConEnabled);
329 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
330 modifyParams.setToolTipText("<html><p>"
331 + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "</p>")
333 modifyParams.addActionListener(new ActionListener()
337 public void actionPerformed(ActionEvent arg0)
339 showAAConAnnotationSettingsFor(aaui, alignFrame);
342 wsmenu.add(modifyParams);
343 wsmenu.addMenuListener(new MenuListener()
347 public void menuSelected(MenuEvent arg0)
349 // TODO: refactor to the implementing class.
350 if (alignFrame.getViewport().getAlignment()
351 .isNucleotide() ? aaui.isNa() : aaui.isPr()) {
352 aaConEnabled.setEnabled(true);
353 modifyParams.setEnabled(true);
356 aaConEnabled.setEnabled(false);
357 modifyParams.setEnabled(false);
359 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
361 .getRegisteredWorkersOfClass(aaui.getClient());
362 if (aaconClient != null && aaconClient.size() > 0)
364 aaConEnabled.setSelected(true);
368 aaConEnabled.setSelected(false);
373 public void menuDeselected(MenuEvent arg0)
375 // TODO Auto-generated method stub
380 public void menuCanceled(MenuEvent arg0)
382 // TODO Auto-generated method stub
391 private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
394 * preferred settings Whether AACon is automatically recalculated Which
395 * AACon server to use What parameters to use
397 // could actually do a class search for this too
398 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
399 .getCalcIdSettingsFor(aaui.getCalcId());
402 fave = createDefaultAAConSettings(aaui);
404 new SequenceAnnotationWSClient(fave, alignFrame, true);
408 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
410 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
413 private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame,
414 Jws2Instance service)
417 * preferred settings Whether AACon is automatically recalculated Which
418 * AACon server to use What parameters to use
420 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
421 .getCalcIdSettingsFor(aaui.getCalcId());
424 fave = createDefaultAAConSettings(aaui, service);
429 && !fave.getService().hosturl.equals(service.hosturl))
431 Cache.log.debug("Changing AACon service to " + service.hosturl
432 + " from " + fave.getService().hosturl);
433 fave.setService(service);
436 new SequenceAnnotationWSClient(fave, alignFrame, false);
439 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui)
441 return createDefaultAAConSettings(aaui, null);
444 private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui,
445 Jws2Instance service)
449 if (!service.serviceType.toString().equals(
450 compbio.ws.client.Services.AAConWS.toString()))
453 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
454 + service.serviceType + ")");
459 // check service is actually in the list of currently avaialable
461 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
470 // get the default service for AACon
471 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
472 aaui.getServiceType());
476 // TODO raise dialog box explaining error, and/or open the JABA
478 throw new Error("No AACon service found.");
480 return new AAConSettings(true, service, null, null);
483 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame)
485 alignFrame.getViewport().getCalcManager()
486 .removeRegisteredWorkersOfClass(aaui.getClient());