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,
62 boolean preserveOrder, Alignment seqdataset,
63 AlignFrame _alignFrame)
65 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
66 seqdataset, _alignFrame);
67 // TODO Auto-generated constructor stub
70 public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
71 AlignmentView msa, boolean submitGaps,
72 boolean preserveOrder, Alignment seqdataset,
73 AlignFrame _alignFrame)
75 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
76 seqdataset, _alignFrame);
77 // TODO Auto-generated constructor stub
81 * Creates a new MsaWSClient object that uses a service given by an externally
82 * retrieved ServiceHandle
85 * service handle of type AbstractName(MsaWS)
92 * @param preserveOrder
96 public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
97 List<Argument> arguments, boolean editParams, String altitle,
98 AlignmentView msa, boolean submitGaps,
99 boolean preserveOrder, Alignment seqdataset,
100 AlignFrame _alignFrame)
102 super(_alignFrame, preset, arguments);
103 if (!processParams(sh, editParams))
108 if (!(sh.service instanceof MsaWS))
110 // redundant at mo - but may change
111 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
112 .formatMessage("label.service_called_is_not_msa_service",
114 { sh.serviceType }), MessageManager
115 .getString("label.internal_jalview_error"),
116 JOptionPane.WARNING_MESSAGE);
120 server = (MsaWS) sh.service;
121 if ((wsInfo = setWebService(sh, false)) == null)
123 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
124 .formatMessage("label.msa_service_is_unknown", new String[]
125 { sh.serviceType }), MessageManager
126 .getString("label.internal_jalview_error"),
127 JOptionPane.WARNING_MESSAGE);
132 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
140 // add a class reference to the list
143 private void startMsaWSClient(String altitle, AlignmentView msa,
144 boolean submitGaps, boolean preserveOrder, Alignment seqdataset)
146 // if (!locateWebService())
151 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
152 + " of " + altitle + "\nJob details\n");
153 String jobtitle = WebServiceName.toLowerCase();
154 if (jobtitle.endsWith("alignment"))
157 && (!jobtitle.endsWith("realignment") || jobtitle
158 .indexOf("profile") == -1))
160 int pos = jobtitle.indexOf("alignment");
161 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
166 jobtitle = WebServiceName + " of " + altitle;
171 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
172 + "alignment of " + altitle;
175 MsaWSThread msathread = new MsaWSThread(server, preset, paramset,
176 WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa,
177 submitGaps, preserveOrder, seqdataset);
178 if (msathread.hasValidInput())
180 wsInfo.setthisService(msathread);
181 wsInfo.setVisible(true);
186 JOptionPane.showMessageDialog(alignFrame,
187 MessageManager.getString("info.invalid_msa_input_mininfo"),
188 MessageManager.getString("info.invalid_msa_notenough"),
189 JOptionPane.INFORMATION_MESSAGE);
190 wsInfo.setVisible(false);
194 public static void main(String[] args)
196 System.out.println("A".matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*"));
201 protected String getServiceActionKey()
206 protected String getServiceActionDescription()
208 return "Multiple Sequence Alignment";
212 * look at ourselves and work out if we are a service that can take a profile
215 * @return true if we can send gapped sequences to the alignment service
217 private boolean canSubmitGaps()
219 // TODO: query service or extract service handle props to check if we can
221 return (WebServiceName.indexOf("lustal") > -1); // cheat!
224 public void attachWSMenuEntry(JMenu rmsawsmenu,
225 final Jws2Instance service, final AlignFrame alignFrame)
227 if (registerAAConWSInstance(rmsawsmenu, service, alignFrame))
229 // Alignment dependent analysis calculation WS gui
232 setWebService(service, true); // headless
233 boolean finished = true, submitGaps = false;
234 JMenu msawsmenu = rmsawsmenu;
235 String svcname = WebServiceName;
236 if (svcname.endsWith("WS"))
238 svcname = svcname.substring(0, svcname.length() - 2);
240 String calcName = svcname + " ";
243 msawsmenu = new JMenu(svcname);
244 rmsawsmenu.add(msawsmenu);
247 boolean hasparams = service.hasParameters();
250 String action = "Align ";
251 if (submitGaps == true)
254 msawsmenu = new JMenu(MessageManager.formatMessage(
255 "label.realign_with_params", new String[]
257 msawsmenu.setToolTipText(MessageManager
258 .getString("label.align_sequences_to_existing_alignment"));
259 rmsawsmenu.add(msawsmenu);
261 final boolean withGaps = submitGaps;
263 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
264 "label.calcname_with_default_settings", new String[]
266 method.setToolTipText(MessageManager.formatMessage(
267 "label.action_with_default_settings", new String[]
270 method.addActionListener(new ActionListener()
272 public void actionPerformed(ActionEvent e)
274 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
278 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
279 true, alignFrame.getViewport().getAlignment()
280 .getDataset(), alignFrame);
285 msawsmenu.add(method);
288 // only add these menu options if the service has user-modifiable
290 method = new JMenuItem(
291 MessageManager.getString("label.edit_settings_and_run"));
292 method.setToolTipText(MessageManager
293 .getString("label.view_and_change_parameters_before_alignment"));
295 method.addActionListener(new ActionListener()
297 public void actionPerformed(ActionEvent e)
299 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
302 new MsaWSClient(service, null, null, true, alignFrame
303 .getTitle(), msa, withGaps, true, alignFrame
304 .getViewport().getAlignment().getDataset(), alignFrame);
309 msawsmenu.add(method);
310 List<WsParamSetI> presets = service.getParamStore().getPresets();
311 if (presets != null && presets.size() > 0)
313 JMenu presetlist = new JMenu(MessageManager.formatMessage(
314 "label.run_with_preset_params", new String[]
317 final int showToolTipFor = ToolTipManager.sharedInstance()
319 for (final WsParamSetI preset : presets)
321 final JMenuItem methodR = new JMenuItem(preset.getName());
322 final int QUICK_TOOLTIP = 1500;
323 // JAL-1582 shorten tooltip display time in these menu items as
324 // they can obscure other options
325 methodR.addMouseListener(new MouseAdapter()
328 public void mouseEntered(MouseEvent e)
330 ToolTipManager.sharedInstance().setDismissDelay(
335 public void mouseExited(MouseEvent e)
337 ToolTipManager.sharedInstance().setDismissDelay(showToolTipFor);
341 methodR.setToolTipText(JvSwingUtils.wrapTooltip(
344 + (preset.isModifiable() ? MessageManager
345 .getString("label.user_preset")
347 .getString("label.service_preset"))
348 + "</strong><br/>" + preset.getDescription()
350 methodR.addActionListener(new ActionListener()
352 public void actionPerformed(ActionEvent e)
354 AlignmentView msa = alignFrame
355 .gatherSequencesForAlignment();
359 MsaWSClient msac = new MsaWSClient(service, preset,
360 alignFrame.getTitle(),
361 msa, false, true, alignFrame.getViewport()
362 .getAlignment().getDataset(), alignFrame);
368 presetlist.add(methodR);
370 msawsmenu.add(presetlist);
373 if (!submitGaps && canSubmitGaps())