Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.ws.jws1

File MsaWSClient.java

 

Coverage histogram

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

Code metrics

16
50
10
1
253
160
21
0.42
5
10
2.1

Classes

Class Line # Actions
MsaWSClient 49 50 21
0.026315792.6%
 

Contributing tests

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