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.AlignmentI;
25 import jalview.datamodel.AlignmentView;
26 import jalview.datamodel.SequenceI;
27 import jalview.gui.AlignFrame;
28 import jalview.gui.Desktop;
29 import jalview.gui.JvSwingUtils;
30 import jalview.util.MessageManager;
31 import jalview.ws.jws2.jabaws2.Jws2Instance;
32 import jalview.ws.params.WsParamSetI;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.util.List;
38 import javax.swing.JMenu;
39 import javax.swing.JMenuItem;
40 import javax.swing.JOptionPane;
42 import compbio.data.msa.MsaWS;
43 import compbio.metadata.Argument;
51 public class MsaWSClient extends Jws2Client
54 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
58 public MsaWSClient(Jws2Instance sh, String altitle,
59 jalview.datamodel.AlignmentView msa, boolean submitGaps,
60 boolean preserveOrder, Alignment seqdataset,
61 AlignFrame _alignFrame)
63 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
64 seqdataset, _alignFrame);
65 // TODO Auto-generated constructor stub
68 public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
69 jalview.datamodel.AlignmentView msa, boolean submitGaps,
70 boolean preserveOrder, Alignment seqdataset,
71 AlignFrame _alignFrame)
73 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
74 seqdataset, _alignFrame);
75 // TODO Auto-generated constructor stub
79 * Creates a new MsaWSClient object that uses a service given by an externally
80 * retrieved ServiceHandle
83 * service handle of type AbstractName(MsaWS)
90 * @param preserveOrder
94 public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
95 List<Argument> arguments, boolean editParams, String altitle,
96 jalview.datamodel.AlignmentView msa, boolean submitGaps,
97 boolean preserveOrder, Alignment seqdataset,
98 AlignFrame _alignFrame)
100 super(_alignFrame, preset, arguments);
101 if (!processParams(sh, editParams))
106 if (!(sh.service instanceof MsaWS))
108 // redundant at mo - but may change
112 MessageManager.formatMessage("label.service_called_is_not_msa_service", new String[]{sh.serviceType}),
113 MessageManager.getString("label.internal_jalview_error"), JOptionPane.WARNING_MESSAGE);
117 server = (MsaWS) sh.service;
118 if ((wsInfo = setWebService(sh, false)) == null)
120 JOptionPane.showMessageDialog(Desktop.desktop,
121 MessageManager.formatMessage("label.msa_service_is_unknown", new String[]{sh.serviceType}),
122 MessageManager.getString("label.internal_jalview_error"), JOptionPane.WARNING_MESSAGE);
126 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
133 // add a class reference to the list
136 private void startMsaWSClient(String altitle, AlignmentView msa,
137 boolean submitGaps, boolean preserveOrder, Alignment seqdataset)
139 // if (!locateWebService())
144 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
145 + " of " + altitle + "\nJob details\n");
146 String jobtitle = WebServiceName.toLowerCase();
147 if (jobtitle.endsWith("alignment"))
150 && (!jobtitle.endsWith("realignment") || jobtitle
151 .indexOf("profile") == -1))
153 int pos = jobtitle.indexOf("alignment");
154 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
159 jobtitle = WebServiceName + " of " + altitle;
164 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
165 + "alignment of " + altitle;
168 MsaWSThread msathread = new MsaWSThread(server, preset, paramset,
169 WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa,
170 submitGaps, preserveOrder, seqdataset);
171 wsInfo.setthisService(msathread);
172 if (isValidAlignment(alignFrame.getCurrentView().getAlignment()))
179 private boolean isValidAlignment(AlignmentI seqdataset)
181 String header = wsInfo.getInfoText()
182 + "\nValidating submited Alignment...";
183 wsInfo.setInfoText(header);
184 int validSeqCount = 0;
185 List<SequenceI> seqs = seqdataset.getSequences();
188 wsInfo.setInfoText(header
189 + "\nA minimum of two sequences is required to perform this operation");
193 for (SequenceI seq : seqs)
196 if (seq.getSequenceAsString().matches(
197 "([(a-zA-Z?)(-?)(.?)]+)?[a-zA-Z]([(a-zA-Z?)(-?)(.?)]+)?"))
201 if (validSeqCount > 1)
203 wsInfo.setInfoText(header
204 + "\nAlignment sequences was successfully validated");
209 wsInfo.setInfoText(header
210 + "\nA minimum of two sequences with at least one non-gap character in each sequence is required to perform this operation");
214 public static void main(String[] args)
218 .matches("([(a-zA-Z?)(-?)(.?)]+)?[a-zA-Z]([(a-zA-Z?)(-?)(.?)]+)?"));
223 protected String getServiceActionKey()
228 protected String getServiceActionDescription()
230 return "Multiple Sequence Alignment";
234 * look at ourselves and work out if we are a service that can take a profile
237 * @return true if we can send gapped sequences to the alignment service
239 private boolean canSubmitGaps()
241 // TODO: query service or extract service handle props to check if we can
243 return (WebServiceName.indexOf("lustal") > -1); // cheat!
246 public void attachWSMenuEntry(JMenu rmsawsmenu,
247 final Jws2Instance service, final AlignFrame alignFrame)
249 if (registerAAConWSInstance(rmsawsmenu, service, alignFrame))
251 // Alignment dependent analysis calculation WS gui
254 setWebService(service, true); // headless
255 boolean finished = true, submitGaps = false;
256 JMenu msawsmenu = rmsawsmenu;
257 String svcname = WebServiceName;
258 if (svcname.endsWith("WS"))
260 svcname = svcname.substring(0, svcname.length() - 2);
262 String calcName = svcname + " ";
265 msawsmenu = new JMenu(svcname);
266 rmsawsmenu.add(msawsmenu);
269 boolean hasparams = service.hasParameters();
272 String action = "Align ";
273 if (submitGaps == true)
276 msawsmenu = new JMenu(MessageManager.formatMessage(
277 "label.realign_with_params", new String[]
279 msawsmenu.setToolTipText(MessageManager
280 .getString("label.align_sequences_to_existing_alignment"));
281 rmsawsmenu.add(msawsmenu);
283 final boolean withGaps = submitGaps;
285 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
286 "label.calcname_with_default_settings", new String[]
288 method.setToolTipText(MessageManager.formatMessage(
289 "label.action_with_default_settings", new String[]
292 method.addActionListener(new ActionListener()
294 public void actionPerformed(ActionEvent e)
296 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
297 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
298 true, alignFrame.getViewport().getAlignment()
299 .getDataset(), alignFrame);
303 msawsmenu.add(method);
306 // only add these menu options if the service has user-modifiable
308 method = new JMenuItem(
309 MessageManager.getString("label.edit_settings_and_run"));
310 method.setToolTipText(MessageManager
311 .getString("label.view_and_change_parameters_before_alignment"));
313 method.addActionListener(new ActionListener()
315 public void actionPerformed(ActionEvent e)
317 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
318 new MsaWSClient(service, null, null, true, alignFrame
319 .getTitle(), msa, withGaps, true, alignFrame
320 .getViewport().getAlignment().getDataset(), alignFrame);
324 msawsmenu.add(method);
325 List<WsParamSetI> presets = service.getParamStore().getPresets();
326 if (presets != null && presets.size() > 0)
328 JMenu presetlist = new JMenu(MessageManager.formatMessage(
329 "label.run_with_preset_params", new String[]
332 for (final WsParamSetI preset : presets)
334 final JMenuItem methodR = new JMenuItem(preset.getName());
335 methodR.setToolTipText(JvSwingUtils.wrapTooltip(true, "<p><strong>"
336 + (preset.isModifiable() ? MessageManager.getString("label.user_preset")
337 : MessageManager.getString("label.service_preset")) + "</strong><br/>"
338 + preset.getDescription() + "</p>"));
339 methodR.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent e)
343 AlignmentView msa = alignFrame
344 .gatherSequencesForAlignment();
345 new MsaWSClient(service, preset, alignFrame.getTitle(),
346 msa, false, true, alignFrame.getViewport()
347 .getAlignment().getDataset(), alignFrame);
352 presetlist.add(methodR);
354 msawsmenu.add(presetlist);
357 if (!submitGaps && canSubmitGaps())