Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ws.jws2

File MsaWSClient.java

 

Coverage histogram

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

Code metrics

40
92
15
1
386
286
39
0.42
6.13
15
2.6

Classes

Class Line # Actions
MsaWSClient 52 92 39 81
0.448979644.9%
 

Contributing tests

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