2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.datamodel.SequenceI;
26 import jalview.gui.AlignFrame;
27 import jalview.gui.Desktop;
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.JOptionPane;
42 import javax.swing.ToolTipManager;
44 import compbio.data.msa.MsaWS;
45 import compbio.metadata.Argument;
53 public class MsaWSClient extends Jws2Client
56 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
60 public MsaWSClient(Jws2Instance sh, String altitle,
61 jalview.datamodel.AlignmentView msa, boolean submitGaps,
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 jalview.datamodel.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 jalview.datamodel.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 wsInfo.setthisService(msathread);
184 private boolean isValidAlignment(AlignmentView av)
186 int validSeqCount = 0;
187 List<SequenceI> seqs = av.getVisibleAlignment('c').getSequences(); // .getSequences();
193 "A minimum of two sequences is required to perform this operation",
194 "Invalid selection", JOptionPane.INFORMATION_MESSAGE);
199 for (SequenceI seq : seqs)
202 if (seq.getSequenceAsString().matches("(-*[a-zA-Z]-*){3}[a-zA-Z-]*"))
206 if (validSeqCount > 1)
215 "A minimum of two sequences with at least three non-gap character \nis required to perform this operation",
216 "Invalid selection", JOptionPane.INFORMATION_MESSAGE);
221 public static void main(String[] args)
223 System.out.println("A".matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*"));
228 protected String getServiceActionKey()
233 protected String getServiceActionDescription()
235 return "Multiple Sequence Alignment";
239 * look at ourselves and work out if we are a service that can take a profile
242 * @return true if we can send gapped sequences to the alignment service
244 private boolean canSubmitGaps()
246 // TODO: query service or extract service handle props to check if we can
248 return (WebServiceName.indexOf("lustal") > -1); // cheat!
251 public void attachWSMenuEntry(JMenu rmsawsmenu,
252 final Jws2Instance service, final AlignFrame alignFrame)
254 if (registerAAConWSInstance(rmsawsmenu, service, alignFrame))
256 // Alignment dependent analysis calculation WS gui
259 setWebService(service, true); // headless
260 boolean finished = true, submitGaps = false;
261 JMenu msawsmenu = rmsawsmenu;
262 String svcname = WebServiceName;
263 if (svcname.endsWith("WS"))
265 svcname = svcname.substring(0, svcname.length() - 2);
267 String calcName = svcname + " ";
270 msawsmenu = new JMenu(svcname);
271 rmsawsmenu.add(msawsmenu);
274 boolean hasparams = service.hasParameters();
277 String action = "Align ";
278 if (submitGaps == true)
281 msawsmenu = new JMenu(MessageManager.formatMessage(
282 "label.realign_with_params", new String[]
284 msawsmenu.setToolTipText(MessageManager
285 .getString("label.align_sequences_to_existing_alignment"));
286 rmsawsmenu.add(msawsmenu);
288 final boolean withGaps = submitGaps;
290 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
291 "label.calcname_with_default_settings", new String[]
293 method.setToolTipText(MessageManager.formatMessage(
294 "label.action_with_default_settings", new String[]
297 method.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
301 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
303 if (isValidAlignment(msa))
305 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
306 true, alignFrame.getViewport().getAlignment()
307 .getDataset(), alignFrame);
312 msawsmenu.add(method);
315 // only add these menu options if the service has user-modifiable
317 method = new JMenuItem(
318 MessageManager.getString("label.edit_settings_and_run"));
319 method.setToolTipText(MessageManager
320 .getString("label.view_and_change_parameters_before_alignment"));
322 method.addActionListener(new ActionListener()
324 public void actionPerformed(ActionEvent e)
326 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
328 if (isValidAlignment(msa))
330 new MsaWSClient(service, null, null, true, alignFrame
331 .getTitle(), msa, withGaps, true, alignFrame
332 .getViewport().getAlignment().getDataset(), alignFrame);
337 msawsmenu.add(method);
338 List<WsParamSetI> presets = service.getParamStore().getPresets();
339 if (presets != null && presets.size() > 0)
341 JMenu presetlist = new JMenu(MessageManager.formatMessage(
342 "label.run_with_preset_params", new String[]
345 final int showToolTipFor = ToolTipManager.sharedInstance()
347 for (final WsParamSetI preset : presets)
349 final JMenuItem methodR = new JMenuItem(preset.getName());
350 final int QUICK_TOOLTIP = 1500;
351 // JAL-1582 shorten tooltip display time in these menu items as
352 // they can obscure other options
353 methodR.addMouseListener(new MouseAdapter()
356 public void mouseEntered(MouseEvent e)
358 ToolTipManager.sharedInstance().setDismissDelay(
363 public void mouseExited(MouseEvent e)
365 ToolTipManager.sharedInstance().setDismissDelay(showToolTipFor);
369 methodR.setToolTipText(JvSwingUtils.wrapTooltip(
372 + (preset.isModifiable() ? MessageManager
373 .getString("label.user_preset")
375 .getString("label.service_preset"))
376 + "</strong><br/>" + preset.getDescription()
378 methodR.addActionListener(new ActionListener()
380 public void actionPerformed(ActionEvent e)
382 AlignmentView msa = alignFrame
383 .gatherSequencesForAlignment();
385 if (isValidAlignment(msa))
387 new MsaWSClient(service, preset, alignFrame.getTitle(),
388 msa, false, true, alignFrame.getViewport()
389 .getAlignment().getDataset(), alignFrame);
395 presetlist.add(methodR);
397 msawsmenu.add(presetlist);
400 if (!submitGaps && canSubmitGaps())