2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 java.util.Locale;
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;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.util.Hashtable;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuItem;
43 import ext.vamsas.Jpred;
44 import ext.vamsas.JpredServiceLocator;
45 import ext.vamsas.JpredSoapBindingStub;
46 import ext.vamsas.ServiceHandle;
48 public class JPredClient extends WS1Client
51 * crate a new GUI JPred Job
58 * boolean - true - submit alignment as a sequence profile
64 public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa,
65 AlignmentView alview, AlignFrame parentFrame, boolean viewonly)
68 wsInfo = setWebService(sh);
69 startJPredClient(title, msa, alview, parentFrame, viewonly);
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
89 * if true then the prediction will be made just on the concatenated
92 private void startJPredClient(String title, boolean msa,
93 jalview.datamodel.AlignmentView alview, AlignFrame parentFrame,
96 AlignmentView input = alview;
99 wsInfo = setWebService();
101 Jpred server = locateWebService();
104 Console.warn("Couldn't find a Jpred webservice to invoke!");
107 SeqCigar[] msf = null;
108 SequenceI seq = null;
110 // original JNetClient behaviour - submit full length of sequence or profile
112 msf = input.getSequences();
113 seq = msf[0].getSeq('-');
117 delMap = alview.getVisibleContigMapFor(seq.gapMap());
119 if (msa && msf.length > 1)
122 String altitle = getPredictionName(WebServiceName) + " on "
123 + (viewonly ? "visible " : "") + seq.getName()
124 + " using alignment from " + title;
126 SequenceI aln[] = new SequenceI[msf.length];
127 for (int i = 0, j = msf.length; i < j; i++)
129 aln[i] = msf[i].getSeq('-');
132 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
136 // Remove hidden regions from sequence objects.
137 String seqs[] = alview.getSequenceStrings('-');
138 for (int i = 0, j = msf.length; i < j; i++)
140 aln[i].setSequence(seqs[i]);
142 seq.setSequence(seqs[0]);
144 wsInfo.setProgressText("Job details for "
145 + (viewonly ? "visible " : "") + "MSA based prediction ("
146 + title + ") on sequence :\n>" + seq.getName() + "\n"
147 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
149 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
150 SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
151 wsInfo.setthisService(jthread);
156 if (!msa && msf.length > 1)
158 throw new Error(MessageManager.getString(
159 "error.implementation_error_multiple_single_sequence_prediction_jobs_not_supported"));
162 String altitle = getPredictionName(WebServiceName) + " for "
163 + (viewonly ? "visible " : "") + "sequence " + seq.getName()
165 String seqname = seq.getName();
166 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
167 .SeqCharacterHash(seq);
170 // Remove hidden regions from input sequence
171 String seqs[] = alview.getSequenceStrings('-');
172 seq.setSequence(seqs[0]);
174 wsInfo.setProgressText("Job details for prediction on "
175 + (viewonly ? "visible " : "") + "sequence :\n>" + seqname
177 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
179 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
180 SequenceInfo, seq, delMap, alview, parentFrame);
181 wsInfo.setthisService(jthread);
186 private String getPredictionName(String webServiceName)
188 if (webServiceName.toLowerCase(Locale.ROOT)
189 .indexOf("secondary structure prediction") > -1)
191 return webServiceName;
195 return webServiceName + "secondary structure prediction";
199 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
200 SequenceI seq, AlignFrame parentFrame)
203 wsInfo = setWebService(sh);
204 startJPredClient(title, seq, parentFrame);
207 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
208 SequenceI[] msa, AlignFrame parentFrame)
210 wsInfo = setWebService(sh);
211 startJPredClient(title, msa, parentFrame);
214 public JPredClient(String title, SequenceI[] msf)
216 startJPredClient(title, msf, null);
219 public JPredClient(String title, SequenceI seq)
221 startJPredClient(title, seq, null);
228 // add a class reference to the list
231 private void startJPredClient(String title, SequenceI[] msf,
232 AlignFrame parentFrame)
236 wsInfo = setWebService();
239 SequenceI seq = msf[0];
241 String altitle = "JPred prediction on " + seq.getName()
242 + " using alignment from " + title;
244 wsInfo.setProgressText("Job details for MSA based prediction (" + title
245 + ") on sequence :\n>" + seq.getName() + "\n"
246 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
248 SequenceI aln[] = new SequenceI[msf.length];
249 for (int i = 0, j = msf.length; i < j; i++)
251 aln[i] = new jalview.datamodel.Sequence(msf[i]);
254 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
257 Jpred server = locateWebService();
263 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
264 SequenceInfo, aln, null, null, parentFrame, WsURL);
265 wsInfo.setthisService(jthread);
269 public void startJPredClient(String title, SequenceI seq,
270 AlignFrame parentFrame)
274 wsInfo = setWebService();
276 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
277 + seq.getName() + "\n"
278 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
280 String altitle = "JPred prediction for sequence " + seq.getName()
283 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
284 .SeqCharacterHash(seq);
286 Jpred server = locateWebService();
292 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
293 SequenceInfo, seq, null, null, parentFrame);
294 wsInfo.setthisService(jthread);
298 private WebserviceInfo setWebService()
300 WebServiceName = "JNetWS";
301 WebServiceJobTitle = MessageManager
302 .getString("label.jnet_secondary_structure_prediction");
303 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 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
308 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
309 WebServiceReference, true);
314 private ext.vamsas.Jpred locateWebService()
316 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
317 ext.vamsas.Jpred server = null;
320 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set
322 ((JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
323 // ((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C,
326 } catch (Exception ex)
328 JvOptionPane.showMessageDialog(Desktop.desktop,
329 MessageManager.formatMessage(
330 "label.secondary_structure_prediction_service_couldnt_be_located",
332 { WebServiceName, WsURL }),
333 MessageManager.getString("label.internal_jalview_error"),
334 JvOptionPane.WARNING_MESSAGE);
335 wsInfo.setProgressText(MessageManager.formatMessage(
336 "label.secondary_structure_prediction_service_couldnt_be_located",
338 { WebServiceName, WsURL }) + "\n" + ex.getMessage());
339 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
347 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
350 final JMenuItem method = new JMenuItem(sh.getName());
351 method.setToolTipText(sh.getEndpointURL());
352 method.addActionListener(new ActionListener()
355 public void actionPerformed(ActionEvent e)
357 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
358 if (msa.getSequences().length == 1)
360 // Single Sequence prediction
361 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), false, msa, af,
366 if (msa.getSequences().length > 1)
368 // Sequence profile based prediction
369 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), true, msa,