Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.ws.jws1

File MsaWSClient.java

 

Coverage histogram

../../../img/srcFileCovDistChart1.png
52% of files have more coverage

Code metrics

16
50
10
1
251
159
21
0.42
5
10
2.1

Classes

Class Line # Actions
MsaWSClient 47 50 21
0.026315792.6%
 

Contributing tests

This file is covered by 1 test. .

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.jws1;
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.WebserviceInfo;
29    import jalview.util.MessageManager;
30   
31    import java.awt.event.ActionEvent;
32    import java.awt.event.ActionListener;
33   
34    import javax.swing.JMenu;
35    import javax.swing.JMenuItem;
36   
37    import ext.vamsas.MuscleWSServiceLocator;
38    import ext.vamsas.MuscleWSSoapBindingStub;
39    import ext.vamsas.ServiceHandle;
40   
41    /**
42    * DOCUMENT ME!
43    *
44    * @author $author$
45    * @version $Revision$
46    */
 
47    public class MsaWSClient extends WS1Client
48    {
49    /**
50    * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
51    */
52    ext.vamsas.MuscleWS server;
53   
54    AlignFrame alignFrame;
55   
56    /**
57    * Creates a new MsaWSClient object that uses a service given by an externally
58    * retrieved ServiceHandle
59    *
60    * @param sh
61    * service handle of type AbstractName(MsaWS)
62    * @param altitle
63    * DOCUMENT ME!
64    * @param msa
65    * DOCUMENT ME!
66    * @param submitGaps
67    * DOCUMENT ME!
68    * @param preserveOrder
69    * DOCUMENT ME!
70    */
71   
 
72  0 toggle public MsaWSClient(ext.vamsas.ServiceHandle sh, String altitle,
73    jalview.datamodel.AlignmentView msa, boolean submitGaps,
74    boolean preserveOrder, AlignmentI seqdataset,
75    AlignFrame _alignFrame)
76    {
77  0 super();
78  0 alignFrame = _alignFrame;
79  0 if (!sh.getAbstractName().equals("MsaWS"))
80    {
81  0 JvOptionPane.showMessageDialog(Desktop.desktop,
82    MessageManager.formatMessage(
83    "label.service_called_is_not_msa_service",
84    new String[]
85    { sh.getName() }),
86    MessageManager.getString("label.internal_jalview_error"),
87    JvOptionPane.WARNING_MESSAGE);
88   
89  0 return;
90    }
91   
92  0 if ((wsInfo = setWebService(sh)) == null)
93    {
94  0 JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
95    .formatMessage("label.msa_service_is_unknown", new String[]
96    { sh.getName() }),
97    MessageManager.getString("label.internal_jalview_error"),
98    JvOptionPane.WARNING_MESSAGE);
99   
100  0 return;
101    }
102  0 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
103   
104    }
105   
 
106  1 toggle public MsaWSClient()
107    {
108  1 super();
109    // add a class reference to the list
110    }
111   
 
112  0 toggle private void startMsaWSClient(String altitle, AlignmentView msa,
113    boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
114    {
115  0 if (!locateWebService())
116    {
117  0 return;
118    }
119   
120  0 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
121    + " of " + altitle + "\nJob details\n");
122  0 String jobtitle = WebServiceName.toLowerCase();
123  0 if (jobtitle.endsWith("alignment"))
124    {
125  0 if (submitGaps && (!jobtitle.endsWith("realignment")
126    || jobtitle.indexOf("profile") == -1))
127    {
128  0 int pos = jobtitle.indexOf("alignment");
129  0 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
130    + altitle;
131    }
132    else
133    {
134  0 jobtitle = WebServiceName + " of " + altitle;
135    }
136    }
137    else
138    {
139  0 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
140    + "alignment of " + altitle;
141    }
142   
143  0 MsaWSThread msathread = new MsaWSThread(server, WsURL, wsInfo,
144    alignFrame, WebServiceName, jobtitle, msa, submitGaps,
145    preserveOrder, seqdataset);
146  0 wsInfo.setthisService(msathread);
147  0 msathread.start();
148    }
149   
150    /**
151    * Initializes the server field with a valid service implementation.
152    *
153    * @return true if service was located.
154    */
 
155  0 toggle private boolean locateWebService()
156    {
157    // TODO: MuscleWS transmuted to generic MsaWS client
158  0 MuscleWSServiceLocator loc = new MuscleWSServiceLocator(); // Default
159   
160  0 try
161    {
162  0 this.server = loc.getMuscleWS(new java.net.URL(WsURL));
163  0 ((MuscleWSSoapBindingStub) this.server).setTimeout(60000); // One minute
164    // timeout
165    } catch (Exception ex)
166    {
167  0 wsInfo.setProgressText("Serious! " + WebServiceName
168    + " Service location failed\nfor URL :" + WsURL + "\n"
169    + ex.getMessage());
170  0 wsInfo.setStatus(WebserviceInfo.ERROR);
171  0 ex.printStackTrace();
172   
173  0 return false;
174    }
175   
176  0 loc.getEngine().setOption("axis", "1");
177   
178  0 return true;
179    }
180   
 
181  0 toggle protected String getServiceActionKey()
182    {
183  0 return "MsaWS";
184    }
185   
 
186  0 toggle protected String getServiceActionDescription()
187    {
188  0 return "Multiple Sequence Alignment";
189    }
190   
191    /**
192    * look at ourselves and work out if we are a service that can take a profile
193    * and align to it
194    *
195    * @return true if we can send gapped sequences to the alignment service
196    */
 
197  0 toggle private boolean canSubmitGaps()
198    {
199    // TODO: query service or extract service handle props to check if we can
200    // realign
201  0 return (WebServiceName.indexOf("lustal") > -1); // cheat!
202    }
203   
 
204  0 toggle @Override
205    public void attachWSMenuEntry(JMenu msawsmenu,
206    final ServiceHandle serviceHandle, final AlignFrame alignFrame)
207    {
208  0 setWebService(serviceHandle, true); // headless
209  0 JMenuItem method = new JMenuItem(WebServiceName);
210  0 method.setToolTipText(WsURL);
211  0 method.addActionListener(new ActionListener()
212    {
 
213  0 toggle @Override
214    public void actionPerformed(ActionEvent e)
215    {
216  0 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
217  0 new jalview.ws.jws1.MsaWSClient(serviceHandle,
218    alignFrame.getTitle(), msa, false, true,
219    alignFrame.getViewport().getAlignment().getDataset(),
220    alignFrame);
221   
222    }
223   
224    });
225  0 msawsmenu.add(method);
226  0 if (canSubmitGaps())
227    {
228    // We know that ClustalWS can accept partial alignments for refinement.
229  0 final JMenuItem methodR = new JMenuItem(
230    serviceHandle.getName() + " Realign");
231  0 methodR.setToolTipText(WsURL);
232  0 methodR.addActionListener(new ActionListener()
233    {
 
234  0 toggle @Override
235    public void actionPerformed(ActionEvent e)
236    {
237  0 AlignmentView msa = alignFrame.gatherSequencesForAlignment();
238  0 new jalview.ws.jws1.MsaWSClient(serviceHandle,
239    alignFrame.getTitle(), msa, true, true,
240    alignFrame.getViewport().getAlignment().getDataset(),
241    alignFrame);
242   
243    }
244   
245    });
246  0 msawsmenu.add(methodR);
247   
248    }
249   
250    }
251    }