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.api.MultipleSequenceAlignmentI;
31 import jalview.ws.gui.MsaWSThread;
32 import jalview.ws.jws2.jabaws2.Jws2Instance;
33 import jalview.ws.params.ArgumentI;
34 import jalview.ws.params.WsParamSetI;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.MouseAdapter;
39 import java.awt.event.MouseEvent;
40 import java.util.List;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuItem;
44 import javax.swing.ToolTipManager;
52 public class MsaWSClient extends Jws2Client
55 * server is a proxy class implementing the core methods for submitting,
56 * monitoring and retrieving results from a multiple sequence alignment
59 MultipleSequenceAlignmentI server;
61 public MsaWSClient(Jws2Instance sh, String altitle,
62 jalview.datamodel.AlignmentView msa, boolean submitGaps,
63 boolean preserveOrder, AlignmentI seqdataset,
64 AlignFrame _alignFrame)
66 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
67 seqdataset, _alignFrame);
68 // TODO Auto-generated constructor stub
71 public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
72 jalview.datamodel.AlignmentView msa, boolean submitGaps,
73 boolean preserveOrder, AlignmentI seqdataset,
74 AlignFrame _alignFrame)
76 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
77 seqdataset, _alignFrame);
78 // TODO Auto-generated constructor stub
82 * Creates a new MsaWSClient object that uses a service given by an externally
83 * retrieved ServiceHandle
86 * service handle of type AbstractName(MsaWS)
93 * @param preserveOrder
97 public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
98 List<ArgumentI> arguments, boolean editParams, String altitle,
99 jalview.datamodel.AlignmentView msa, boolean submitGaps,
100 boolean preserveOrder, AlignmentI seqdataset,
101 AlignFrame _alignFrame)
103 super(_alignFrame, preset, arguments);
104 if (!processParams(sh, editParams))
109 if (!(sh.getEndpoint() instanceof MultipleSequenceAlignmentI))
111 // redundant at mo - but may change
112 JvOptionPane.showMessageDialog(Desktop.desktop,
113 MessageManager.formatMessage(
114 "label.service_called_is_not_msa_service",
117 MessageManager.getString("label.internal_jalview_error"),
118 JvOptionPane.WARNING_MESSAGE);
123 server = (MultipleSequenceAlignmentI) sh.getEndpoint();
124 if ((wsInfo = setWebService(sh, false)) == null)
126 JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
127 .formatMessage("label.msa_service_is_unknown", new String[]
129 MessageManager.getString("label.internal_jalview_error"),
130 JvOptionPane.WARNING_MESSAGE);
135 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
142 // add a class reference to the list
145 private void startMsaWSClient(String altitle, AlignmentView msa,
146 boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
148 // if (!locateWebService())
153 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
154 + " of " + altitle + "\nJob details\n");
155 String jobtitle = WebServiceName.toLowerCase();
156 if (jobtitle.endsWith("alignment"))
158 if (submitGaps && (!jobtitle.endsWith("realignment")
159 || jobtitle.indexOf("profile") == -1))
161 int pos = jobtitle.indexOf("alignment");
162 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
167 jobtitle = WebServiceName + " of " + altitle;
172 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
173 + "alignment of " + altitle;
176 MsaWSThread msathread = new MsaWSThread(server, preset, paramset, WsURL,
177 wsInfo, alignFrame, WebServiceName, jobtitle, msa, submitGaps,
178 preserveOrder, seqdataset);
179 if (msathread.hasValidInput())
181 wsInfo.setthisService(msathread);
182 wsInfo.setVisible(true);
187 JvOptionPane.showMessageDialog(alignFrame,
188 MessageManager.getString("info.invalid_msa_input_mininfo"),
189 MessageManager.getString("info.invalid_msa_notenough"),
190 JvOptionPane.INFORMATION_MESSAGE);
191 wsInfo.setVisible(false);
195 public static void main(String[] args)
197 System.out.println("A".matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*"));
200 protected String getServiceActionKey()
205 protected String getServiceActionDescription()
207 return "Multiple Sequence Alignment";
211 * look at ourselves and work out if we are a service that can take a profile
214 * @return true if we can send gapped sequences to the alignment service
216 private boolean canSubmitGaps()
218 // TODO: query service or extract service handle props to check if we can
220 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
255 .formatMessage("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()
273 public void actionPerformed(ActionEvent e)
275 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
279 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
281 alignFrame.getViewport().getAlignment().getDataset(),
287 msawsmenu.add(method);
290 // only add these menu options if the service has user-modifiable
292 method = new JMenuItem(
293 MessageManager.getString("label.edit_settings_and_run"));
294 method.setToolTipText(MessageManager.getString(
295 "label.view_and_change_parameters_before_alignment"));
297 method.addActionListener(new ActionListener()
300 public void actionPerformed(ActionEvent e)
302 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
305 new MsaWSClient(service, null, null, true,
306 alignFrame.getTitle(), msa, withGaps, true,
307 alignFrame.getViewport().getAlignment().getDataset(),
313 msawsmenu.add(method);
314 List<WsParamSetI> presets = service.getParamStore().getPresets();
315 if (presets != null && presets.size() > 0)
317 JMenu presetlist = new JMenu(MessageManager.formatMessage(
318 "label.run_with_preset_params", new String[]
321 final int showToolTipFor = ToolTipManager.sharedInstance()
323 for (final WsParamSetI preset : presets)
325 final JMenuItem methodR = new JMenuItem(preset.getName());
326 final int QUICK_TOOLTIP = 1500;
327 // JAL-1582 shorten tooltip display time in these menu items as
328 // they can obscure other options
329 methodR.addMouseListener(new MouseAdapter()
332 public void mouseEntered(MouseEvent e)
334 ToolTipManager.sharedInstance()
335 .setDismissDelay(QUICK_TOOLTIP);
339 public void mouseExited(MouseEvent e)
341 ToolTipManager.sharedInstance()
342 .setDismissDelay(showToolTipFor);
346 String tooltip = JvSwingUtils.wrapTooltip(true, "<strong>"
347 + (preset.isModifiable()
348 ? MessageManager.getString("label.user_preset")
350 .getString("label.service_preset"))
351 + "</strong><br/>" + preset.getDescription());
352 methodR.setToolTipText(tooltip);
353 methodR.addActionListener(new ActionListener()
356 public void actionPerformed(ActionEvent e)
358 AlignmentView msa = alignFrame
359 .gatherSequencesForAlignment();
363 MsaWSClient msac = new MsaWSClient(service, preset,
364 alignFrame.getTitle(), msa, false, true,
365 alignFrame.getViewport().getAlignment()
373 presetlist.add(methodR);
375 msawsmenu.add(presetlist);
378 if (!submitGaps && canSubmitGaps())