2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
28 import jalview.analysis.*;
30 import jalview.datamodel.*;
33 public class JPredClient extends WSClient
36 * crate a new GUI JPred Job
43 * boolean - true - submit alignment as a sequence profile
49 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
50 boolean msa, AlignmentView alview, AlignFrame parentFrame,
54 wsInfo = setWebService(sh);
55 startJPredClient(title, msa, alview, parentFrame, viewonly);
60 * startJPredClient TODO: refine submission to cope with local prediction of
61 * visible regions or multiple single sequence jobs TODO: sequence
62 * representative support - could submit alignment of representatives as msa.
63 * TODO: msa hidden region prediction - submit each chunk for prediction.
64 * concatenate results of each. TODO: single seq prediction - submit each
65 * contig of each sequence for prediction (but must cope with flanking regions
75 * if true then the prediction will be made just on the
76 * concatenated visible regions
78 private void startJPredClient(String title, boolean msa,
79 jalview.datamodel.AlignmentView alview, AlignFrame parentFrame,
82 AlignmentView input = alview;
85 wsInfo = setWebService();
87 Jpred server = locateWebService();
90 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
93 SeqCigar[] msf = null;
96 // original JNetClient behaviour - submit full length of sequence or profile
98 msf = input.getSequences();
99 seq = msf[0].getSeq('-');
103 int[] viscontigs = alview.getVisibleContigs();
106 if (viscontigs != null)
108 // Construct the delMap - mapping from the positions within the input to
109 // Jnet to the contigs in the original sequence
111 delMap = new int[seq.getEnd() - seq.getStart() + 1];
112 int gapMap[] = seq.gapMap();
113 for (int contig = 0; contig < viscontigs.length; contig += 2)
116 while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
120 while (spos < gapMap.length
121 && gapMap[spos] <= viscontigs[contig + 1])
123 delMap[i++] = spos++;
126 int tmap[] = new int[i];
127 System.arraycopy(delMap, 0, tmap, 0, i);
131 if (msa && msf.length > 1)
134 String altitle = getPredictionName(WebServiceName) + " on "
135 + (viewonly ? "visible " : "") + seq.getName()
136 + " using alignment from " + title;
138 SequenceI aln[] = new SequenceI[msf.length];
139 for (int i = 0, j = msf.length; i < j; i++)
141 aln[i] = msf[i].getSeq('-');
144 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
148 // Remove hidden regions from sequence objects.
149 String seqs[] = alview.getSequenceStrings('-');
150 for (int i = 0, j = msf.length; i < j; i++)
152 aln[i].setSequence(seqs[i]);
154 seq.setSequence(seqs[0]);
156 wsInfo.setProgressText("Job details for "
157 + (viewonly ? "visible " : "") + "MSA based prediction ("
158 + title + ") on sequence :\n>" + seq.getName() + "\n"
159 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
161 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
162 SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
163 wsInfo.setthisService(jthread);
168 if (!msa && msf.length > 1)
171 "Implementation Error! Multiple single sequence prediction jobs are not yet supported.");
174 String altitle = getPredictionName(WebServiceName) + " for "
175 + (viewonly ? "visible " : "") + "sequence " + seq.getName()
177 String seqname = seq.getName();
178 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
179 .SeqCharacterHash(seq);
182 // Remove hidden regions from input sequence
183 String seqs[] = alview.getSequenceStrings('-');
184 seq.setSequence(seqs[0]);
186 wsInfo.setProgressText("Job details for prediction on "
187 + (viewonly ? "visible " : "") + "sequence :\n>" + seqname
189 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
191 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
192 SequenceInfo, seq, delMap, alview, parentFrame);
193 wsInfo.setthisService(jthread);
198 private String getPredictionName(String webServiceName)
200 if (webServiceName.toLowerCase().indexOf(
201 "secondary structure prediction") > -1)
203 return webServiceName;
207 return webServiceName + "secondary structure prediction";
211 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
212 SequenceI seq, AlignFrame parentFrame)
215 wsInfo = setWebService(sh);
216 startJPredClient(title, seq, parentFrame);
219 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
220 SequenceI[] msa, AlignFrame parentFrame)
222 wsInfo = setWebService(sh);
223 startJPredClient(title, msa, parentFrame);
226 public JPredClient(String title, SequenceI[] msf)
228 startJPredClient(title, msf, null);
231 public JPredClient(String title, SequenceI seq)
233 startJPredClient(title, seq, null);
240 // add a class reference to the list
243 private void startJPredClient(String title, SequenceI[] msf,
244 AlignFrame parentFrame)
248 wsInfo = setWebService();
251 SequenceI seq = msf[0];
253 String altitle = "JNet prediction on " + seq.getName()
254 + " using alignment from " + title;
257 .setProgressText("Job details for MSA based prediction ("
259 + ") on sequence :\n>"
263 .extractGaps("-. ", seq.getSequenceAsString())
265 SequenceI aln[] = new SequenceI[msf.length];
266 for (int i = 0, j = msf.length; i < j; i++)
268 aln[i] = new jalview.datamodel.Sequence(msf[i]);
271 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
274 Jpred server = locateWebService();
280 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
281 SequenceInfo, aln, null, null, parentFrame, WsURL);
282 wsInfo.setthisService(jthread);
286 public void startJPredClient(String title, SequenceI seq,
287 AlignFrame parentFrame)
291 wsInfo = setWebService();
294 .setProgressText("Job details for prediction on sequence :\n>"
298 .extractGaps("-. ", seq.getSequenceAsString())
300 String altitle = "JNet prediction for sequence " + seq.getName()
303 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
304 .SeqCharacterHash(seq);
306 Jpred server = locateWebService();
312 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
313 SequenceInfo, seq, null, null, parentFrame);
314 wsInfo.setthisService(jthread);
318 private WebserviceInfo setWebService()
320 WebServiceName = "JNetWS";
321 WebServiceJobTitle = "JNet secondary structure prediction";
322 WebServiceReference = "\"Cuff J. A and Barton G.J (2000) Application of "
323 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
324 + "Proteins 40:502-511\".";
325 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
327 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
328 WebServiceReference);
333 private ext.vamsas.Jpred locateWebService()
335 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
336 ext.vamsas.Jpred server = null;
339 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set
341 ((JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
342 // ((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C,
345 } catch (Exception ex)
347 JOptionPane.showMessageDialog(Desktop.desktop,
348 "The Secondary Structure Prediction Service named "
349 + WebServiceName + " at " + WsURL
350 + " couldn't be located.", "Internal Jalview Error",
351 JOptionPane.WARNING_MESSAGE);
352 wsInfo.setProgressText("Serious! " + WebServiceName
353 + " Service location failed\nfor URL :" + WsURL + "\n"
355 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
362 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
365 final JMenuItem method = new JMenuItem(sh.getName());
366 method.setToolTipText(sh.getEndpointURL());
367 method.addActionListener(new ActionListener()
369 public void actionPerformed(ActionEvent e)
371 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
372 if (msa.getSequences().length == 1)
374 // Single Sequence prediction
375 new jalview.ws.JPredClient(sh, af.getTitle(), false, msa, af,
380 if (msa.getSequences().length > 1)
382 // Sequence profile based prediction
383 new jalview.ws.JPredClient(sh, af.getTitle(), true, msa, af,