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.Alignment;
24 import jalview.datamodel.AlignmentView;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.Desktop;
27 import jalview.gui.JvSwingUtils;
28 import jalview.util.MessageManager;
29 import jalview.ws.jws2.jabaws2.Jws2Instance;
30 import jalview.ws.params.WsParamSetI;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.MouseAdapter;
35 import java.awt.event.MouseEvent;
36 import java.util.List;
38 import javax.swing.JMenu;
39 import javax.swing.JMenuItem;
40 import javax.swing.JOptionPane;
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, Alignment 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, Alignment 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, Alignment 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 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
111 .formatMessage("label.service_called_is_not_msa_service",
112 new String[] { sh.serviceType }), MessageManager
113 .getString("label.internal_jalview_error"),
114 JOptionPane.WARNING_MESSAGE);
118 server = (MsaWS) sh.service;
119 if ((wsInfo = setWebService(sh, false)) == null)
121 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
122 .formatMessage("label.msa_service_is_unknown",
123 new String[] { sh.serviceType }), MessageManager
124 .getString("label.internal_jalview_error"),
125 JOptionPane.WARNING_MESSAGE);
130 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
137 // add a class reference to the list
140 private void startMsaWSClient(String altitle, AlignmentView msa,
141 boolean submitGaps, boolean preserveOrder, Alignment seqdataset)
143 // if (!locateWebService())
148 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
149 + " of " + altitle + "\nJob details\n");
150 String jobtitle = WebServiceName.toLowerCase();
151 if (jobtitle.endsWith("alignment"))
154 && (!jobtitle.endsWith("realignment") || jobtitle
155 .indexOf("profile") == -1))
157 int pos = jobtitle.indexOf("alignment");
158 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
163 jobtitle = WebServiceName + " of " + altitle;
168 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
169 + "alignment of " + altitle;
172 MsaWSThread msathread = new MsaWSThread(server, preset, paramset,
173 WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa,
174 submitGaps, preserveOrder, seqdataset);
175 if (msathread.hasValidInput())
177 wsInfo.setthisService(msathread);
178 wsInfo.setVisible(true);
183 JOptionPane.showMessageDialog(alignFrame,
184 MessageManager.getString("info.invalid_msa_input_mininfo"),
185 MessageManager.getString("info.invalid_msa_notenough"),
186 JOptionPane.INFORMATION_MESSAGE);
187 wsInfo.setVisible(false);
191 public static void main(String[] args)
193 System.out.println("A".matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*"));
196 protected String getServiceActionKey()
201 protected String getServiceActionDescription()
203 return "Multiple Sequence Alignment";
207 * look at ourselves and work out if we are a service that can take a profile
210 * @return true if we can send gapped sequences to the alignment service
212 private boolean canSubmitGaps()
214 // TODO: query service or extract service handle props to check if we can
216 return (WebServiceName.indexOf("lustal") > -1); // cheat!
219 public void attachWSMenuEntry(JMenu rmsawsmenu,
220 final Jws2Instance service, final AlignFrame alignFrame)
222 if (registerAAConWSInstance(rmsawsmenu, service, alignFrame))
224 // Alignment dependent analysis calculation WS gui
227 setWebService(service, true); // headless
228 boolean finished = true, submitGaps = false;
229 JMenu msawsmenu = rmsawsmenu;
230 String svcname = WebServiceName;
231 if (svcname.endsWith("WS"))
233 svcname = svcname.substring(0, svcname.length() - 2);
235 String calcName = svcname + " ";
238 msawsmenu = new JMenu(svcname);
239 rmsawsmenu.add(msawsmenu);
242 boolean hasparams = service.hasParameters();
245 String action = "Align ";
246 if (submitGaps == true)
249 msawsmenu = new JMenu(MessageManager.formatMessage(
250 "label.realign_with_params", new String[] { svcname }));
251 msawsmenu.setToolTipText(MessageManager
252 .getString("label.align_sequences_to_existing_alignment"));
253 rmsawsmenu.add(msawsmenu);
255 final boolean withGaps = submitGaps;
257 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
258 "label.calcname_with_default_settings",
259 new String[] { calcName }));
260 method.setToolTipText(MessageManager
261 .formatMessage("label.action_with_default_settings",
262 new String[] { action }));
264 method.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
272 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
273 true, alignFrame.getViewport().getAlignment()
274 .getDataset(), alignFrame);
279 msawsmenu.add(method);
282 // only add these menu options if the service has user-modifiable
284 method = new JMenuItem(
285 MessageManager.getString("label.edit_settings_and_run"));
286 method.setToolTipText(MessageManager
287 .getString("label.view_and_change_parameters_before_alignment"));
289 method.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
296 new MsaWSClient(service, null, null, true, alignFrame
297 .getTitle(), msa, withGaps, true, alignFrame
298 .getViewport().getAlignment().getDataset(),
304 msawsmenu.add(method);
305 List<WsParamSetI> presets = service.getParamStore().getPresets();
306 if (presets != null && presets.size() > 0)
308 JMenu presetlist = new JMenu(
309 MessageManager.formatMessage(
310 "label.run_with_preset_params",
311 new String[] { calcName }));
313 final int showToolTipFor = ToolTipManager.sharedInstance()
315 for (final WsParamSetI preset : presets)
317 final JMenuItem methodR = new JMenuItem(preset.getName());
318 final int QUICK_TOOLTIP = 1500;
319 // JAL-1582 shorten tooltip display time in these menu items as
320 // they can obscure other options
321 methodR.addMouseListener(new MouseAdapter()
324 public void mouseEntered(MouseEvent e)
326 ToolTipManager.sharedInstance().setDismissDelay(
331 public void mouseExited(MouseEvent e)
333 ToolTipManager.sharedInstance().setDismissDelay(
338 methodR.setToolTipText(JvSwingUtils.wrapTooltip(
341 + (preset.isModifiable() ? MessageManager
342 .getString("label.user_preset")
344 .getString("label.service_preset"))
345 + "</strong><br/>" + preset.getDescription()
347 methodR.addActionListener(new ActionListener()
349 public void actionPerformed(ActionEvent e)
351 AlignmentView msa = alignFrame
352 .gatherSequencesForAlignment();
356 MsaWSClient msac = new MsaWSClient(service, preset,
357 alignFrame.getTitle(), msa, false, true,
358 alignFrame.getViewport().getAlignment()
359 .getDataset(), alignFrame);
365 presetlist.add(methodR);
367 msawsmenu.add(presetlist);
370 if (!submitGaps && canSubmitGaps())