2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws1;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
27 import jalview.analysis.*;
29 import jalview.datamodel.*;
32 public class JPredClient extends WS1Client
35 * crate a new GUI JPred Job
42 * boolean - true - submit alignment as a sequence profile
48 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
49 boolean msa, AlignmentView alview, AlignFrame parentFrame,
53 wsInfo = setWebService(sh);
54 startJPredClient(title, msa, alview, parentFrame, viewonly);
59 * startJPredClient TODO: refine submission to cope with local prediction of
60 * visible regions or multiple single sequence jobs TODO: sequence
61 * representative support - could submit alignment of representatives as msa.
62 * TODO: msa hidden region prediction - submit each chunk for prediction.
63 * concatenate results of each. TODO: single seq prediction - submit each
64 * contig of each sequence for prediction (but must cope with flanking regions
74 * if true then the prediction will be made just on the concatenated
77 private void startJPredClient(String title, boolean msa,
78 jalview.datamodel.AlignmentView alview, AlignFrame parentFrame,
81 AlignmentView input = alview;
84 wsInfo = setWebService();
86 Jpred server = locateWebService();
89 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
92 SeqCigar[] msf = null;
95 // original JNetClient behaviour - submit full length of sequence or profile
97 msf = input.getSequences();
98 seq = msf[0].getSeq('-');
102 int[] viscontigs = alview.getVisibleContigs();
105 if (viscontigs != null)
107 // Construct the delMap - mapping from the positions within the input to
108 // Jnet to the contigs in the original sequence
110 delMap = new int[seq.getEnd() - seq.getStart() + 1];
111 int gapMap[] = seq.gapMap();
112 for (int contig = 0; contig < viscontigs.length; contig += 2)
115 while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
119 while (spos < gapMap.length
120 && gapMap[spos] <= viscontigs[contig + 1])
122 delMap[i++] = spos++;
125 int tmap[] = new int[i];
126 System.arraycopy(delMap, 0, tmap, 0, i);
130 if (msa && msf.length > 1)
133 String altitle = getPredictionName(WebServiceName) + " on "
134 + (viewonly ? "visible " : "") + seq.getName()
135 + " using alignment from " + title;
137 SequenceI aln[] = new SequenceI[msf.length];
138 for (int i = 0, j = msf.length; i < j; i++)
140 aln[i] = msf[i].getSeq('-');
143 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
147 // Remove hidden regions from sequence objects.
148 String seqs[] = alview.getSequenceStrings('-');
149 for (int i = 0, j = msf.length; i < j; i++)
151 aln[i].setSequence(seqs[i]);
153 seq.setSequence(seqs[0]);
155 wsInfo.setProgressText("Job details for "
156 + (viewonly ? "visible " : "") + "MSA based prediction ("
157 + title + ") on sequence :\n>" + seq.getName() + "\n"
158 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
160 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
161 SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
162 wsInfo.setthisService(jthread);
167 if (!msa && msf.length > 1)
170 "Implementation Error! Multiple single sequence prediction jobs are not yet supported.");
173 String altitle = getPredictionName(WebServiceName) + " for "
174 + (viewonly ? "visible " : "") + "sequence " + seq.getName()
176 String seqname = seq.getName();
177 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
178 .SeqCharacterHash(seq);
181 // Remove hidden regions from input sequence
182 String seqs[] = alview.getSequenceStrings('-');
183 seq.setSequence(seqs[0]);
185 wsInfo.setProgressText("Job details for prediction on "
186 + (viewonly ? "visible " : "") + "sequence :\n>" + seqname
188 + AlignSeq.extractGaps("-. ", seq.getSequenceAsString())
190 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
191 SequenceInfo, seq, delMap, alview, parentFrame);
192 wsInfo.setthisService(jthread);
197 private String getPredictionName(String webServiceName)
199 if (webServiceName.toLowerCase().indexOf(
200 "secondary structure prediction") > -1)
202 return webServiceName;
206 return webServiceName + "secondary structure prediction";
210 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
211 SequenceI seq, AlignFrame parentFrame)
214 wsInfo = setWebService(sh);
215 startJPredClient(title, seq, parentFrame);
218 public JPredClient(ext.vamsas.ServiceHandle sh, String title,
219 SequenceI[] msa, AlignFrame parentFrame)
221 wsInfo = setWebService(sh);
222 startJPredClient(title, msa, parentFrame);
225 public JPredClient(String title, SequenceI[] msf)
227 startJPredClient(title, msf, null);
230 public JPredClient(String title, SequenceI seq)
232 startJPredClient(title, seq, null);
239 // add a class reference to the list
242 private void startJPredClient(String title, SequenceI[] msf,
243 AlignFrame parentFrame)
247 wsInfo = setWebService();
250 SequenceI seq = msf[0];
252 String altitle = "JNet prediction on " + seq.getName()
253 + " using alignment from " + title;
256 .setProgressText("Job details for MSA based prediction ("
258 + ") on sequence :\n>"
262 .extractGaps("-. ", seq.getSequenceAsString())
264 SequenceI aln[] = new SequenceI[msf.length];
265 for (int i = 0, j = msf.length; i < j; i++)
267 aln[i] = new jalview.datamodel.Sequence(msf[i]);
270 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln,
273 Jpred server = locateWebService();
279 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
280 SequenceInfo, aln, null, null, parentFrame, WsURL);
281 wsInfo.setthisService(jthread);
285 public void startJPredClient(String title, SequenceI seq,
286 AlignFrame parentFrame)
290 wsInfo = setWebService();
293 .setProgressText("Job details for prediction on sequence :\n>"
297 .extractGaps("-. ", seq.getSequenceAsString())
299 String altitle = "JNet prediction for sequence " + seq.getName()
302 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils
303 .SeqCharacterHash(seq);
305 Jpred server = locateWebService();
311 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
312 SequenceInfo, seq, null, null, parentFrame);
313 wsInfo.setthisService(jthread);
317 private WebserviceInfo setWebService()
319 WebServiceName = "JNetWS";
320 WebServiceJobTitle = "JNet secondary structure prediction";
321 WebServiceReference = "\"Cuff J. A and Barton G.J (2000) Application of "
322 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
323 + "Proteins 40:502-511\".";
324 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
326 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
327 WebServiceReference);
332 private ext.vamsas.Jpred locateWebService()
334 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
335 ext.vamsas.Jpred server = null;
338 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set
340 ((JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
341 // ((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C,
344 } catch (Exception ex)
346 JOptionPane.showMessageDialog(Desktop.desktop,
347 "The Secondary Structure Prediction Service named "
348 + WebServiceName + " at " + WsURL
349 + " couldn't be located.", "Internal Jalview Error",
350 JOptionPane.WARNING_MESSAGE);
351 wsInfo.setProgressText("Serious! " + WebServiceName
352 + " Service location failed\nfor URL :" + WsURL + "\n"
354 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
361 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
364 final JMenuItem method = new JMenuItem(sh.getName());
365 method.setToolTipText(sh.getEndpointURL());
366 method.addActionListener(new ActionListener()
368 public void actionPerformed(ActionEvent e)
370 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
371 if (msa.getSequences().length == 1)
373 // Single Sequence prediction
374 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), false, msa, af,
379 if (msa.getSequences().length > 1)
381 // Sequence profile based prediction
382 new jalview.ws.jws1.JPredClient(sh, af.getTitle(), true, msa, af,