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
26 import jalview.analysis.*;
28 import jalview.datamodel.*;
31 public class JPredClient
35 * crate a new GUI JPred Job
36 * @param sh ServiceHandle
38 * @param msa boolean - true - submit alignment as a sequence profile
39 * @param alview AlignmentView
40 * @param viewonly TODO
42 public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa,
43 AlignmentView alview, AlignFrame parentFrame,
47 wsInfo = setWebService(sh);
48 startJPredClient(title, msa, alview, parentFrame, viewonly);
54 * TODO: refine submission to cope with local prediction of visible regions or multiple single sequence jobs
55 * TODO: sequence representative support - could submit alignment of representatives as msa.
56 * TODO: msa hidden region prediction - submit each chunk for prediction. concatenate results of each.
57 * TODO: single seq prediction - submit each contig of each sequence for prediction (but must cope with flanking regions and short seqs)
60 * @param alview AlignmentView
61 * @param viewonly if true then the prediction will be made just on the concatenated visible regions
63 private void startJPredClient(String title, boolean msa,
64 jalview.datamodel.AlignmentView alview,
65 AlignFrame parentFrame, boolean viewonly)
67 AlignmentView input = alview;
70 wsInfo = setWebService();
72 Jpred server = locateWebService();
75 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
78 SeqCigar[] msf = null;
81 // original JNetClient behaviour - submit full length of sequence or profile
83 msf = input.getSequences();
84 seq = msf[0].getSeq('-');
88 int[] viscontigs = alview.getVisibleContigs();
91 if (viscontigs != null)
93 // Construct the delMap - mapping from the positions within the input to Jnet to the contigs in the original sequence
95 delMap = new int[seq.getEnd() - seq.getStart() + 1];
96 int gapMap[] = seq.gapMap();
97 for (int contig = 0; contig < viscontigs.length; contig += 2)
100 while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
104 while (spos < gapMap.length && gapMap[spos] <= viscontigs[contig + 1])
106 delMap[i++] = spos++;
109 int tmap[] = new int[i];
110 System.arraycopy(delMap, 0, tmap, 0, i);
114 if (msa && msf.length > 1)
117 String altitle = getPredictionName(WebServiceName)+" on " + (viewonly ? "visible " : "") +
119 " using alignment from " + title;
121 SequenceI aln[] = new SequenceI[msf.length];
122 for (int i = 0, j = msf.length; i < j; i++)
124 aln[i] = msf[i].getSeq('-');
127 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
130 // Remove hidden regions from sequence objects.
131 String seqs[] = alview.getSequenceStrings('-');
132 for (int i = 0, j = msf.length; i < j; i++)
134 aln[i].setSequence(seqs[i]);
136 seq.setSequence(seqs[0]);
138 wsInfo.setProgressText("Job details for " + (viewonly ? "visible " : "") +
139 "MSA based prediction (" +
140 title + ") on sequence :\n>" + seq.getName() +
142 AlignSeq.extractGaps("-. ",
143 seq.getSequenceAsString()) +
145 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
146 SequenceInfo, aln, delMap, alview,
148 wsInfo.setthisService(jthread);
153 if (!msa && msf.length > 1)
155 throw new Error("Implementation Error! Multiple single sequence prediction jobs are not yet supported.");
158 String altitle = getPredictionName(WebServiceName)+" for " + (viewonly ? "visible " : "") +
159 "sequence " + seq.getName() +
162 String seqname = seq.getName();
163 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(
167 // Remove hidden regions from input sequence
168 String seqs[] = alview.getSequenceStrings('-');
169 seq.setSequence(seqs[0]);
171 wsInfo.setProgressText("Job details for prediction on " +
172 (viewonly ? "visible " : "") + "sequence :\n>" +
174 AlignSeq.extractGaps("-. ",
175 seq.getSequenceAsString()) +
177 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
178 SequenceInfo, seq, delMap, alview,
180 wsInfo.setthisService(jthread);
185 private String getPredictionName(String webServiceName)
187 if (webServiceName.toLowerCase().indexOf("secondary structure prediction")>-1)
189 return webServiceName;
191 return webServiceName+"secondary structure prediction";
195 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq,
196 AlignFrame parentFrame)
199 wsInfo = setWebService(sh);
200 startJPredClient(title, seq, parentFrame);
203 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa,
204 AlignFrame parentFrame)
206 wsInfo = setWebService(sh);
207 startJPredClient(title, msa, parentFrame);
210 public JPredClient(String title, SequenceI[] msf)
212 startJPredClient(title, msf, null);
215 public JPredClient(String title, SequenceI seq)
217 startJPredClient(title, seq, null);
220 private void startJPredClient(String title, SequenceI[] msf,
221 AlignFrame parentFrame)
225 wsInfo = setWebService();
228 SequenceI seq = msf[0];
230 String altitle = "JNet prediction on " + seq.getName() +
231 " using alignment from " + title;
233 wsInfo.setProgressText("Job details for MSA based prediction (" +
234 title + ") on sequence :\n>" + seq.getName() + "\n" +
235 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
237 SequenceI aln[] = new SequenceI[msf.length];
238 for (int i = 0, j = msf.length; i < j; i++)
240 aln[i] = new jalview.datamodel.Sequence(msf[i]);
243 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
245 Jpred server = locateWebService();
251 JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo,
252 aln, null, null, parentFrame, WsURL);
253 wsInfo.setthisService(jthread);
257 public void startJPredClient(String title, SequenceI seq,
258 AlignFrame parentFrame)
262 wsInfo = setWebService();
264 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
265 seq.getName() + "\n" +
266 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
268 String altitle = "JNet prediction for sequence " + seq.getName() + " from " +
271 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
273 Jpred server = locateWebService();
279 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
280 SequenceInfo, seq, null, null,
282 wsInfo.setthisService(jthread);
286 private WebserviceInfo setWebService()
288 WebServiceName = "JNetWS";
289 WebServiceJobTitle = "JNet secondary structure prediction";
290 WebServiceReference =
291 "\"Cuff J. A and Barton G.J (2000) Application of " +
292 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
293 "Proteins 40:502-511\".";
294 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
296 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
297 WebServiceReference);
302 private ext.vamsas.Jpred locateWebService()
304 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
305 ext.vamsas.Jpred server = null;
308 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
309 ( (JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
310 //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);
315 JOptionPane.showMessageDialog(Desktop.desktop,
316 "The Secondary Structure Prediction Service named " +
317 WebServiceName + " at " + WsURL +
318 " couldn't be located.",
319 "Internal Jalview Error",
320 JOptionPane.WARNING_MESSAGE);
321 wsInfo.setProgressText("Serious! " + WebServiceName +
322 " Service location failed\nfor URL :" + WsURL +
325 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);