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.AAConSettings;
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 AAConCalcId = "jabaws2.AACon";
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 AACon style client - take alignment, return annotation for
66 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
68 .getRegisteredWorkersOfClass(AAConClient.class);
69 if (clnts == null || clnts.size() == 0)
71 if (!processParams(sh, editParams))
80 worker = new AAConClient(sh, alignFrame,
81 this.preset, paramset));
82 alignFrame.getViewport().getCalcManager().startWorker(worker);
87 AAConClient worker = (AAConClient) 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(AAConSettings 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 registerAAConWSInstance(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 annotservice = new JMenuItem(calcName + " Defaults");
152 annotservice.addActionListener(new ActionListener()
156 public void actionPerformed(ActionEvent e)
158 new SequenceAnnotationWSClient(service, alignFrame, null, false);
161 wsmenu.add(annotservice);
164 // only add these menu options if the service has user-modifiable
166 annotservice = new JMenuItem("Edit settings and run ...");
168 .setToolTipText("View and change parameters before running calculation");
170 annotservice.addActionListener(new ActionListener()
172 public void actionPerformed(ActionEvent e)
174 new SequenceAnnotationWSClient(service, alignFrame, null, true);
177 wsmenu.add(annotservice);
178 List<WsParamSetI> presets = service.getParamStore().getPresets();
179 if (presets != null && presets.size() > 0)
181 JMenu presetlist = new JMenu("Run " + calcName + "with preset");
183 for (final WsParamSetI preset : presets)
185 final JMenuItem methodR = new JMenuItem(preset.getName());
186 methodR.setToolTipText("<html><p>"
187 + JvSwingUtils.wrapTooltip("<strong>"
188 + (preset.isModifiable() ? "User Preset"
189 : "Service Preset") + "</strong><br/>"
190 + preset.getDescription() + "</p>") + "</html>");
191 methodR.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 new SequenceAnnotationWSClient(service, alignFrame, preset,
200 presetlist.add(methodR);
202 wsmenu.add(presetlist);
208 annotservice = new JMenuItem("View documentation");
209 if (service.docUrl != null)
211 annotservice.addActionListener(new ActionListener()
215 public void actionPerformed(ActionEvent arg0)
217 Desktop.instance.showUrl(service.docUrl);
220 annotservice.setToolTipText("<html>"
221 + JvSwingUtils.wrapTooltip("View <a href=\""
222 + service.docUrl + "\">" + service.docUrl + "</a>")
224 wsmenu.add(annotservice);
229 private final String AAconToggle = "AACon Calculations",
230 AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
231 AAeditSettings = "Change AACon Settings...",
232 AAeditSettingsTooltip = "Modify settings for AACon calculations.";
234 private void registerAAConWSInstance(final JMenu wsmenu,
235 final Jws2Instance service, final AlignFrame alignFrame)
237 // register this in the AACon settings set
238 JCheckBoxMenuItem _aaConEnabled = null;
239 for (int i = 0; i < wsmenu.getItemCount(); i++)
241 JMenuItem item = wsmenu.getItem(i);
242 if (item instanceof JCheckBoxMenuItem
243 && item.getText().equals(AAconToggle))
245 _aaConEnabled = (JCheckBoxMenuItem) item;
248 // is there an aaCon worker already present - if so, set it to use the
249 // given service handle
251 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
253 .getRegisteredWorkersOfClass(AAConClient.class);
254 if (aaconClient != null && aaconClient.size() > 0)
256 AAConClient worker = (AAConClient) aaconClient.get(0);
257 if (!worker.service.hosturl.equals(service.hosturl))
259 // javax.swing.SwingUtilities.invokeLater(new Runnable()
264 removeCurrentAAConWorkerFor(alignFrame);
265 buildCurrentAAConWorkerFor(alignFrame, service);
272 // is there a service already registered ? there shouldn't be if we are
273 // being called correctly
274 if (_aaConEnabled == null)
276 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
278 wsmenu.addMenuListener(new MenuListener()
282 public void menuSelected(MenuEvent arg0)
284 wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
286 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
288 .getRegisteredWorkersOfClass(AAConClient.class);
289 if (aaconClient != null && aaconClient.size() > 0)
291 aaConEnabled.setSelected(true);
295 aaConEnabled.setSelected(false);
300 public void menuDeselected(MenuEvent arg0)
302 // TODO Auto-generated method stub
307 public void menuCanceled(MenuEvent arg0)
309 // TODO Auto-generated method stub
313 aaConEnabled.setToolTipText("<html><p>"
314 + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "</p>")
316 aaConEnabled.addActionListener(new ActionListener()
319 public void actionPerformed(ActionEvent arg0)
321 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
323 .getRegisteredWorkersOfClass(AAConClient.class);
324 if (aaconClient != null && aaconClient.size() > 0)
326 removeCurrentAAConWorkerFor(alignFrame);
330 buildCurrentAAConWorkerFor(alignFrame);
336 wsmenu.add(aaConEnabled);
337 JMenuItem modifyParams = new JMenuItem(AAeditSettings);
338 modifyParams.setToolTipText("<html><p>"
339 + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
341 modifyParams.addActionListener(new ActionListener()
345 public void actionPerformed(ActionEvent arg0)
347 showAAConAnnotationSettingsFor(alignFrame);
350 wsmenu.add(modifyParams);
355 private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
358 * preferred settings Whether AACon is automatically recalculated Which
359 * AACon server to use What parameters to use
361 // could actually do a class search for this too
362 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
363 .getCalcIdSettingsFor(AAConCalcId);
366 fave = createDefaultAAConSettings();
368 new SequenceAnnotationWSClient(fave, alignFrame, true);
372 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
374 buildCurrentAAConWorkerFor(alignFrame, null);
377 private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
378 Jws2Instance service)
381 * preferred settings Whether AACon is automatically recalculated Which
382 * AACon server to use What parameters to use
384 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
385 .getCalcIdSettingsFor(AAConCalcId);
388 fave = createDefaultAAConSettings(service);
393 && !fave.getService().hosturl.equals(service.hosturl))
395 Cache.log.debug("Changing AACon service to " + service.hosturl
396 + " from " + fave.getService().hosturl);
397 fave.setService(service);
400 new SequenceAnnotationWSClient(fave, alignFrame, false);
403 private static AAConSettings createDefaultAAConSettings()
405 return createDefaultAAConSettings(null);
408 private static AAConSettings createDefaultAAConSettings(
409 Jws2Instance service)
413 if (!service.serviceType.toString().equals(
414 compbio.ws.client.Services.AAConWS.toString()))
417 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
418 + service.serviceType + ")");
423 // check service is actually in the list of currently avaialable
425 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
434 // get the default service for AACon
435 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
436 compbio.ws.client.Services.AAConWS.toString());
440 // TODO raise dialog box explaining error, and/or open the JABA
442 throw new Error("No AACon service found.");
444 return new AAConSettings(true, service, null, null);
447 private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
449 alignFrame.getViewport().getCalcManager()
450 .removeRegisteredWorkersOfClass(AAConClient.class);