2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
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 Preset 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);
117 if (preset instanceof JabaPreset)
119 this.preset = ((JabaPreset) preset).p;
121 else if (preset instanceof JabaWsParamSet)
123 List<Argument> newargs = new ArrayList<Argument>();
124 JabaWsParamSet pset = ((JabaWsParamSet) preset);
125 for (Option opt : pset.getjabaArguments())
129 if (arguments != null && arguments.size() > 0)
131 // merge arguments with preset's own arguments.
132 for (Argument opt : arguments)
142 "Implementation error: Can only instantiate Jaba parameter sets.");
147 // just provided with a bunch of arguments
148 this.paramset = arguments;
152 if (sh.paramStore == null)
154 sh.paramStore = new JabaParamStore(sh, Desktop.getUserParameterStore());
156 WsJobParameters jobParams = new WsJobParameters(sh, preset);
157 if (!jobParams.showRunDialog())
161 WsParamSetI prset = jobParams.getPreset();
164 paramset = JabaParamStore.getJabafromJwsArgs(jobParams
169 this.preset = ((JabaPreset) prset).p;
170 paramset = null; // no user supplied parameters.
174 if ((wsInfo = setWebService(sh, false)) == null)
176 JOptionPane.showMessageDialog(Desktop.desktop,
177 "The Multiple Sequence Alignment Service named "
178 + sh.serviceType + " is unknown",
179 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
183 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
190 // add a class reference to the list
193 private void startMsaWSClient(String altitle, AlignmentView msa,
194 boolean submitGaps, boolean preserveOrder, Alignment seqdataset)
196 // if (!locateWebService())
201 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
202 + " of " + altitle + "\nJob details\n");
203 String jobtitle = WebServiceName.toLowerCase();
204 if (jobtitle.endsWith("alignment"))
207 && (!jobtitle.endsWith("realignment") || jobtitle
208 .indexOf("profile") == -1))
210 int pos = jobtitle.indexOf("alignment");
211 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
216 jobtitle = WebServiceName + " of " + altitle;
221 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
222 + "alignment of " + altitle;
225 MsaWSThread msathread = new MsaWSThread(server, preset, paramset,
226 WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa,
227 submitGaps, preserveOrder, seqdataset);
228 wsInfo.setthisService(msathread);
232 protected String getServiceActionKey()
237 protected String getServiceActionDescription()
239 return "Multiple Sequence Alignment";
243 * look at ourselves and work out if we are a service that can take a profile
246 * @return true if we can send gapped sequences to the alignment service
248 private boolean canSubmitGaps()
250 // TODO: query service or extract service handle props to check if we can
252 return (WebServiceName.indexOf("lustal") > -1); // cheat!
255 public void attachWSMenuEntry(JMenu rmsawsmenu,
256 final Jws2Instance service, final AlignFrame alignFrame)
258 setWebService(service, true); // headless
259 boolean finished = true, submitGaps = false;
260 JMenu msawsmenu = rmsawsmenu;
261 String svcname = WebServiceName;
262 if (svcname.endsWith("WS"))
264 svcname = svcname.substring(0, svcname.length() - 2);
266 String calcName = svcname + " ";
269 msawsmenu = new JMenu(svcname);
270 rmsawsmenu.add(msawsmenu);
276 if (submitGaps == true)
278 msawsmenu = new JMenu("profile " + svcname);
279 rmsawsmenu.add(msawsmenu);
281 final boolean withGaps = submitGaps;
282 JMenuItem method = new JMenuItem(calcName + "Defaults");
283 method.setToolTipText("Align with default settings");
285 method.addActionListener(new ActionListener()
287 public void actionPerformed(ActionEvent e)
289 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
290 new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
291 true, alignFrame.getViewport().getAlignment()
292 .getDataset(), alignFrame);
296 msawsmenu.add(method);
297 method = new JMenuItem(calcName + "Edit and run ...");
298 method.setToolTipText("View and change the parameters before alignment.");
300 method.addActionListener(new ActionListener()
302 public void actionPerformed(ActionEvent e)
304 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
305 new MsaWSClient(service, null, null, true, alignFrame.getTitle(),
306 msa, withGaps, true, alignFrame.getViewport()
307 .getAlignment().getDataset(), alignFrame);
311 msawsmenu.add(method);
312 List<WsParamSetI> presets = service.getParamStore().getPresets();
313 if (presets != null && presets.size() > 0)
315 JMenu presetlist = new JMenu(calcName + "Presets");
317 for (final WsParamSetI preset : presets)
319 final JMenuItem methodR = new JMenuItem(preset.getName());
320 methodR.setToolTipText("<html><p>"+JvSwingUtils.wrapTooltip("<strong>"
321 + (preset.isModifiable() ? "User Preset"
322 : "Service Preset") + "</strong><br/>"
323 + preset.getDescription() + "</p>")+"</html>");
324 methodR.addActionListener(new ActionListener()
326 public void actionPerformed(ActionEvent e)
328 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
329 new MsaWSClient(service, preset, alignFrame.getTitle(), msa,
330 false, true, alignFrame.getViewport().getAlignment()
331 .getDataset(), alignFrame);
336 presetlist.add(methodR);
338 msawsmenu.add(presetlist);
340 if (!submitGaps && canSubmitGaps())