4 package jalview.ws.jws2;
6 import jalview.api.AlignCalcWorkerI;
7 import jalview.bin.Cache;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.Desktop;
10 import jalview.gui.JvSwingUtils;
11 import jalview.ws.jws2.dm.AAConsSettings;
12 import jalview.ws.jws2.jabaws2.Jws2Instance;
13 import jalview.ws.params.WsParamSetI;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.util.List;
19 import javax.swing.JCheckBoxMenuItem;
20 import javax.swing.JMenu;
21 import javax.swing.JMenuItem;
22 import javax.swing.JOptionPane;
23 import javax.swing.event.MenuEvent;
24 import javax.swing.event.MenuListener;
30 public class SequenceAnnotationWSClient extends Jws2Client
33 public static final String AAConsCalcId = "jabaws2.AACons";
36 * initialise a client so its attachWSMenuEntry method can be called.
38 public SequenceAnnotationWSClient()
40 // TODO Auto-generated constructor stub
43 public SequenceAnnotationWSClient(final Jws2Instance sh,
44 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
46 super(alignFrame, preset, null);
47 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
50 public void initSequenceAnnotationWSClient(final Jws2Instance sh,
51 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
53 if (alignFrame.getViewport().getAlignment().isNucleotide())
55 JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
56 + " can only be used\nfor amino acid alignments.",
57 "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
61 if (sh.action.toLowerCase().contains("conservation"))
63 // Build an AACons style client - take alignment, return annotation for
66 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
68 .getRegisteredWorkersOfClass(AAConsClient.class);
69 if (clnts == null || clnts.size() == 0)
71 if (!processParams(sh, editParams))
80 worker = new AAConsClient(sh, alignFrame,
81 this.preset, paramset));
82 alignFrame.getViewport().getCalcManager().startWorker(worker);
87 AAConsClient worker = (AAConsClient) clnts.get(0);
90 paramset = worker.getArguments();
91 preset = worker.getPreset();
94 if (!processParams(sh, editParams, true))
98 // reinstate worker if it was blacklisted (might have happened due to
99 // invalid parameters)
100 alignFrame.getViewport().getCalcManager().workerMayRun(worker);
101 worker.updateParameters(this.preset, paramset);
105 if (sh.action.toLowerCase().contains("disorder"))
107 // build IUPred style client. take sequences, returns annotation per
109 if (!processParams(sh, editParams))
118 new AADisorderClient(sh, alignFrame, preset, paramset));
123 public SequenceAnnotationWSClient(AAConsSettings fave,
124 AlignFrame alignFrame, boolean b)
126 super(alignFrame, fave.getPreset(), fave.getJobArgset());
127 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
128 fave.getPreset(), b);
134 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
135 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
137 public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
138 final AlignFrame alignFrame)
140 if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
143 registerAAConsWSInstance(wsmenu, service, alignFrame);
146 boolean hasparams = service.hasParameters();
147 // Assume name ends in WS
148 String calcName = service.serviceType.substring(0,
149 service.serviceType.length() - 2);
151 JMenuItem aacons = new JMenuItem(calcName + " Defaults");
152 aacons.addActionListener(new ActionListener()
156 public void actionPerformed(ActionEvent e)
158 new SequenceAnnotationWSClient(service, alignFrame, null, false);
164 // only add these menu options if the service has user-modifiable
166 aacons = new JMenuItem("Edit settings and run ...");
167 aacons.setToolTipText("View and change parameters before running calculation");
169 aacons.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent e)
173 new SequenceAnnotationWSClient(service, alignFrame, null, true);
177 List<WsParamSetI> presets = service.getParamStore().getPresets();
178 if (presets != null && presets.size() > 0)
180 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
182 for (final WsParamSetI preset : presets)
184 final JMenuItem methodR = new JMenuItem(preset.getName());
185 methodR.setToolTipText("<html><p>"
186 + JvSwingUtils.wrapTooltip("<strong>"
187 + (preset.isModifiable() ? "User Preset"
188 : "Service Preset") + "</strong><br/>"
189 + preset.getDescription() + "</p>") + "</html>");
190 methodR.addActionListener(new ActionListener()
192 public void actionPerformed(ActionEvent e)
194 new SequenceAnnotationWSClient(service, alignFrame, preset,
199 presetlist.add(methodR);
201 wsmenu.add(presetlist);
205 aacons = new JMenuItem("View documentation");
206 if (service.docUrl!=null)
208 aacons.addActionListener(new ActionListener()
212 public void actionPerformed(ActionEvent arg0)
214 Desktop.instance.showUrl(service.docUrl);
217 aacons.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("View <a href=\""+service.docUrl+"\">"+service.docUrl+"</a>")+"</html>");
223 private final String AAconsToggle = "AACons Calculations",
224 AAconsToggleTooltip = "When checked, AACons calculations are updated automatically.",
225 AAeditSettings = "Change AACons Settings...",
226 AAeditSettingsTooltip = "Modify settings for AACons calculations.";
228 // private final enableAAConsCalculation(final AlignFrame alignFrame, )
229 private void registerAAConsWSInstance(final JMenu wsmenu,
230 final Jws2Instance service, final AlignFrame alignFrame)
232 // register this in the AACons settings set
233 JCheckBoxMenuItem _aaConsEnabled = null;
234 for (int i = 0; i < wsmenu.getItemCount(); i++)
236 JMenuItem item = wsmenu.getItem(i);
237 if (item instanceof JCheckBoxMenuItem
238 && item.getText().equals(AAconsToggle))
240 _aaConsEnabled = (JCheckBoxMenuItem) item;
243 // is there an aaCons worker already present - if so, set it to use the
244 // given service handle
246 List<AlignCalcWorkerI> aaconsClient = alignFrame.getViewport()
248 .getRegisteredWorkersOfClass(AAConsClient.class);
249 if (aaconsClient != null && aaconsClient.size() > 0)
251 AAConsClient worker = (AAConsClient) aaconsClient.get(0);
252 if (!worker.service.hosturl.equals(service.hosturl))
254 // javax.swing.SwingUtilities.invokeLater(new Runnable()
259 removeCurrentAAConsWorkerFor(alignFrame);
260 buildCurrentAAConsWorkerFor(alignFrame, service);
267 // is there a service already registered ? there shouldn't be if we are
268 // being called correctly
269 if (_aaConsEnabled == null)
271 final JCheckBoxMenuItem aaConsEnabled = new JCheckBoxMenuItem(
273 wsmenu.addMenuListener(new MenuListener()
277 public void menuSelected(MenuEvent arg0)
279 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
281 List<AlignCalcWorkerI> aaconsClient = alignFrame.getViewport()
283 .getRegisteredWorkersOfClass(AAConsClient.class);
284 if (aaconsClient != null && aaconsClient.size() > 0)
286 aaConsEnabled.setSelected(true);
290 aaConsEnabled.setSelected(false);
295 public void menuDeselected(MenuEvent arg0)
297 // TODO Auto-generated method stub
302 public void menuCanceled(MenuEvent arg0)
304 // TODO Auto-generated method stub
308 aaConsEnabled.setToolTipText("<html><p>"
309 + JvSwingUtils.wrapTooltip(AAconsToggleTooltip + "</p>")
311 aaConsEnabled.addActionListener(new ActionListener()
314 public void actionPerformed(ActionEvent arg0)
316 // aaConsEnabled.setSelected(!aaConsEnabled.isSelected());
317 List<AlignCalcWorkerI> aaconsClient = alignFrame.getViewport()
319 .getRegisteredWorkersOfClass(AAConsClient.class);
320 if (aaconsClient != null && aaconsClient.size() > 0)
322 removeCurrentAAConsWorkerFor(alignFrame);
326 buildCurrentAAConsWorkerFor(alignFrame);
332 wsmenu.add(aaConsEnabled);
333 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
334 modifyParams.setToolTipText("<html><p>"
335 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
337 modifyParams.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent arg0)
343 showAAConsAnnotationSettingsFor(alignFrame);
346 wsmenu.add(modifyParams);
351 private static void showAAConsAnnotationSettingsFor(AlignFrame alignFrame)
354 * preferred settings Whether AACons is automatically recalculated Which
355 * AACons server to use What parameters to use
357 // could actually do a class search for this too
358 AAConsSettings fave = (AAConsSettings) alignFrame.getViewport()
359 .getCalcIdSettingsFor(AAConsCalcId);
362 fave = createDefaultAAConsSettings();
364 new SequenceAnnotationWSClient(fave, alignFrame, true);
368 private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame)
370 buildCurrentAAConsWorkerFor(alignFrame, null);
373 private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame,
374 Jws2Instance service)
377 * preferred settings Whether AACons is automatically recalculated Which
378 * AACons server to use What parameters to use
380 AAConsSettings fave = (AAConsSettings) alignFrame.getViewport()
381 .getCalcIdSettingsFor(AAConsCalcId);
384 fave = createDefaultAAConsSettings(service);
389 && !fave.getService().hosturl.equals(service.hosturl))
391 Cache.log.debug("Changing AACons service to " + service.hosturl
392 + " from " + fave.getService().hosturl);
393 fave.setService(service);
396 new SequenceAnnotationWSClient(fave, alignFrame, false);
399 private static AAConsSettings createDefaultAAConsSettings()
401 return createDefaultAAConsSettings(null);
404 private static AAConsSettings createDefaultAAConsSettings(
405 Jws2Instance service)
409 if (!service.serviceType.toString().equals(
410 compbio.ws.client.Services.AAConWS.toString()))
413 .warn("Ignoring invalid preferred service for AACons calculations (service type was "
414 + service.serviceType + ")");
419 // check service is actually in the list of currently avaialable
421 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
430 // get the default service for AACons
431 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
432 compbio.ws.client.Services.AAConWS.toString());
434 * for (Jws2Instance sv : Jws2Discoverer.getDiscoverer().getServices()) {
435 * if (sv.serviceType.toString().equals(
436 * compbio.ws.client.Services.AAConWS.toString())) { service = sv; break;
442 // TODO raise dialog box explaining error, and/or open the JABA
444 throw new Error("No AACons service found.");
446 return new AAConsSettings(true, service, null, null);
449 private static void removeCurrentAAConsWorkerFor(AlignFrame alignFrame)
451 alignFrame.getViewport().getCalcManager()
452 .removeRegisteredWorkersOfClass(AAConsClient.class);
453 // AAConsClient.removeAAConsAnnotation(alignFrame.alignPanel);