2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.jws1;
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.WebserviceInfo;
31 import jalview.util.MessageManager;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.util.Hashtable;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuItem;
39 import javax.swing.JOptionPane;
41 import ext.vamsas.Jpred;
42 import ext.vamsas.JpredServiceLocator;
43 import ext.vamsas.JpredSoapBindingStub;
44 import ext.vamsas.ServiceHandle;
46 public class JPredClient extends WS1Client
49 * crate a new GUI JPred Job
56 * boolean - true - submit alignment as a sequence profile
62 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
63 boolean msa, AlignmentView alview, AlignFrame parentFrame,
67 wsInfo = setWebService(sh);
68 startJPredClient(title, msa, alview, parentFrame, viewonly);
73 * startJPredClient TODO: refine submission to cope with local prediction of
74 * visible regions or multiple single sequence jobs TODO: sequence
75 * representative support - could submit alignment of representatives as msa.
76 * TODO: msa hidden region prediction - submit each chunk for prediction.
77 * concatenate results of each. TODO: single seq prediction - submit each
78 * contig of each sequence for prediction (but must cope with flanking regions
88 * if true then the prediction will be made just on the concatenated
91 private void startJPredClient(String title, boolean msa,
92 jalview.datamodel.AlignmentView alview, AlignFrame parentFrame,
95 AlignmentView input = alview;
98 wsInfo = setWebService();
100 Jpred server = locateWebService();
103 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
106 SeqCigar[] msf = null;
107 SequenceI seq = null;
109 // original JNetClient behaviour - submit full length of sequence or profile
111 msf = input.getSequences();
112 seq = msf[0].getSeq('-');
116 delMap = alview.getVisibleContigMapFor(seq.gapMap());
118 if (msa && msf.length > 1)
121 String altitle = getPredictionName(WebServiceName) + " on "
122 + (viewonly ? "visible " : "") + seq.getName()
123 + " using alignment from " + title;
125 SequenceI aln[] = new SequenceI[msf.length];
126 for (int i = 0, j = msf.length; i < j; i++)
128 aln[i] = msf[i].getSeq('-');
131 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
135 // Remove hidden regions from sequence objects.
136 String seqs[] = alview.getSequenceStrings('-');
137 for (int i = 0, j = msf.length; i < j; i++)
139 aln[i].setSequence(seqs[i]);
141 seq.setSequence(seqs[0]);
143 wsInfo.setProgressText("Job details for "
144 + (viewonly ? "visible " : "") + "MSA based prediction ("
145 + title + ") on sequence :\n>" + seq.getName() + "\n"
146 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
148 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
149 SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
150 wsInfo.setthisService(jthread);
155 if (!msa && msf.length > 1)
157 throw new Error(MessageManager.getString("error.implementation_error_multiple_single_sequence_prediction_jobs_not_supported"));
160 String altitle = getPredictionName(WebServiceName) + " for "
161 + (viewonly ? "visible " : "") + "sequence " + seq.getName()
163 String seqname = seq.getName();
164 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
165 .SeqCharacterHash(seq);
168 // Remove hidden regions from input sequence
169 String seqs[] = alview.getSequenceStrings('-');
170 seq.setSequence(seqs[0]);
172 wsInfo.setProgressText("Job details for prediction on "
173 + (viewonly ? "visible " : "") + "sequence :\n>" + seqname
175 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
177 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
178 SequenceInfo, seq, delMap, alview, parentFrame);
179 wsInfo.setthisService(jthread);
184 private String getPredictionName(String webServiceName)
186 if (webServiceName.toLowerCase().indexOf(
187 "secondary structure prediction") > -1)
189 return webServiceName;
193 return webServiceName + "secondary structure prediction";
197 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
198 SequenceI seq, AlignFrame parentFrame)
201 wsInfo = setWebService(sh);
202 startJPredClient(title, seq, parentFrame);
205 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
206 SequenceI[] msa, AlignFrame parentFrame)
208 wsInfo = setWebService(sh);
209 startJPredClient(title, msa, parentFrame);
212 public JPredClient(String title, SequenceI[] msf)
214 startJPredClient(title, msf, null);
217 public JPredClient(String title, SequenceI seq)
219 startJPredClient(title, seq, null);
226 // add a class reference to the list
229 private void startJPredClient(String title, SequenceI[] msf,
230 AlignFrame parentFrame)
234 wsInfo = setWebService();
237 SequenceI seq = msf[0];
239 String altitle = "JNet prediction on " + seq.getName()
240 + " using alignment from " + title;
242 wsInfo.setProgressText("Job details for MSA based prediction (" + title
243 + ") on sequence :\n>" + seq.getName() + "\n"
244 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) + "\n");
245 SequenceI aln[] = new SequenceI[msf.length];
246 for (int i = 0, j = msf.length; i < j; i++)
248 aln[i] = new jalview.datamodel.Sequence(msf[i]);
251 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
254 Jpred server = locateWebService();
260 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
261 SequenceInfo, aln, null, null, parentFrame, WsURL);
262 wsInfo.setthisService(jthread);
266 public void startJPredClient(String title, SequenceI seq,
267 AlignFrame parentFrame)
271 wsInfo = setWebService();
273 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
274 + seq.getName() + "\n"
275 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) + "\n");
276 String altitle = "JNet prediction for sequence " + seq.getName()
279 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
280 .SeqCharacterHash(seq);
282 Jpred server = locateWebService();
288 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
289 SequenceInfo, seq, null, null, parentFrame);
290 wsInfo.setthisService(jthread);
294 private WebserviceInfo setWebService()
296 WebServiceName = "JNetWS";
297 WebServiceJobTitle = MessageManager.getString("label.jnet_secondary_structure_prediction");
298 WebServiceReference = "\"Cuff J. A and Barton G.J (2000) Application of "
299 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
300 + "Proteins 40:502-511\".";
301 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
303 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
304 WebServiceReference, true);
309 private ext.vamsas.Jpred locateWebService()
311 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
312 ext.vamsas.Jpred server = null;
315 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set
317 ((JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
318 // ((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C,
321 } catch (Exception ex)
323 JOptionPane.showMessageDialog(Desktop.desktop,
324 MessageManager.formatMessage("label.secondary_structure_prediction_service_couldnt_be_located", new String[]{WebServiceName,WsURL}),
325 MessageManager.getString("label.internal_jalview_error"),
326 JOptionPane.WARNING_MESSAGE);
327 wsInfo.setProgressText(MessageManager.formatMessage("label.secondary_structure_prediction_service_couldnt_be_located", new String[]{WebServiceName,WsURL})
330 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
337 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
340 final JMenuItem method = new JMenuItem(sh.getName());
341 method.setToolTipText(sh.getEndpointURL());
342 method.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
347 if (msa.getSequences().length == 1)
349 // Single Sequence prediction
350 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), false, msa,
355 if (msa.getSequences().length > 1)
357 // Sequence profile based prediction
358 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), true, msa,