2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws2;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.util.ArrayList;
23 import java.util.List;
27 import jalview.datamodel.*;
29 import compbio.data.msa.MsaWS;
30 import compbio.metadata.Argument;
31 import compbio.metadata.Option;
32 import compbio.metadata.Preset;
33 import compbio.metadata.PresetManager;
34 import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
35 import jalview.ws.jws2.dm.JabaWsParamSet;
36 import jalview.ws.params.WsParamSetI;
44 public class MsaWSClient extends Jws2Client
47 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
51 AlignFrame alignFrame;
53 private WsParamSetI preset;
55 private List<Argument> paramset;
57 public MsaWSClient(Jws2Discoverer.Jws2Instance sh, String altitle,
58 jalview.datamodel.AlignmentView msa, boolean submitGaps,
59 boolean preserveOrder, Alignment seqdataset,
60 AlignFrame _alignFrame)
62 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
63 seqdataset, _alignFrame);
64 // TODO Auto-generated constructor stub
67 public MsaWSClient(Jws2Discoverer.Jws2Instance sh, WsParamSetI preset,
68 String altitle, jalview.datamodel.AlignmentView msa,
69 boolean submitGaps, boolean preserveOrder, Alignment seqdataset,
70 AlignFrame _alignFrame)
72 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
73 seqdataset, _alignFrame);
74 // TODO Auto-generated constructor stub
78 * Creates a new MsaWSClient object that uses a service given by an externally
79 * retrieved ServiceHandle
82 * service handle of type AbstractName(MsaWS)
89 * @param preserveOrder
93 public MsaWSClient(Jws2Discoverer.Jws2Instance sh, WsParamSetI preset,
94 List<Argument> arguments, boolean editParams, String altitle,
95 jalview.datamodel.AlignmentView msa, boolean submitGaps,
96 boolean preserveOrder, Alignment seqdataset,
97 AlignFrame _alignFrame)
100 alignFrame = _alignFrame;
101 if (!(sh.service instanceof MsaWS))
103 // redundant at mo - but may change
107 "The Service called \n"
109 + "\nis not a \nMultiple Sequence Alignment Service !",
110 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
118 if (!((preset instanceof JabaPreset) || preset instanceof JabaWsParamSet)) {
120 this.preset = ((JabaPreset) preset).p;
122 else if (preset instanceof JabaWsParamSet)
124 List<Argument> newargs = new ArrayList<Argument>();
125 JabaWsParamSet pset = ((JabaWsParamSet) preset);
126 for (Option opt : pset.getjabaArguments())
130 if (arguments != null && arguments.size() > 0)
132 // merge arguments with preset's own arguments.
133 for (Argument opt : arguments)
143 "Implementation error: Can only instantiate Jaba parameter sets.");
148 // just provided with a bunch of arguments
149 this.paramset = arguments;
153 if (sh.paramStore == null)
155 sh.paramStore = new JabaParamStore(sh,
156 Desktop.getUserParameterStore());
158 WsJobParameters jobParams = new WsJobParameters(sh, preset);
159 if (!jobParams.showRunDialog())
163 WsParamSetI prset = jobParams.getPreset();
166 paramset = JabaParamStore.getJabafromJwsArgs(jobParams
171 this.preset = prset; // ((JabaPreset) prset).p;
172 paramset = null; // no user supplied parameters.
176 if ((wsInfo = setWebService(sh, false)) == null)
178 JOptionPane.showMessageDialog(Desktop.desktop,
179 "The Multiple Sequence Alignment Service named "
180 + sh.serviceType + " is unknown",
181 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
185 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
192 // add a class reference to the list
195 private void startMsaWSClient(String altitle, AlignmentView msa,
196 boolean submitGaps, boolean preserveOrder, Alignment seqdataset)
198 // if (!locateWebService())
203 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
204 + " of " + altitle + "\nJob details\n");
205 String jobtitle = WebServiceName.toLowerCase();
206 if (jobtitle.endsWith("alignment"))
209 && (!jobtitle.endsWith("realignment") || jobtitle
210 .indexOf("profile") == -1))
212 int pos = jobtitle.indexOf("alignment");
213 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
218 jobtitle = WebServiceName + " of " + altitle;
223 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
224 + "alignment of " + altitle;
227 MsaWSThread msathread = new MsaWSThread(server, preset, paramset,
228 WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa,
229 submitGaps, preserveOrder, seqdataset);
230 wsInfo.setthisService(msathread);
234 protected String getServiceActionKey()
239 protected String getServiceActionDescription()
241 return "Multiple Sequence Alignment";
245 * look at ourselves and work out if we are a service that can take a profile
248 * @return true if we can send gapped sequences to the alignment service
250 private boolean canSubmitGaps()
252 // TODO: query service or extract service handle props to check if we can
254 return (WebServiceName.indexOf("lustal") > -1); // cheat!
257 public void attachWSMenuEntry(JMenu rmsawsmenu,
258 final Jws2Instance service, final AlignFrame alignFrame)
260 setWebService(service, true); // headless
261 boolean finished = true, submitGaps = false;
262 JMenu msawsmenu = rmsawsmenu;
263 String svcname = WebServiceName;
264 if (svcname.endsWith("WS"))
266 svcname = svcname.substring(0, svcname.length() - 2);
268 String calcName = svcname + " ";
271 msawsmenu = new JMenu(svcname);
272 rmsawsmenu.add(msawsmenu);
275 boolean hasparams = service.hasParameters();
278 String action = "Align ";
279 if (submitGaps == true)
282 msawsmenu = new JMenu("Realign with " + svcname);
284 .setToolTipText("Align sequences to an existing alignment");
285 rmsawsmenu.add(msawsmenu);
287 final boolean withGaps = submitGaps;
289 JMenuItem method = new JMenuItem(calcName + "with Defaults");
290 method.setToolTipText(action + "with default settings");
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("Edit settings and run ...");
309 method.setToolTipText("View and change the parameters before alignment.");
311 method.addActionListener(new ActionListener()
313 public void actionPerformed(ActionEvent e)
315 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
316 new MsaWSClient(service, null, null, true, alignFrame
317 .getTitle(), msa, withGaps, true, alignFrame
318 .getViewport().getAlignment().getDataset(), alignFrame);
322 msawsmenu.add(method);
323 List<WsParamSetI> presets = service.getParamStore().getPresets();
324 if (presets != null && presets.size() > 0)
326 JMenu presetlist = new JMenu("Run "+calcName + "with preset");
328 for (final WsParamSetI preset : presets)
330 final JMenuItem methodR = new JMenuItem(preset.getName());
331 methodR.setToolTipText("<html><p>"
332 + JvSwingUtils.wrapTooltip("<strong>"
333 + (preset.isModifiable() ? "User Preset"
334 : "Service Preset") + "</strong><br/>"
335 + preset.getDescription() + "</p>") + "</html>");
336 methodR.addActionListener(new ActionListener()
338 public void actionPerformed(ActionEvent e)
340 AlignmentView msa = alignFrame
341 .gatherSequencesForAlignment();
342 new MsaWSClient(service, preset, alignFrame.getTitle(),
343 msa, false, true, alignFrame.getViewport()
344 .getAlignment().getDataset(), alignFrame);
349 presetlist.add(methodR);
351 msawsmenu.add(presetlist);
354 if (!submitGaps && canSubmitGaps())