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 = "JNet prediction 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.");
157 String altitle = "JNet prediction for " + (viewonly ? "visible " : "") +
158 "sequence " + seq.getName() +
161 String seqname = seq.getName();
162 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(
166 // Remove hidden regions from input sequence
167 String seqs[] = alview.getSequenceStrings('-');
168 seq.setSequence(seqs[0]);
170 wsInfo.setProgressText("Job details for prediction on " +
171 (viewonly ? "visible " : "") + "sequence :\n>" +
173 AlignSeq.extractGaps("-. ",
174 seq.getSequenceAsString()) +
176 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
177 SequenceInfo, seq, delMap, alview,
179 wsInfo.setthisService(jthread);
184 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq,
185 AlignFrame parentFrame)
188 wsInfo = setWebService(sh);
189 startJPredClient(title, seq, parentFrame);
192 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa,
193 AlignFrame parentFrame)
195 wsInfo = setWebService(sh);
196 startJPredClient(title, msa, parentFrame);
199 public JPredClient(String title, SequenceI[] msf)
201 startJPredClient(title, msf, null);
204 public JPredClient(String title, SequenceI seq)
206 startJPredClient(title, seq, null);
209 private void startJPredClient(String title, SequenceI[] msf,
210 AlignFrame parentFrame)
214 wsInfo = setWebService();
217 SequenceI seq = msf[0];
219 String altitle = "JNet prediction on " + seq.getName() +
220 " using alignment from " + title;
222 wsInfo.setProgressText("Job details for MSA based prediction (" +
223 title + ") on sequence :\n>" + seq.getName() + "\n" +
224 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
226 SequenceI aln[] = new SequenceI[msf.length];
227 for (int i = 0, j = msf.length; i < j; i++)
229 aln[i] = new jalview.datamodel.Sequence(msf[i]);
232 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
234 Jpred server = locateWebService();
240 JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo,
241 aln, null, null, parentFrame, WsURL);
242 wsInfo.setthisService(jthread);
246 public void startJPredClient(String title, SequenceI seq,
247 AlignFrame parentFrame)
251 wsInfo = setWebService();
253 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
254 seq.getName() + "\n" +
255 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
257 String altitle = "JNet prediction for sequence " + seq.getName() + " from " +
260 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
262 Jpred server = locateWebService();
268 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
269 SequenceInfo, seq, null, null,
271 wsInfo.setthisService(jthread);
275 private WebserviceInfo setWebService()
277 WebServiceName = "JNetWS";
278 WebServiceJobTitle = "JNet secondary structure prediction";
279 WebServiceReference =
280 "\"Cuff J. A and Barton G.J (2000) Application of " +
281 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
282 "Proteins 40:502-511\".";
283 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
285 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
286 WebServiceReference);
291 private ext.vamsas.Jpred locateWebService()
293 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
294 ext.vamsas.Jpred server = null;
297 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
298 ( (JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
299 //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);
304 JOptionPane.showMessageDialog(Desktop.desktop,
305 "The Secondary Structure Prediction Service named " +
306 WebServiceName + " at " + WsURL +
307 " couldn't be located.",
308 "Internal Jalview Error",
309 JOptionPane.WARNING_MESSAGE);
310 wsInfo.setProgressText("Serious! " + WebServiceName +
311 " Service location failed\nfor URL :" + WsURL +
314 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);