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.analysis.SeqsetUtils.SequenceInfo;
27 import jalview.bin.Cache;
28 import jalview.datamodel.AlignmentView;
29 import jalview.datamodel.SeqCigar;
30 import jalview.datamodel.SequenceI;
31 import jalview.gui.AlignFrame;
32 import jalview.gui.Desktop;
33 import jalview.gui.JvOptionPane;
34 import jalview.gui.WebserviceInfo;
35 import jalview.util.MessageManager;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.util.Hashtable;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuItem;
45 import ext.vamsas.Jpred;
46 import ext.vamsas.JpredServiceLocator;
47 import ext.vamsas.JpredSoapBindingStub;
48 import ext.vamsas.ServiceHandle;
50 public class JPredClient extends WS1Client
53 * crate a new GUI JPred Job
60 * boolean - true - submit alignment as a sequence profile
66 public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa,
67 AlignmentView alview, AlignFrame parentFrame, boolean viewonly)
70 wsInfo = setWebService(sh);
71 startJPredClient(title, msa, alview, parentFrame, viewonly);
76 * startJPredClient TODO: refine submission to cope with local prediction of
77 * visible regions or multiple single sequence jobs TODO: sequence
78 * representative support - could submit alignment of representatives as msa.
79 * TODO: msa hidden region prediction - submit each chunk for prediction.
80 * concatenate results of each. TODO: single seq prediction - submit each
81 * contig of each sequence for prediction (but must cope with flanking regions
91 * if true then the prediction will be made just on the concatenated
94 private void startJPredClient(String title, boolean msa,
95 jalview.datamodel.AlignmentView alview, AlignFrame parentFrame,
98 AlignmentView input = alview;
101 wsInfo = setWebService();
103 Jpred server = locateWebService();
106 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
109 SeqCigar[] msf = null;
110 SequenceI seq = null;
112 // original JNetClient behaviour - submit full length of sequence or profile
114 msf = input.getSequences();
115 seq = msf[0].getSeq('-');
119 delMap = alview.getVisibleContigMapFor(seq.gapMap());
121 if (msa && msf.length > 1)
124 String altitle = getPredictionName(WebServiceName) + " on "
125 + (viewonly ? "visible " : "") + seq.getName()
126 + " using alignment from " + title;
128 SequenceI aln[] = new SequenceI[msf.length];
129 for (int i = 0, j = msf.length; i < j; i++)
131 aln[i] = msf[i].getSeq('-');
134 Map<String, SequenceInfo> SequenceInfo =
135 jalview.analysis.SeqsetUtils.uniquify(aln, true);
138 // Remove hidden regions from sequence objects.
139 String seqs[] = alview.getSequenceStrings('-');
140 for (int i = 0, j = msf.length; i < j; i++)
142 aln[i].setSequence(seqs[i]);
144 seq.setSequence(seqs[0]);
146 wsInfo.setProgressText("Job details for "
147 + (viewonly ? "visible " : "") + "MSA based prediction ("
148 + title + ") on sequence :\n>" + seq.getName() + "\n"
149 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
151 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
152 SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
153 wsInfo.setthisService(jthread);
158 if (!msa && msf.length > 1)
160 throw new Error(MessageManager.getString(
161 "error.implementation_error_multiple_single_sequence_prediction_jobs_not_supported"));
164 String altitle = getPredictionName(WebServiceName) + " for "
165 + (viewonly ? "visible " : "") + "sequence " + seq.getName()
167 String seqname = seq.getName();
168 SequenceInfo SequenceInfo = jalview.analysis.SeqsetUtils
169 .SeqCharacterHash(seq);
172 // Remove hidden regions from input sequence
173 String seqs[] = alview.getSequenceStrings('-');
174 seq.setSequence(seqs[0]);
176 wsInfo.setProgressText("Job details for prediction on "
177 + (viewonly ? "visible " : "") + "sequence :\n>" + seqname
179 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
181 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
182 SequenceInfo, seq, delMap, alview, parentFrame);
183 wsInfo.setthisService(jthread);
188 private String getPredictionName(String webServiceName)
190 if (webServiceName.toLowerCase(Locale.ROOT)
191 .indexOf("secondary structure prediction") > -1)
193 return webServiceName;
197 return webServiceName + "secondary structure prediction";
201 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
202 SequenceI seq, AlignFrame parentFrame)
205 wsInfo = setWebService(sh);
206 startJPredClient(title, seq, parentFrame);
209 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
210 SequenceI[] msa, AlignFrame parentFrame)
212 wsInfo = setWebService(sh);
213 startJPredClient(title, msa, parentFrame);
216 public JPredClient(String title, SequenceI[] msf)
218 startJPredClient(title, msf, null);
221 public JPredClient(String title, SequenceI seq)
223 startJPredClient(title, seq, null);
230 // add a class reference to the list
233 private void startJPredClient(String title, SequenceI[] msf,
234 AlignFrame parentFrame)
238 wsInfo = setWebService();
241 SequenceI seq = msf[0];
243 String altitle = "JPred prediction on " + seq.getName()
244 + " using alignment from " + title;
246 wsInfo.setProgressText("Job details for MSA based prediction (" + title
247 + ") on sequence :\n>" + seq.getName() + "\n"
248 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
250 SequenceI aln[] = new SequenceI[msf.length];
251 for (int i = 0, j = msf.length; i < j; i++)
253 aln[i] = new jalview.datamodel.Sequence(msf[i]);
256 Map<String, SequenceInfo> SequenceInfo =
257 jalview.analysis.SeqsetUtils.uniquify(aln, true);
259 Jpred server = locateWebService();
265 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
266 SequenceInfo, aln, null, null, parentFrame, WsURL);
267 wsInfo.setthisService(jthread);
271 public void startJPredClient(String title, SequenceI seq,
272 AlignFrame parentFrame)
276 wsInfo = setWebService();
278 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
279 + seq.getName() + "\n"
280 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
282 String altitle = "JPred prediction for sequence " + seq.getName()
285 SequenceInfo SequenceInfo = jalview.analysis.SeqsetUtils
286 .SeqCharacterHash(seq);
288 Jpred server = locateWebService();
294 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
295 SequenceInfo, seq, null, null, parentFrame);
296 wsInfo.setthisService(jthread);
300 private WebserviceInfo setWebService()
302 WebServiceName = "JNetWS";
303 WebServiceJobTitle = MessageManager
304 .getString("label.jnet_secondary_structure_prediction");
305 WebServiceReference = "\"Cuff J. A and Barton G.J (2000) Application of "
306 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
307 + "Proteins 40:502-511\".";
308 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
310 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
311 WebServiceReference, Desktop.FRAME_MAKE_VISIBLE);
316 private ext.vamsas.Jpred locateWebService()
318 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
319 ext.vamsas.Jpred server = null;
322 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set
324 ((JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
325 // ((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C,
328 } catch (Exception ex)
330 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
331 MessageManager.formatMessage(
332 "label.secondary_structure_prediction_service_couldnt_be_located",
334 { WebServiceName, WsURL }),
335 MessageManager.getString("label.internal_jalview_error"),
336 JvOptionPane.WARNING_MESSAGE);
337 wsInfo.setProgressText(MessageManager.formatMessage(
338 "label.secondary_structure_prediction_service_couldnt_be_located",
340 { WebServiceName, WsURL }) + "\n" + ex.getMessage());
341 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
349 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
352 final JMenuItem method = new JMenuItem(sh.getName());
353 method.setToolTipText(sh.getEndpointURL());
354 method.addActionListener(new ActionListener()
357 public void actionPerformed(ActionEvent e)
359 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
360 if (msa.getSequences().length == 1)
362 // Single Sequence prediction
363 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), false, msa, af,
368 if (msa.getSequences().length > 1)
370 // Sequence profile based prediction
371 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), true, msa,