Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:05:32 GMT
  2. Package jalview.ws.jws1

File JPredClient.java

 

Coverage histogram

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

Code metrics

42
105
14
1
377
275
38
0.36
7.5
14
2.71

Classes

Class Line # Actions
JPredClient 48 105 38
0.043478264.3%
 

Contributing tests

This file is covered by 178 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.analysis.AlignSeq;
26    import jalview.bin.Console;
27    import jalview.datamodel.AlignmentView;
28    import jalview.datamodel.SeqCigar;
29    import jalview.datamodel.SequenceI;
30    import jalview.gui.AlignFrame;
31    import jalview.gui.Desktop;
32    import jalview.gui.JvOptionPane;
33    import jalview.gui.WebserviceInfo;
34    import jalview.util.MessageManager;
35   
36    import java.awt.event.ActionEvent;
37    import java.awt.event.ActionListener;
38    import java.util.Hashtable;
39   
40    import javax.swing.JMenu;
41    import javax.swing.JMenuItem;
42   
43    import ext.vamsas.Jpred;
44    import ext.vamsas.JpredServiceLocator;
45    import ext.vamsas.JpredSoapBindingStub;
46    import ext.vamsas.ServiceHandle;
47   
 
48    public class JPredClient extends WS1Client
49    {
50    /**
51    * crate a new GUI JPred Job
52    *
53    * @param sh
54    * ServiceHandle
55    * @param title
56    * String
57    * @param msa
58    * boolean - true - submit alignment as a sequence profile
59    * @param alview
60    * AlignmentView
61    * @param viewonly
62    * TODO
63    */
 
64  0 toggle public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa,
65    AlignmentView alview, AlignFrame parentFrame, boolean viewonly)
66    {
67  0 super();
68  0 wsInfo = setWebService(sh);
69  0 startJPredClient(title, msa, alview, parentFrame, viewonly);
70   
71    }
72   
73    /**
74    * startJPredClient TODO: refine submission to cope with local prediction of
75    * visible regions or multiple single sequence jobs TODO: sequence
76    * representative support - could submit alignment of representatives as msa.
77    * TODO: msa hidden region prediction - submit each chunk for prediction.
78    * concatenate results of each. TODO: single seq prediction - submit each
79    * contig of each sequence for prediction (but must cope with flanking regions
80    * and short seqs)
81    *
82    * @param title
83    * String
84    * @param msa
85    * boolean
86    * @param alview
87    * AlignmentView
88    * @param viewonly
89    * if true then the prediction will be made just on the concatenated
90    * visible regions
91    */
 
92  0 toggle private void startJPredClient(String title, boolean msa,
93    jalview.datamodel.AlignmentView alview, AlignFrame parentFrame,
94    boolean viewonly)
95    {
96  0 AlignmentView input = alview;
97  0 if (wsInfo == null)
98    {
99  0 wsInfo = setWebService();
100    }
101  0 Jpred server = locateWebService();
102  0 if (server == null)
103    {
104  0 Console.warn("Couldn't find a Jpred webservice to invoke!");
105  0 return;
106    }
107  0 SeqCigar[] msf = null;
108  0 SequenceI seq = null;
109  0 int[] delMap = null;
110    // original JNetClient behaviour - submit full length of sequence or profile
111    // and mask result.
112  0 msf = input.getSequences();
113  0 seq = msf[0].getSeq('-');
114   
115  0 if (viewonly)
116    {
117  0 delMap = alview.getVisibleContigMapFor(seq.gapMap());
118    }
119  0 if (msa && msf.length > 1)
120    {
121   
122  0 String altitle = getPredictionName(WebServiceName) + " on "
123  0 + (viewonly ? "visible " : "") + seq.getName()
124    + " using alignment from " + title;
125   
126  0 SequenceI aln[] = new SequenceI[msf.length];
127  0 for (int i = 0, j = msf.length; i < j; i++)
128    {
129  0 aln[i] = msf[i].getSeq('-');
130    }
131   
132  0 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
133    true);
134  0 if (viewonly)
135    {
136    // Remove hidden regions from sequence objects.
137  0 String seqs[] = alview.getSequenceStrings('-');
138  0 for (int i = 0, j = msf.length; i < j; i++)
139    {
140  0 aln[i].setSequence(seqs[i]);
141    }
142  0 seq.setSequence(seqs[0]);
143    }
144  0 wsInfo.setProgressText("Job details for "
145  0 + (viewonly ? "visible " : "") + "MSA based prediction ("
146    + title + ") on sequence :\n>" + seq.getName() + "\n"
147    + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
148    + "\n");
149  0 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
150    SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
151  0 wsInfo.setthisService(jthread);
152  0 jthread.start();
153    }
154    else
155    {
156  0 if (!msa && msf.length > 1)
157    {
158  0 throw new Error(MessageManager.getString(
159    "error.implementation_error_multiple_single_sequence_prediction_jobs_not_supported"));
160    }
161   
162  0 String altitle = getPredictionName(WebServiceName) + " for "
163  0 + (viewonly ? "visible " : "") + "sequence " + seq.getName()
164    + " from " + title;
165  0 String seqname = seq.getName();
166  0 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
167    .SeqCharacterHash(seq);
168  0 if (viewonly)
169    {
170    // Remove hidden regions from input sequence
171  0 String seqs[] = alview.getSequenceStrings('-');
172  0 seq.setSequence(seqs[0]);
173    }
174  0 wsInfo.setProgressText("Job details for prediction on "
175  0 + (viewonly ? "visible " : "") + "sequence :\n>" + seqname
176    + "\n"
177    + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
178    + "\n");
179  0 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
180    SequenceInfo, seq, delMap, alview, parentFrame);
181  0 wsInfo.setthisService(jthread);
182  0 jthread.start();
183    }
184    }
185   
 
186  0 toggle private String getPredictionName(String webServiceName)
187    {
188  0 if (webServiceName.toLowerCase(Locale.ROOT)
189    .indexOf("secondary structure prediction") > -1)
190    {
191  0 return webServiceName;
192    }
193    else
194    {
195  0 return webServiceName + "secondary structure prediction";
196    }
197    }
198   
 
199  0 toggle public JPredClient(ext.vamsas.ServiceHandle sh, String title,
200    SequenceI seq, AlignFrame parentFrame)
201    {
202  0 super();
203  0 wsInfo = setWebService(sh);
204  0 startJPredClient(title, seq, parentFrame);
205    }
206   
 
207  0 toggle public JPredClient(ext.vamsas.ServiceHandle sh, String title,
208    SequenceI[] msa, AlignFrame parentFrame)
209    {
210  0 wsInfo = setWebService(sh);
211  0 startJPredClient(title, msa, parentFrame);
212    }
213   
 
214  0 toggle public JPredClient(String title, SequenceI[] msf)
215    {
216  0 startJPredClient(title, msf, null);
217    }
218   
 
219  0 toggle public JPredClient(String title, SequenceI seq)
220    {
221  0 startJPredClient(title, seq, null);
222    }
223   
 
224  6 toggle public JPredClient()
225    {
226   
227  6 super();
228    // add a class reference to the list
229    }
230   
 
231  0 toggle private void startJPredClient(String title, SequenceI[] msf,
232    AlignFrame parentFrame)
233    {
234  0 if (wsInfo == null)
235    {
236  0 wsInfo = setWebService();
237    }
238   
239  0 SequenceI seq = msf[0];
240   
241  0 String altitle = "JPred prediction on " + seq.getName()
242    + " using alignment from " + title;
243   
244  0 wsInfo.setProgressText("Job details for MSA based prediction (" + title
245    + ") on sequence :\n>" + seq.getName() + "\n"
246    + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
247    + "\n");
248  0 SequenceI aln[] = new SequenceI[msf.length];
249  0 for (int i = 0, j = msf.length; i < j; i++)
250    {
251  0 aln[i] = new jalview.datamodel.Sequence(msf[i]);
252    }
253   
254  0 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
255    true);
256   
257  0 Jpred server = locateWebService();
258  0 if (server == null)
259    {
260  0 return;
261    }
262   
263  0 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
264    SequenceInfo, aln, null, null, parentFrame, WsURL);
265  0 wsInfo.setthisService(jthread);
266  0 jthread.start();
267    }
268   
 
269  0 toggle public void startJPredClient(String title, SequenceI seq,
270    AlignFrame parentFrame)
271    {
272  0 if (wsInfo == null)
273    {
274  0 wsInfo = setWebService();
275    }
276  0 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
277    + seq.getName() + "\n"
278    + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
279    + "\n");
280  0 String altitle = "JPred prediction for sequence " + seq.getName()
281    + " from " + title;
282   
283  0 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
284    .SeqCharacterHash(seq);
285   
286  0 Jpred server = locateWebService();
287  0 if (server == null)
288    {
289  0 return;
290    }
291   
292  0 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
293    SequenceInfo, seq, null, null, parentFrame);
294  0 wsInfo.setthisService(jthread);
295  0 jthread.start();
296    }
297   
 
298  0 toggle private WebserviceInfo setWebService()
299    {
300  0 WebServiceName = "JNetWS";
301  0 WebServiceJobTitle = MessageManager
302    .getString("label.jnet_secondary_structure_prediction");
303  0 WebServiceReference = "\"Cuff J. A and Barton G.J (2000) Application of "
304    + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
305    + "Proteins 40:502-511\".";
306  0 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
307   
308  0 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
309    WebServiceReference, true);
310   
311  0 return wsInfo;
312    }
313   
 
314  0 toggle private ext.vamsas.Jpred locateWebService()
315    {
316  0 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
317  0 ext.vamsas.Jpred server = null;
318  0 try
319    {
320  0 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set
321    // from properties
322  0 ((JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
323    // ((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C,
324    // Boolean.TRUE);
325   
326    } catch (Exception ex)
327    {
328  0 JvOptionPane.showMessageDialog(Desktop.desktop,
329    MessageManager.formatMessage(
330    "label.secondary_structure_prediction_service_couldnt_be_located",
331    new String[]
332    { WebServiceName, WsURL }),
333    MessageManager.getString("label.internal_jalview_error"),
334    JvOptionPane.WARNING_MESSAGE);
335  0 wsInfo.setProgressText(MessageManager.formatMessage(
336    "label.secondary_structure_prediction_service_couldnt_be_located",
337    new String[]
338    { WebServiceName, WsURL }) + "\n" + ex.getMessage());
339  0 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
340   
341    }
342   
343  0 return server;
344    }
345   
 
346  2864 toggle @Override
347    public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
348    final AlignFrame af)
349    {
350  2864 final JMenuItem method = new JMenuItem(sh.getName());
351  2864 method.setToolTipText(sh.getEndpointURL());
352  2864 method.addActionListener(new ActionListener()
353    {
 
354  0 toggle @Override
355    public void actionPerformed(ActionEvent e)
356    {
357  0 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
358  0 if (msa.getSequences().length == 1)
359    {
360    // Single Sequence prediction
361  0 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), false, msa, af,
362    true);
363    }
364    else
365    {
366  0 if (msa.getSequences().length > 1)
367    {
368    // Sequence profile based prediction
369  0 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), true, msa,
370    af, true);
371    }
372    }
373    }
374    });
375  2864 wsmenu.add(method);
376    }
377    }