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
23 import javax.swing.*;
\r
25 import ext.vamsas.*;
\r
26 import jalview.analysis.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.gui.*;
\r
30 public class JPredClient
\r
33 ext.vamsas.Jpred server;
\r
34 String altitle = "";
\r
35 java.util.Hashtable SequenceInfo = null;
\r
36 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq) {
\r
37 wsInfo = setWebService(sh);
\r
38 startJPredClient(title, seq);
\r
40 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa) {
\r
41 wsInfo = setWebService(sh);
\r
42 startJPredClient(title, msa);
\r
45 public JPredClient(String title, SequenceI[] msf) {
\r
46 startJPredClient(title, msf);
\r
49 public JPredClient(String title, SequenceI seq) {
\r
50 startJPredClient(title, seq);
\r
53 private void startJPredClient(String title, SequenceI[] msf)
\r
56 wsInfo = setWebService();
\r
58 SequenceI seq = msf[0];
\r
59 altitle = "JNet prediction on " + seq.getName() +
\r
60 " using alignment from " + title;
\r
62 wsInfo.setProgressText("Job details for MSA based prediction (" +
\r
63 title + ") on sequence :\n>" + seq.getName() + "\n" +
\r
64 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
67 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
69 if (!locateWebService())
\r
74 JPredThread jthread = new JPredThread(msf);
\r
78 public void startJPredClient(String title, SequenceI seq)
\r
81 wsInfo = setWebService();
\r
82 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
\r
83 seq.getName() + "\n" +
\r
84 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
86 altitle = "JNet prediction for sequence " + seq.getName() + " from " +
\r
89 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
91 if (!locateWebService())
\r
96 JPredThread jthread = new JPredThread(seq);
\r
100 private WebserviceInfo setWebService()
\r
102 WebServiceName = "JNetWS";
\r
103 WebServiceJobTitle = "JNet secondary structure prediction";
\r
104 WebServiceReference =
\r
105 "\"Cuff J. A and Barton G.J (1999) Application of enhanced " +
\r
106 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
\r
107 "Proteins 40:502-511\".";
\r
108 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
110 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
\r
111 WebServiceReference);
\r
116 private boolean locateWebService()
\r
118 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
\r
122 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
123 ( (JpredSoapBindingStub)this.server).setTimeout(60000); // one minute stub
\r
125 catch (Exception ex)
\r
127 JOptionPane.showMessageDialog(Desktop.desktop,
\r
128 "The Secondary Structure Prediction Service named " +
\r
129 WebServiceName + " at " + WsURL +
\r
130 " couldn't be located.",
\r
131 "Internal Jalview Error",
\r
132 JOptionPane.WARNING_MESSAGE);
\r
133 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
134 " Service location failed\nfor URL :" + WsURL +
\r
137 wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR);
\r
148 String OutputHeader;
\r
149 vamsas.objects.simple.JpredResult result;
\r
150 vamsas.objects.simple.Sequence sequence;
\r
151 vamsas.objects.simple.Msfalignment msa;
\r
153 boolean jobComplete = false;
\r
154 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
156 JPredThread(SequenceI seq)
\r
158 OutputHeader = wsInfo.getProgressText();
\r
159 this.sequence = new vamsas.objects.simple.Sequence();
\r
160 this.sequence.setId(seq.getName());
\r
161 this.sequence.setSeq(AlignSeq.extractGaps("-. ", seq.getSequence()));
\r
164 JPredThread(SequenceI[] msf)
\r
166 OutputHeader = wsInfo.getProgressText();
\r
167 this.sequence = new vamsas.objects.simple.Sequence();
\r
168 this.sequence.setId(msf[0].getName());
\r
169 this.sequence.setSeq(AlignSeq.extractGaps("-. ",
\r
170 msf[0].getSequence()));
\r
172 jalview.io.PileUpfile mwrite = new jalview.io.PileUpfile();
\r
173 this.msa = new vamsas.objects.simple.Msfalignment();
\r
174 msa.setMsf(mwrite.print(msf));
\r
181 while (!jobComplete && (allowedServerExceptions > 0))
\r
185 if ( (result = server.getresult(jobId)) == null)
\r
187 throw (new Exception(
\r
188 "Timed out when communicating with server\nTry again later.\n"));
\r
190 if (result.getState()==0)
\r
191 jalview.bin.Jalview.log.debug("Finished "+jobId);
\r
192 if (result.isRunning())
\r
194 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
196 if (result.isQueued())
\r
198 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
201 wsInfo.setProgressText(OutputHeader + "\n" +
\r
202 result.getStatus());
\r
204 if (result.isFinished())
\r
208 jobComplete = true;
\r
211 // catch exceptions
\r
212 if (! (result.isJobFailed() || result.isServerError()))
\r
216 Thread.sleep(5000);
\r
218 catch (InterruptedException ex1)
\r
222 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
226 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
228 jobComplete = true;
\r
232 catch (Exception ex)
\r
234 allowedServerExceptions--;
\r
235 wsInfo.appendProgressText("\nJPredWS Server exception!\n" +
\r
240 if (allowedServerExceptions > 0)
\r
242 Thread.sleep(5000);
\r
245 catch (InterruptedException ex1)
\r
251 if (! (result.isJobFailed() || result.isServerError()))
\r
253 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
257 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
267 jobId = server.predictOnMsa(msa);
\r
271 jobId = server.predict(sequence);
\r
276 if (jobId.startsWith("Broken"))
\r
278 throw new Exception("Submission " + jobId);
\r
282 System.out.println(WsURL + " Job Id '" + jobId + "'");
\r
287 throw new Exception("Server timed out - try again later\n");
\r
290 catch (Exception e)
\r
292 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
293 allowedServerExceptions = 0;
\r
294 jobComplete = false;
\r
296 wsInfo.appendProgressText("Failed to submit the prediction.\n"
\r
298 "It is most likely that there is a problem with the server.\n"
\r
299 + "Just close the window\n");
\r
300 System.err.println(
\r
301 "JPredWS Client: Failed to submit the prediction (Probably a server error - see below)\n" +
\r
302 e.toString() + "\n");
\r
304 jalview.bin.Jalview.log.debug("Failed Submission",e);
\r
310 private void addFloatAnnotations(Alignment al, int[] gapmap,
\r
311 Vector values, String Symname,
\r
312 String Visname, float min,
\r
313 float max, int winLength)
\r
315 Annotation[] annotations = new Annotation[al.getWidth()];
\r
317 for (int j = 0; j < values.size(); j++)
\r
319 float value = Float.parseFloat(values.get(j).toString());
\r
320 annotations[gapmap[j]] = new Annotation("", value + "", ' ',
\r
324 al.addAnnotation(new AlignmentAnnotation(Symname, Visname,
\r
325 annotations, min, max, winLength));
\r
330 // OutputHeader = output.getText();
\r
331 if (result.isFailed())
\r
333 OutputHeader += "Job failed.\n";
\r
336 if (result.getStatus() != null)
\r
338 OutputHeader += ("\n" + result.getStatus());
\r
341 if (result.getPredfile() != null)
\r
343 OutputHeader += ("\n" + result.getPredfile());
\r
345 // 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
348 if (result.getAligfile() != null)
\r
350 OutputHeader += ("\n" + result.getAligfile());
\r
353 wsInfo.setProgressText(OutputHeader);
\r
357 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
358 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.
\r
361 SequenceI[] preds = prediction.getSeqsAsArray();
\r
363 int FirstSeq; // the position of the query sequence in Alignment al
\r
364 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
366 if ( (this.msa != null) && (result.getAligfile() != null))
\r
368 // we ignore the returned alignment if we only predicted on a single sequence
\r
369 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(),
\r
372 if (jalview.io.FormatAdapter.formats.contains(format))
\r
374 al = new Alignment(jalview.io.FormatAdapter.readFile(
\r
375 result.getAligfile(), "Paste", format));
\r
381 throw (new Exception(
\r
382 "Unknown format 'format' for file : \n" +
\r
383 result.getAligfile()));
\r
388 al = new Alignment(preds);
\r
389 FirstSeq = prediction.getQuerySeqPosition();
\r
392 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(
\r
393 al.getSequenceAt(FirstSeq), SequenceInfo))
\r
395 throw (new Exception(
\r
396 "Couldn't recover sequence properties for JNet Query sequence!"));
\r
399 AlignmentAnnotation annot;
\r
400 Annotation[] annotations = null;
\r
402 int width = preds[0].getSequence().length();
\r
404 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
406 if (gapmap.length != width)
\r
408 throw (new Exception(
\r
409 "Jnet Client Error\nNumber of residues in supposed query sequence :\n" +
\r
410 al.getSequenceAt(FirstSeq).getName() + "\n" +
\r
411 al.getSequenceAt(FirstSeq).getSequence() +
\r
412 "\nDiffer from number of prediction sites in \n" +
\r
413 result.getPredfile() + "\n"));
\r
416 // JBPNote Should also rename the query sequence sometime...
\r
419 while (i < preds.length)
\r
421 String id = preds[i].getName().toUpperCase();
\r
423 if (id.startsWith("LUPAS") || id.startsWith("JNET") ||
\r
424 id.startsWith("JPRED"))
\r
426 annotations = new Annotation[al.getWidth()];
\r
428 if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||
\r
429 id.equals("JNETFREQ") || id.equals("JNETHMM") ||
\r
430 id.equals("JNETALIGN") || id.equals("JPRED"))
\r
432 for (int j = 0; j < width; j++)
\r
434 annotations[gapmap[j]] = new Annotation("", "",
\r
435 preds[i].getCharAt(j), 0);
\r
438 else if (id.equals("JNETCONF"))
\r
440 for (int j = 0; j < width; j++)
\r
442 float value = Float.parseFloat(preds[i].getCharAt(
\r
444 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
445 j) + "", "", preds[i].getCharAt(j),
\r
451 for (int j = 0; j < width; j++)
\r
453 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
454 j) + "", "", ' ', 0);
\r
458 if (id.equals("JNETCONF"))
\r
460 annot = new AlignmentAnnotation(preds[i].getName(),
\r
461 "JNet Output", annotations, 0f,
\r
466 annot = new AlignmentAnnotation(preds[i].getName(),
\r
467 "JNet Output", annotations);
\r
470 al.addAnnotation(annot);
\r
474 al.deleteSequence(preds[i]);
\r
481 Hashtable scores = prediction.getScores();
\r
483 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
484 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
486 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
487 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
489 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
490 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
492 AlignFrame af = new AlignFrame(al);
\r
494 Desktop.addInternalFrame(af, altitle,
\r
495 AlignFrame.NEW_WINDOW_WIDTH,
\r
496 AlignFrame.NEW_WINDOW_HEIGHT);
\r
498 catch (Exception ex)
\r
500 jalview.bin.Jalview.log.warn("Exception whilst parsing JNet style secondary structure prediction.");
\r
501 jalview.bin.Jalview.log.debug(ex);
\r