2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.*;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentView;
33 import jalview.util.*;
34 import jalview.ws.WSThread.*;
35 import vamsas.objects.simple.*;
37 public class JPredClient
41 * crate a new GUI JPred Job
42 * @param sh ServiceHandle
44 * @param msa boolean - true - submit alignment as a sequence profile
45 * @param alview AlignmentView
46 * @param viewonly TODO
48 public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa, AlignmentView alview, AlignFrame parentFrame, boolean viewonly) {
50 wsInfo=setWebService(sh);
51 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, AlignFrame parentFrame, boolean viewonly)
68 AlignmentView input = alview;
71 wsInfo = setWebService();
73 Jpred server = locateWebService();
76 Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
82 // original JNetClient behaviour - submit full length of sequence or profile
84 msf = input.getSequences();
85 seq = msf[0].getSeq('-');
88 int[] viscontigs = alview.getVisibleContigs();
91 if (viscontigs!=null) {
92 // Construct the delMap - mapping from the positions within the input to Jnet to the contigs in the original sequence
94 delMap = new int[seq.getEnd()-seq.getStart()+1];
95 int gapMap[] = seq.gapMap();
96 for (int contig = 0; contig<viscontigs.length; contig += 2)
99 while (spos<gapMap.length && gapMap[spos]<viscontigs[contig]) {
102 while (spos<gapMap.length && gapMap[spos]<=viscontigs[contig+1]) {
103 delMap[i++] = spos++;
106 int tmap[] = new int[i];
107 System.arraycopy(delMap, 0, tmap, 0, i);
111 if (msa && msf.length > 1)
114 String altitle = "JNet prediction on "+(viewonly?"visible ":"") + seq.getName() +
115 " using alignment from " + title;
117 SequenceI aln[] = new SequenceI[msf.length];
118 for (int i = 0, j = msf.length; i < j; i++)
120 aln[i] = msf[i].getSeq('-');
124 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
126 // Remove hidden regions from sequence objects.
127 String seqs[] = alview.getSequenceStrings('-');
128 for (int i = 0, j = msf.length; i < j; i++)
130 aln[i].setSequence(seqs[i]);
132 seq.setSequence(seqs[0]);
134 wsInfo.setProgressText("Job details for "+(viewonly?"visible ":"")+"MSA based prediction (" +
135 title + ") on sequence :\n>" + seq.getName() +
137 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
139 JPredThread jthread = new JPredThread(wsInfo, altitle, server,
140 SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
141 wsInfo.setthisService(jthread);
146 if (!msa && msf.length>1)
147 throw new Error("Implementation Error! Multiple single sequence prediction jobs are not yet supported.");
148 String altitle = "JNet prediction for "+(viewonly?"visible ":"")+"sequence " + seq.getName() +
151 String seqname = seq.getName();
152 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(
155 // Remove hidden regions from input sequence
156 String seqs[] = alview.getSequenceStrings('-');
157 seq.setSequence(seqs[0]);
159 wsInfo.setProgressText("Job details for prediction on "+(viewonly?"visible ":"")+"sequence :\n>" +
161 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
163 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
164 SequenceInfo, seq, delMap, alview, parentFrame);
165 wsInfo.setthisService(jthread);
169 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq, AlignFrame parentFrame)
172 wsInfo = setWebService(sh);
173 startJPredClient(title, seq, parentFrame);
176 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa, AlignFrame parentFrame)
178 wsInfo = setWebService(sh);
179 startJPredClient(title, msa, parentFrame);
182 public JPredClient(String title, SequenceI[] msf)
184 startJPredClient(title, msf, null);
187 public JPredClient(String title, SequenceI seq)
189 startJPredClient(title, seq, null);
192 private void startJPredClient(String title, SequenceI[] msf, AlignFrame parentFrame)
196 wsInfo = setWebService();
199 SequenceI seq = msf[0];
201 String altitle = "JNet prediction on " + seq.getName() +
202 " using alignment from " + title;
204 wsInfo.setProgressText("Job details for MSA based prediction (" +
205 title + ") on sequence :\n>" + seq.getName() + "\n" +
206 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
208 SequenceI aln[] = new SequenceI[msf.length];
209 for (int i = 0, j = msf.length; i < j; i++)
211 aln[i] = new jalview.datamodel.Sequence(msf[i]);
214 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
216 Jpred server = locateWebService();
222 JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo, aln,null, null, parentFrame, WsURL);
223 wsInfo.setthisService(jthread);
227 public void startJPredClient(String title, SequenceI seq, AlignFrame parentFrame)
231 wsInfo = setWebService();
233 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
234 seq.getName() + "\n" +
235 AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
237 String altitle = "JNet prediction for sequence " + seq.getName() + " from " +
240 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
242 Jpred server = locateWebService();
248 JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL, SequenceInfo, seq,null, null, parentFrame);
249 wsInfo.setthisService(jthread);
253 private WebserviceInfo setWebService()
255 WebServiceName = "JNetWS";
256 WebServiceJobTitle = "JNet secondary structure prediction";
257 WebServiceReference =
258 "\"Cuff J. A and Barton G.J (2000) Application of " +
259 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
260 "Proteins 40:502-511\".";
261 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
263 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
264 WebServiceReference);
269 private ext.vamsas.Jpred locateWebService()
271 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
272 ext.vamsas.Jpred server=null;
275 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
276 ( (JpredSoapBindingStub)server).setTimeout(60000); // one minute stub
277 //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);
282 JOptionPane.showMessageDialog(Desktop.desktop,
283 "The Secondary Structure Prediction Service named " +
284 WebServiceName + " at " + WsURL +
285 " couldn't be located.",
286 "Internal Jalview Error",
287 JOptionPane.WARNING_MESSAGE);
288 wsInfo.setProgressText("Serious! " + WebServiceName +
289 " Service location failed\nfor URL :" + WsURL +
292 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);