2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws2;
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.AlignmentView;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.Desktop;
27 import jalview.gui.JvOptionPane;
28 import jalview.gui.JvSwingUtils;
29 import jalview.util.MessageManager;
30 import jalview.ws.jws2.jabaws2.Jws2Instance;
31 import jalview.ws.params.WsParamSetI;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.MouseAdapter;
36 import java.awt.event.MouseEvent;
37 import java.util.List;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuItem;
41 import javax.swing.ToolTipManager;
43 import compbio.data.msa.MsaWS;
44 import compbio.metadata.Argument;
52 public class MsaWSClient extends Jws2Client
55 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
59 public MsaWSClient(Jws2Instance sh, String altitle,
60 jalview.datamodel.AlignmentView msa, boolean submitGaps,
61 boolean preserveOrder, AlignmentI seqdataset,
62 AlignFrame _alignFrame)
64 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
65 seqdataset, _alignFrame);
66 // TODO Auto-generated constructor stub
69 public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
70 jalview.datamodel.AlignmentView msa, boolean submitGaps,
71 boolean preserveOrder, AlignmentI seqdataset,
72 AlignFrame _alignFrame)
74 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
75 seqdataset, _alignFrame);
76 // TODO Auto-generated constructor stub
80 * Creates a new MsaWSClient object that uses a service given by an externally
81 * retrieved ServiceHandle
84 * service handle of type AbstractName(MsaWS)
91 * @param preserveOrder
95 public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
96 List<Argument> arguments, boolean editParams, String altitle,
97 jalview.datamodel.AlignmentView msa, boolean submitGaps,
98 boolean preserveOrder, AlignmentI seqdataset,
99 AlignFrame _alignFrame)
101 super(_alignFrame, preset, arguments);
102 if (!processParams(sh, editParams))
107 if (!(sh.service instanceof MsaWS))
109 // redundant at mo - but may change
110 JvOptionPane.showMessageDialog(Desktop.desktop,
111 MessageManager.formatMessage(
112 "label.service_called_is_not_msa_service",
115 MessageManager.getString("label.internal_jalview_error"),
116 JvOptionPane.WARNING_MESSAGE);
120 server = (MsaWS) sh.service;
121 if ((wsInfo = setWebService(sh, false)) == null)
123 JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
124 .formatMessage("label.msa_service_is_unknown", new String[]
126 MessageManager.getString("label.internal_jalview_error"),
127 JvOptionPane.WARNING_MESSAGE);
132 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
139 // add a class reference to the list
142 private void startMsaWSClient(String altitle, AlignmentView msa,
143 boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
145 // if (!locateWebService())
150 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
151 + " of " + altitle + "\nJob details\n");
152 String jobtitle = WebServiceName.toLowerCase();
153 if (jobtitle.endsWith("alignment"))
155 if (submitGaps && (!jobtitle.endsWith("realignment")
156 || jobtitle.indexOf("profile") == -1))
158 int pos = jobtitle.indexOf("alignment");
159 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
164 jobtitle = WebServiceName + " of " + altitle;
169 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
170 + "alignment of " + altitle;
173 MsaWSThread msathread = new MsaWSThread(server, preset, paramset, WsURL,
174 wsInfo, alignFrame, WebServiceName, jobtitle, msa, submitGaps,
175 preserveOrder, seqdataset);
176 if (msathread.hasValidInput())
178 wsInfo.setthisService(msathread);
179 wsInfo.setVisible(true);
184 wsInfo.setVisible(false);
185 JvOptionPane.showMessageDialog(alignFrame,
186 MessageManager.getString("info.invalid_msa_input_mininfo"),
187 MessageManager.getString("info.invalid_msa_notenough"),
188 JvOptionPane.INFORMATION_MESSAGE);
192 public static void main(String[] args)
194 System.out.println("A".matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*"));
197 protected String getServiceActionKey()
202 protected String getServiceActionDescription()
204 return "Multiple Sequence Alignment";
208 * look at ourselves and work out if we are a service that can take a profile
211 * @return true if we can send gapped sequences to the alignment service
213 private boolean canSubmitGaps()
215 // TODO: query service or extract service handle props to check if we can
217 return (WebServiceName.indexOf("lustal") > -1); // cheat!
221 public void attachWSMenuEntry(JMenu rmsawsmenu,
222 final Jws2Instance service, final AlignFrame alignFrame)
224 if (registerAAConWSInstance(rmsawsmenu, service, alignFrame))
226 // Alignment dependent analysis calculation WS gui
229 setWebService(service, true); // headless
230 boolean finished = true, submitGaps = false;
231 JMenu msawsmenu = rmsawsmenu;
232 String svcname = WebServiceName;
233 if (svcname.endsWith("WS"))
235 svcname = svcname.substring(0, svcname.length() - 2);
237 String calcName = svcname + " ";
240 msawsmenu = new JMenu(svcname);
241 rmsawsmenu.add(msawsmenu);
244 boolean hasparams = service.hasParameters();
247 String action = "Align ";
248 if (submitGaps == true)
251 msawsmenu = new JMenu(MessageManager
252 .formatMessage("label.realign_with_params", new String[]
254 msawsmenu.setToolTipText(MessageManager
255 .getString("label.align_sequences_to_existing_alignment"));
256 rmsawsmenu.add(msawsmenu);
258 final boolean withGaps = submitGaps;
260 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
261 "label.calcname_with_default_settings", new String[]
263 method.setToolTipText(MessageManager.formatMessage(
264 "label.action_with_default_settings", new String[]
267 method.addActionListener(new ActionListener()
270 public void actionPerformed(ActionEvent e)
272 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
276 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
278 alignFrame.getViewport().getAlignment().getDataset(),
284 msawsmenu.add(method);
287 // only add these menu options if the service has user-modifiable
289 method = new JMenuItem(
290 MessageManager.getString("label.edit_settings_and_run"));
291 method.setToolTipText(MessageManager.getString(
292 "label.view_and_change_parameters_before_alignment"));
294 method.addActionListener(new ActionListener()
297 public void actionPerformed(ActionEvent e)
299 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
302 new MsaWSClient(service, null, null, true,
303 alignFrame.getTitle(), msa, withGaps, true,
304 alignFrame.getViewport().getAlignment().getDataset(),
310 msawsmenu.add(method);
311 List<WsParamSetI> presets = service.getParamStore().getPresets();
312 if (presets != null && presets.size() > 0)
314 JMenu presetlist = new JMenu(MessageManager.formatMessage(
315 "label.run_with_preset_params", new String[]
318 final int showToolTipFor = ToolTipManager.sharedInstance()
320 for (final WsParamSetI preset : presets)
322 final JMenuItem methodR = new JMenuItem(preset.getName());
323 final int QUICK_TOOLTIP = 1500;
324 // JAL-1582 shorten tooltip display time in these menu items as
325 // they can obscure other options
326 methodR.addMouseListener(new MouseAdapter()
329 public void mouseEntered(MouseEvent e)
331 ToolTipManager.sharedInstance()
332 .setDismissDelay(QUICK_TOOLTIP);
336 public void mouseExited(MouseEvent e)
338 ToolTipManager.sharedInstance()
339 .setDismissDelay(showToolTipFor);
343 String tooltip = JvSwingUtils.wrapTooltip(true, "<strong>"
344 + (preset.isModifiable()
345 ? MessageManager.getString("label.user_preset")
347 .getString("label.service_preset"))
348 + "</strong><br/>" + preset.getDescription());
349 methodR.setToolTipText(tooltip);
350 methodR.addActionListener(new ActionListener()
353 public void actionPerformed(ActionEvent e)
355 AlignmentView msa = alignFrame
356 .gatherSequencesForAlignment();
360 MsaWSClient msac = new MsaWSClient(service, preset,
361 alignFrame.getTitle(), msa, false, true,
362 alignFrame.getViewport().getAlignment()
370 presetlist.add(methodR);
372 msawsmenu.add(presetlist);
375 if (!submitGaps && canSubmitGaps())