Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.ws.jws2

File MsaWSClient.java

 

Coverage histogram

../../../img/srcFileCovDistChart5.png
43% of files have more coverage

Code metrics

40
94
15
1
391
290
40
0.43
6.27
15
2.67

Classes

Class Line # Actions
MsaWSClient 53 94 40
0.4429530244.3%
 

Contributing tests

This file is covered by 185 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ws.jws2;
22   
23    import java.util.Locale;
24   
25    import java.awt.event.ActionEvent;
26    import java.awt.event.ActionListener;
27    import java.awt.event.MouseAdapter;
28    import java.awt.event.MouseEvent;
29    import java.util.List;
30   
31    import javax.swing.JMenu;
32    import javax.swing.JMenuItem;
33    import javax.swing.ToolTipManager;
34   
35    import compbio.data.msa.MsaWS;
36    import compbio.metadata.Argument;
37    import jalview.datamodel.AlignmentI;
38    import jalview.datamodel.AlignmentView;
39    import jalview.gui.AlignFrame;
40    import jalview.gui.Desktop;
41    import jalview.gui.JvOptionPane;
42    import jalview.gui.JvSwingUtils;
43    import jalview.util.MessageManager;
44    import jalview.ws.jws2.jabaws2.Jws2Instance;
45    import jalview.ws.params.WsParamSetI;
46   
47    /**
48    * DOCUMENT ME!
49    *
50    * @author $author$
51    * @version $Revision$
52    */
 
53    public class MsaWSClient extends Jws2Client
54    {
55    /**
56    * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
57    */
58    MsaWS server;
59   
 
60  0 toggle public MsaWSClient(Jws2Instance sh, String altitle,
61    jalview.datamodel.AlignmentView msa, boolean submitGaps,
62    boolean preserveOrder, AlignmentI seqdataset,
63    AlignFrame _alignFrame)
64    {
65  0 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
66    seqdataset, _alignFrame);
67    // TODO Auto-generated constructor stub
68    }
69   
 
70  0 toggle public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
71    jalview.datamodel.AlignmentView msa, boolean submitGaps,
72    boolean preserveOrder, AlignmentI seqdataset,
73    AlignFrame _alignFrame)
74    {
75  0 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
76    seqdataset, _alignFrame);
77    // TODO Auto-generated constructor stub
78    }
79   
80    /**
81    * Creates a new MsaWSClient object that uses a service given by an externally
82    * retrieved ServiceHandle
83    *
84    * @param sh
85    * service handle of type AbstractName(MsaWS)
86    * @param altitle
87    * DOCUMENT ME!
88    * @param msa
89    * DOCUMENT ME!
90    * @param submitGaps
91    * DOCUMENT ME!
92    * @param preserveOrder
93    * DOCUMENT ME!
94    */
95   
 
96  0 toggle public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
97    List<Argument> arguments, boolean editParams, String altitle,
98    jalview.datamodel.AlignmentView msa, boolean submitGaps,
99    boolean preserveOrder, AlignmentI seqdataset,
100    AlignFrame _alignFrame)
101    {
102  0 super(_alignFrame, preset, arguments);
103  0 if (!processParams(sh, editParams))
104    {
105  0 return;
106    }
107   
108  0 if (!(sh.service instanceof MsaWS))
109    {
110    // redundant at mo - but may change
111  0 JvOptionPane.showMessageDialog(Desktop.desktop,
112    MessageManager.formatMessage(
113    "label.service_called_is_not_msa_service",
114    new String[]
115    { sh.serviceType }),
116    MessageManager.getString("label.internal_jalview_error"),
117    JvOptionPane.WARNING_MESSAGE);
118   
119  0 return;
120    }
121  0 server = (MsaWS) sh.service;
122  0 if ((wsInfo = setWebService(sh, false)) == null)
123    {
124  0 JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
125    .formatMessage("label.msa_service_is_unknown", new String[]
126    { sh.serviceType }),
127    MessageManager.getString("label.internal_jalview_error"),
128    JvOptionPane.WARNING_MESSAGE);
129   
130  0 return;
131    }
132   
133  0 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
134   
135    }
136   
 
137  8325 toggle public MsaWSClient()
138    {
139  8325 super();
140    // add a class reference to the list
141    }
142   
 
143  0 toggle private void startMsaWSClient(String altitle, AlignmentView msa,
144    boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
145    {
146    // if (!locateWebService())
147    // {
148    // return;
149    // }
150   
151  0 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
152    + " of " + altitle + "\nJob details\n");
153  0 String jobtitle = WebServiceName.toLowerCase(Locale.ROOT);
154  0 if (jobtitle.endsWith("alignment"))
155    {
156  0 if (submitGaps && (!jobtitle.endsWith("realignment")
157    || jobtitle.indexOf("profile") == -1))
158    {
159  0 int pos = jobtitle.indexOf("alignment");
160  0 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
161    + altitle;
162    }
163    else
164    {
165  0 jobtitle = WebServiceName + " of " + altitle;
166    }
167    }
168    else
169    {
170  0 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
171    + "alignment of " + altitle;
172    }
173   
174  0 MsaWSThread msathread = new MsaWSThread(server, preset, paramset, WsURL,
175    wsInfo, alignFrame, WebServiceName, jobtitle, msa, submitGaps,
176    preserveOrder, seqdataset);
177  0 if (msathread.hasValidInput())
178    {
179  0 wsInfo.setthisService(msathread);
180  0 wsInfo.setVisible(true);
181  0 msathread.start();
182    }
183    else
184    {
185  0 wsInfo.setVisible(false);
186  0 JvOptionPane.showMessageDialog(alignFrame,
187    MessageManager.getString("info.invalid_msa_input_mininfo"),
188    MessageManager.getString("info.invalid_msa_notenough"),
189    JvOptionPane.INFORMATION_MESSAGE);
190    }
191    }
192   
 
193  0 toggle protected String getServiceActionKey()
194    {
195  0 return "MsaWS";
196    }
197   
 
198  0 toggle protected String getServiceActionDescription()
199    {
200  0 return "Multiple Sequence Alignment";
201    }
202   
203    /**
204    * look at ourselves and work out if we are a service that can take a profile
205    * and align to it
206    *
207    * @return true if we can send gapped sequences to the alignment service
208    */
 
209  16650 toggle private boolean canSubmitGaps()
210    {
211    // TODO: query service or extract service handle props to check if we can
212    // realign
213  16650 return (WebServiceName.indexOf("lustal") > -1); // cheat!
214    }
215   
 
216  8325 toggle @Override
217    public void attachWSMenuEntry(JMenu rmsawsmenu,
218    final Jws2Instance service, final AlignFrame af)
219    {
220  8325 if (registerAAConWSInstance(rmsawsmenu, service, af))
221    {
222    // Alignment dependent analysis calculation WS gui
223  0 return;
224    }
225  8325 setWebService(service, true); // headless
226  8325 boolean finished = true, submitGaps = false;
227  8325 JMenu msawsmenu = rmsawsmenu;
228  8325 String svcname = WebServiceName;
229  8325 if (svcname.endsWith("WS"))
230    {
231  8325 svcname = svcname.substring(0, svcname.length() - 2);
232    }
233  8325 String calcName = svcname + " ";
234  8325 if (canSubmitGaps())
235    {
236  2073 msawsmenu = new JMenu(svcname);
237  2073 rmsawsmenu.add(msawsmenu);
238  2073 calcName = "";
239    }
240  8325 boolean hasparams = service.hasParameters();
241  8325 do
242    {
243  10398 String action = "Align ";
244  10398 if (submitGaps == true)
245    {
246  2073 action = "Realign ";
247  2073 msawsmenu = new JMenu(MessageManager
248    .formatMessage("label.realign_with_params", new String[]
249    { svcname }));
250  2073 msawsmenu.setToolTipText(MessageManager
251    .getString("label.align_sequences_to_existing_alignment"));
252  2073 rmsawsmenu.add(msawsmenu);
253    }
254  10398 final boolean withGaps = submitGaps;
255   
256  10398 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
257    "label.calcname_with_default_settings", new String[]
258    { calcName }));
259  10398 method.setToolTipText(MessageManager.formatMessage(
260    "label.action_with_default_settings", new String[]
261    { action }));
262   
263  10398 method.addActionListener(new ActionListener()
264    {
 
265  0 toggle @Override
266    public void actionPerformed(ActionEvent e)
267    {
268  0 AlignmentView msa = af.gatherSequencesForAlignment();
269   
270  0 if (msa != null)
271    {
272  0 new MsaWSClient(service, af.getTitle(), msa, withGaps, true,
273    af.getViewport().getAlignment().getDataset(), af);
274    }
275   
276    }
277    });
278  10398 msawsmenu.add(method);
279  10398 if (hasparams)
280    {
281    // only add these menu options if the service has user-modifiable
282    // arguments
283  10398 method = new JMenuItem(
284    MessageManager.getString("label.edit_settings_and_run"));
285  10398 method.setToolTipText(MessageManager.getString(
286    "label.view_and_change_parameters_before_alignment"));
287   
288  10398 method.addActionListener(new ActionListener()
289    {
 
290  0 toggle @Override
291    public void actionPerformed(ActionEvent e)
292    {
293  0 AlignmentView msa = af.gatherSequencesForAlignment();
294  0 if (msa != null)
295    {
296  0 startJob(service, af, withGaps, msa);
297    }
298   
299    }
300    });
301  10398 msawsmenu.add(method);
302  10398 List<WsParamSetI> presets = service.getParamStore().getPresets();
303  10398 if (presets != null && presets.size() > 0)
304    {
305  5358 JMenu presetlist = new JMenu(MessageManager.formatMessage(
306    "label.run_with_preset_params", new String[]
307    { calcName }));
308   
309  5358 final int showToolTipFor = ToolTipManager.sharedInstance()
310    .getDismissDelay();
311  5358 for (final WsParamSetI preSet : presets)
312    {
313  13149 final JMenuItem methodR = new JMenuItem(preSet.getName());
314  13149 final int QUICK_TOOLTIP = 1500;
315    // JAL-1582 shorten tooltip display time in these menu items as
316    // they can obscure other options
317  13149 methodR.addMouseListener(new MouseAdapter()
318    {
 
319  0 toggle @Override
320    public void mouseEntered(MouseEvent e)
321    {
322  0 ToolTipManager.sharedInstance()
323    .setDismissDelay(QUICK_TOOLTIP);
324    }
325   
 
326  0 toggle @Override
327    public void mouseExited(MouseEvent e)
328    {
329  0 ToolTipManager.sharedInstance()
330    .setDismissDelay(showToolTipFor);
331    }
332   
333    });
334  13149 String tooltip = JvSwingUtils.wrapTooltip(true, "<strong>"
335  13149 + (preSet.isModifiable()
336    ? MessageManager.getString("label.user_preset")
337    : MessageManager
338    .getString("label.service_preset"))
339    + "</strong><br/>" + preSet.getDescription());
340  13149 methodR.setToolTipText(tooltip);
341  13149 methodR.addActionListener(new ActionListener()
342    {
 
343  0 toggle @Override
344    public void actionPerformed(ActionEvent e)
345    {
346  0 AlignmentView msa = af.gatherSequencesForAlignment();
347   
348  0 if (msa != null)
349    {
350  0 MsaWSClient msac = new MsaWSClient(service, preSet,
351    af.getTitle(), msa, false, true,
352    af.getViewport().getAlignment().getDataset(), af);
353    }
354   
355    }
356   
357    });
358  13149 presetlist.add(methodR);
359    }
360  5358 msawsmenu.add(presetlist);
361    }
362    }
363  10398 if (!submitGaps && canSubmitGaps())
364    {
365  2073 submitGaps = true;
366  2073 finished = false;
367    }
368    else
369    {
370  8325 finished = true;
371    }
372  10398 } while (!finished);
373    }
374   
 
375  0 toggle protected void startJob(final Jws2Instance service, final AlignFrame af,
376    final boolean withGaps, AlignmentView msa)
377    {
378  0 try
379    {
380  0 new MsaWSClient(service, null, null, true, af.getTitle(), msa,
381    withGaps, true, af.getViewport().getAlignment().getDataset(),
382    af);
383    } catch (Exception e)
384    {
385  0 JvOptionPane.showMessageDialog(alignFrame, e.getMessage(),
386    MessageManager.getString("label.state_job_error"),
387    JvOptionPane.WARNING_MESSAGE);
388   
389    }
390    }
391    }