2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
37 * crate a new GUI JPred Job
38 * @param sh ServiceHandle
40 * @param msa boolean - true - submit alignment as a sequence profile
41 * @param alview AlignmentView
42 * @param viewonly TODO
44 public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa,
45 AlignmentView alview, AlignFrame parentFrame,
49 wsInfo = setWebService(sh);
50 startJPredClient(title, msa, alview, parentFrame, viewonly);
56 * TODO: refine submission to cope with local prediction of visible regions or multiple single sequence jobs
57 * TODO: sequence representative support - could submit alignment of representatives as msa.
58 * TODO: msa hidden region prediction - submit each chunk for prediction. concatenate results of each.
59 * TODO: single seq prediction - submit each contig of each sequence for prediction (but must cope with flanking regions and short seqs)
62 * @param alview AlignmentView
63 * @param viewonly if true then the prediction will be made just on the concatenated visible regions
65 private void startJPredClient(String title, boolean msa,
66 jalview.datamodel.AlignmentView alview,
67 AlignFrame parentFrame, boolean viewonly)
69 AlignmentView input = alview;
72 wsInfo = setWebService();
74 Jpred server = locateWebService();
77 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
80 SeqCigar[] msf = null;
83 // original JNetClient behaviour - submit full length of sequence or profile
85 msf = input.getSequences();
86 seq = msf[0].getSeq('-');
90 int[] viscontigs = alview.getVisibleContigs();
93 if (viscontigs != null)
95 // Construct the delMap - mapping from the positions within the input to Jnet to the contigs in the original sequence
97 delMap = new int[seq.getEnd() - seq.getStart() + 1];
98 int gapMap[] = seq.gapMap();
99 for (int contig = 0; contig < viscontigs.length; contig += 2)
102 while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
106 while (spos < gapMap.length && gapMap[spos] <= viscontigs[contig + 1])
108 delMap[i++] = spos++;
111 int tmap[] = new int[i];
112 System.arraycopy(delMap, 0, tmap, 0, i);
116 if (msa && msf.length > 1)
119 String altitle = getPredictionName(WebServiceName)+" on " + (viewonly ? "visible " : "") +
121 " using alignment from " + title;
123 SequenceI aln[] = new SequenceI[msf.length];
124 for (int i = 0, j = msf.length; i < j; i++)
126 aln[i] = msf[i].getSeq('-');
129 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
132 // Remove hidden regions from sequence objects.
133 String seqs[] = alview.getSequenceStrings('-');
134 for (int i = 0, j = msf.length; i < j; i++)
136 aln[i].setSequence(seqs[i]);
138 seq.setSequence(seqs[0]);
140 wsInfo.setProgressText("Job details for " + (viewonly ? "visible " : "") +
141 "MSA based prediction (" +
142 title + ") on sequence :\n>" + seq.getName() +
144 AlignSeq.extractGaps("-. ",
145 seq.getSequenceAsString()) +
147 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
148 SequenceInfo, aln, delMap, alview,
150 wsInfo.setthisService(jthread);
155 if (!msa && msf.length > 1)
157 throw new Error("Implementation Error! Multiple single sequence prediction jobs are not yet supported.");
160 String altitle = getPredictionName(WebServiceName)+" for " + (viewonly ? "visible " : "") +
161 "sequence " + seq.getName() +
164 String seqname = seq.getName();
165 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(
169 // Remove hidden regions from input sequence
170 String seqs[] = alview.getSequenceStrings('-');
171 seq.setSequence(seqs[0]);
173 wsInfo.setProgressText("Job details for prediction on " +
174 (viewonly ? "visible " : "") + "sequence :\n>" +
176 AlignSeq.extractGaps("-. ",
177 seq.getSequenceAsString()) +
179 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
180 SequenceInfo, seq, delMap, alview,
182 wsInfo.setthisService(jthread);
187 private String getPredictionName(String webServiceName)
189 if (webServiceName.toLowerCase().indexOf("secondary structure prediction")>-1)
191 return webServiceName;
193 return webServiceName+"secondary structure prediction";
197 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq,
198 AlignFrame parentFrame)
201 wsInfo = setWebService(sh);
202 startJPredClient(title, seq, parentFrame);
205 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa,
206 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 (" +
243 title + ") on sequence :\n>" + seq.getName() + "\n" +
244 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
246 SequenceI aln[] = new SequenceI[msf.length];
247 for (int i = 0, j = msf.length; i < j; i++)
249 aln[i] = new jalview.datamodel.Sequence(msf[i]);
252 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
254 Jpred server = locateWebService();
260 JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo,
261 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()) +
277 String altitle = "JNet prediction for sequence " + seq.getName() + " from " +
280 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
282 Jpred server = locateWebService();
288 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
289 SequenceInfo, seq, null, null,
291 wsInfo.setthisService(jthread);
295 private WebserviceInfo setWebService()
297 WebServiceName = "JNetWS";
298 WebServiceJobTitle = "JNet secondary structure prediction";
299 WebServiceReference =
300 "\"Cuff J. A and Barton G.J (2000) Application of " +
301 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
302 "Proteins 40:502-511\".";
303 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
305 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
306 WebServiceReference);
311 private ext.vamsas.Jpred locateWebService()
313 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
314 ext.vamsas.Jpred server = null;
317 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
318 ( (JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
319 //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);
324 JOptionPane.showMessageDialog(Desktop.desktop,
325 "The Secondary Structure Prediction Service named " +
326 WebServiceName + " at " + WsURL +
327 " couldn't be located.",
328 "Internal Jalview Error",
329 JOptionPane.WARNING_MESSAGE);
330 wsInfo.setProgressText("Serious! " + WebServiceName +
331 " Service location failed\nfor URL :" + WsURL +
334 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
341 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh, final AlignFrame af)
343 final JMenuItem method = new JMenuItem(sh.getName());
344 method.setToolTipText(sh.getEndpointURL());
345 method.addActionListener(new ActionListener()
347 public void actionPerformed(ActionEvent e)
349 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
350 if (msa.getSequences().length == 1)
352 // Single Sequence prediction
353 new jalview.ws.JPredClient(sh, af.getTitle(), false, msa, af, true);
357 if (msa.getSequences().length > 1)
359 // Sequence profile based prediction
360 new jalview.ws.JPredClient(sh,
361 af.getTitle(), true, msa, af, true);