Clover icon

jalviewX

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

File JPredClient.java

 

Coverage histogram

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

Code metrics

42
105
14
1
375
274
38
0.36
7.5
14
2.71

Classes

Class Line # Actions
JPredClient 46 105 38 154
0.043478264.3%
 

Contributing tests

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