Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.ws.jws1

File JPredClient.java

 

Coverage histogram

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

Code metrics

42
105
14
1
378
277
38
0.36
7.5
14
2.71

Classes

Class Line # Actions
JPredClient 49 105 38
0.043478264.3%
 

Contributing tests

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