2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
22 import org.apache.axis.client.*;
\r
23 import javax.xml.namespace.QName;
\r
25 import jalview.datamodel.*;
\r
26 import jalview.gui.*;
\r
27 import javax.swing.*;
\r
30 import jalview.analysis.AlignSeq;
\r
31 import ext.vamsas.*;
\r
33 public class JPredClient
\r
36 ext.vamsas.JPredWS server;
\r
37 String altitle = "";
\r
38 java.util.Hashtable SequenceInfo = null;
\r
39 private WebserviceInfo setWebService()
\r
41 WebServiceName = "JNetWS";
\r
42 WebServiceJobTitle = "JNet secondary structure prediction";
\r
43 WebServiceReference =
\r
44 "\"Cuff J. A and Barton G.J (1999) Application of enhanced "
\r
45 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
\r
46 + "Proteins 40:502-511\".";
\r
47 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
48 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
\r
49 WebServiceReference);
\r
54 private boolean locateWebService()
\r
57 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
60 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
61 ( (JpredSoapBindingStub)this.server).setTimeout(60000); // one minute stub
\r
63 catch (Exception ex)
\r
65 JOptionPane.showMessageDialog(Desktop.desktop,
\r
66 "The Secondary Structure Prediction Service named "
\r
67 + WebServiceName + " at " + WsURL +
\r
68 " couldn't be located.",
\r
69 "Internal Jalview Error",
\r
70 JOptionPane.WARNING_MESSAGE);
\r
71 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
72 " Service location failed\nfor URL :"
\r
73 + WsURL + "\n" + ex.getMessage());
\r
74 wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR);
\r
80 public JPredClient(String title, SequenceI[] msf)
\r
82 wsInfo = setWebService();
\r
83 SequenceI seq = msf[0];
\r
84 altitle = "JNet prediction on " + seq.getName() +
\r
85 " using alignment from " + title;
\r
87 wsInfo.setProgressText("Job details for MSA based prediction (" + title +
\r
88 ") on sequence :\n>"
\r
89 + seq.getName() + "\n"
\r
90 + AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
93 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
94 if (!locateWebService())
\r
97 JPredThread jthread = new JPredThread(msf);
\r
101 public JPredClient(String title, SequenceI seq)
\r
103 wsInfo = setWebService();
\r
104 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
\r
105 + seq.getName() + "\n" +
\r
106 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
108 altitle = "JNet prediction for sequence " + seq.getName() + " from " +
\r
111 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
113 if (!locateWebService())
\r
116 JPredThread jthread = new JPredThread(seq);
\r
123 String OutputHeader;
\r
124 ext.vamsas.JpredResult result;
\r
125 ext.vamsas.Sequence sequence;
\r
126 ext.vamsas.Msfalignment msa;
\r
128 boolean jobComplete = false;
\r
129 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
130 JPredThread(SequenceI seq)
\r
132 OutputHeader = wsInfo.getProgressText();
\r
133 this.sequence = new ext.vamsas.Sequence();
\r
134 this.sequence.setId(seq.getName());
\r
135 this.sequence.setSeq(AlignSeq.extractGaps("-. ", seq.getSequence()));
\r
138 JPredThread(SequenceI[] msf)
\r
140 OutputHeader = wsInfo.getProgressText();
\r
141 this.sequence = new ext.vamsas.Sequence();
\r
142 this.sequence.setId(msf[0].getName());
\r
143 this.sequence.setSeq(AlignSeq.extractGaps("-. ", msf[0].getSequence()));
\r
144 jalview.io.PileUpfile mwrite = new jalview.io.PileUpfile();
\r
145 this.msa = new ext.vamsas.Msfalignment();
\r
146 msa.setMsf(mwrite.print(msf));
\r
154 while (!jobComplete && (allowedServerExceptions > 0))
\r
158 if ( (result = server.getresult(jobId)) == null)
\r
160 throw (new Exception(
\r
161 "Timed out when communicating with server\nTry again later.\n"));
\r
164 if (result.isRunning())
\r
166 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
168 else if (result.isQueued())
\r
170 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
173 if (result.isFinished())
\r
176 jobComplete = true;
\r
181 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
\r
182 if (! (result.isJobFailed() || result.isServerError()))
\r
186 Thread.sleep(5000);
\r
188 catch (InterruptedException ex1)
\r
191 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
195 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
199 catch (Exception ex)
\r
201 allowedServerExceptions--;
\r
202 wsInfo.appendProgressText("\nJPredWS Server exception!\n" +
\r
206 if (allowedServerExceptions > 0)
\r
208 Thread.sleep(5000);
\r
211 catch (InterruptedException ex1)
\r
217 if (! (result.isJobFailed() || result.isServerError()))
\r
219 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
223 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
233 jobId = server.predictOnMsa(msa);
\r
237 jobId = server.predict(sequence);
\r
241 if (jobId.startsWith("Broken"))
\r
243 throw new Exception("Submission " + jobId);
\r
247 System.out.println(WsURL + " Job Id '" + jobId + "'");
\r
252 throw new Exception("Server timed out - try again later\n");
\r
256 catch (Exception e)
\r
258 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
259 allowedServerExceptions = 0;
\r
260 jobComplete = false;
\r
261 wsInfo.appendProgressText("Failed to submit the prediction: " +
\r
262 e.toString() + "\nJust close the window\n");
\r
263 System.err.println(
\r
264 "JPredWS Client: Failed to submit the prediction\n" +
\r
265 e.toString() + "\n");
\r
266 // e.printStackTrace(); TODO: JBPNote DEBUG
\r
270 private void addFloatAnnotations(Alignment al, int[] gapmap,
\r
271 Vector values, String Symname,
\r
272 String Visname, float min, float max,
\r
276 Annotation[] annotations = new Annotation[al.getWidth()];
\r
277 for (int j = 0; j < values.size(); j++)
\r
279 float value = Float.parseFloat(values.get(j).toString());
\r
280 annotations[gapmap[j]] = new Annotation("", value + "", ' ', value);
\r
282 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations,
\r
283 min, max, winLength));
\r
288 // OutputHeader = output.getText();
\r
289 if (result.isFailed())
\r
291 OutputHeader += "Job failed.\n";
\r
293 if (result.getStatus() != null)
\r
295 OutputHeader += "\n" + result.getStatus();
\r
297 if (result.getPredfile() != null)
\r
299 OutputHeader += "\n" + result.getPredfile();
\r
300 // JBPNote The returned files from a webservice could be hidden behind icons in the monitor window that, when clicked, pop up their corresponding data
\r
302 if (result.getAligfile() != null)
\r
304 OutputHeader += "\n" + result.getAligfile();
\r
306 wsInfo.setProgressText(OutputHeader);
\r
309 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
310 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.
\r
311 getPredfile(), "Paste");
\r
312 SequenceI[] preds = prediction.getSeqsAsArray();
\r
314 int FirstSeq; // the position of the query sequence in Alignment al
\r
315 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
317 if (this.msa != null && result.getAligfile() != null)
\r
319 // we ignore the returned alignment if we only predicted on a single sequence
\r
320 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(),
\r
322 if (jalview.io.FormatAdapter.formats.contains(format))
\r
324 al = new Alignment(jalview.io.FormatAdapter.readFile(result.
\r
325 getAligfile(), "Paste", format));
\r
331 throw (new Exception("Unknown format 'format' for file : \n" +
\r
332 result.getAligfile()));
\r
338 al = new Alignment(preds);
\r
339 FirstSeq = prediction.getQuerySeqPosition();
\r
342 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(al.getSequenceAt(
\r
343 FirstSeq), SequenceInfo))
\r
345 throw (new Exception(
\r
346 "Couldn't recover sequence properties for JNet Query sequence!"));
\r
349 AlignmentAnnotation annot;
\r
350 Annotation[] annotations = null;
\r
352 int width = preds[0].getSequence().length();
\r
354 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
356 if (gapmap.length != width)
\r
358 throw (new Exception(
\r
359 "Jnet Client Error\nNumber of residues in supposed query sequence :\n"
\r
360 + al.getSequenceAt(FirstSeq).getName() + "\n"
\r
361 + al.getSequenceAt(FirstSeq).getSequence()
\r
362 + "\nDiffer from number of prediction sites in \n" +
\r
363 result.getPredfile() + "\n"));
\r
365 // JBPNote Should also rename the query sequence sometime...
\r
367 while (i < preds.length)
\r
369 String id = preds[i].getName().toUpperCase();
\r
370 if (id.startsWith("LUPAS") || id.startsWith("JNET") ||
\r
371 id.startsWith("JPRED"))
\r
373 annotations = new Annotation[al.getWidth()];
\r
375 if (id.equals("JNETPRED")
\r
376 || id.equals("JNETPSSM")
\r
377 || id.equals("JNETFREQ")
\r
378 || id.equals("JNETHMM")
\r
379 || id.equals("JNETALIGN")
\r
380 || id.equals("JPRED"))
\r
382 for (int j = 0; j < width; j++)
\r
384 annotations[gapmap[j]] = new Annotation("", "",
\r
385 preds[i].getCharAt(j), 0);
\r
388 else if (id.equals("JNETCONF"))
\r
390 for (int j = 0; j < width; j++)
\r
392 float value = Float.parseFloat(preds[i].getCharAt(j) + "");
\r
393 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j) +
\r
394 "", "", preds[i].getCharAt(j), value);
\r
399 for (int j = 0; j < width; j++)
\r
401 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j) +
\r
406 if (id.equals("JNETCONF"))
\r
408 annot = new AlignmentAnnotation(preds[i].getName(),
\r
410 annotations, 0f, 10f, 1);
\r
415 annot = new AlignmentAnnotation(preds[i].getName(),
\r
419 al.addAnnotation(annot);
\r
422 al.deleteSequence(preds[i]);
\r
428 Hashtable scores = prediction.getScores();
\r
429 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
430 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
432 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
433 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
435 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
436 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
438 AlignFrame af = new AlignFrame(al);
\r
440 Desktop.addInternalFrame(af,
\r
442 AlignFrame.NEW_WINDOW_WIDTH,
\r
443 AlignFrame.NEW_WINDOW_HEIGHT);
\r
445 catch (Exception ex)
\r
447 ex.printStackTrace();
\r