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
29 import jalview.io.FormatAdapter;
\r
31 public class JPredClient
\r
34 ext.vamsas.Jpred server;
\r
35 String altitle = "";
\r
36 java.util.Hashtable SequenceInfo = null;
\r
37 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq) {
\r
38 wsInfo = setWebService(sh);
\r
39 startJPredClient(title, seq);
\r
41 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa) {
\r
42 wsInfo = setWebService(sh);
\r
43 startJPredClient(title, msa);
\r
46 public JPredClient(String title, SequenceI[] msf) {
\r
47 startJPredClient(title, msf);
\r
50 public JPredClient(String title, SequenceI seq) {
\r
51 startJPredClient(title, seq);
\r
54 private void startJPredClient(String title, SequenceI[] msf)
\r
57 wsInfo = setWebService();
\r
59 SequenceI seq = msf[0];
\r
61 altitle = "JNet prediction on " + seq.getName() +
\r
62 " using alignment from " + title;
\r
64 wsInfo.setProgressText("Job details for MSA based prediction (" +
\r
65 title + ") on sequence :\n>" + seq.getName() + "\n" +
\r
66 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
68 SequenceI aln[] = new SequenceI[msf.length];
\r
69 for (int i=0,j=msf.length; i<j;i++) {
\r
70 aln[i] = new jalview.datamodel.Sequence(msf[i]);
\r
73 SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
\r
75 if (!locateWebService())
\r
80 JPredThread jthread = new JPredThread(aln);
\r
84 public void startJPredClient(String title, SequenceI seq)
\r
87 wsInfo = setWebService();
\r
88 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
\r
89 seq.getName() + "\n" +
\r
90 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
92 altitle = "JNet prediction for sequence " + seq.getName() + " from " +
\r
95 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
97 if (!locateWebService())
\r
102 JPredThread jthread = new JPredThread(seq);
\r
106 private WebserviceInfo setWebService()
\r
108 WebServiceName = "JNetWS";
\r
109 WebServiceJobTitle = "JNet secondary structure prediction";
\r
110 WebServiceReference =
\r
111 "\"Cuff J. A and Barton G.J (1999) Application of enhanced " +
\r
112 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
\r
113 "Proteins 40:502-511\".";
\r
114 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
116 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
\r
117 WebServiceReference);
\r
122 private boolean locateWebService()
\r
124 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
\r
128 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
129 ( (JpredSoapBindingStub)this.server).setTimeout(60000); // one minute stub
\r
131 catch (Exception ex)
\r
133 JOptionPane.showMessageDialog(Desktop.desktop,
\r
134 "The Secondary Structure Prediction Service named " +
\r
135 WebServiceName + " at " + WsURL +
\r
136 " couldn't be located.",
\r
137 "Internal Jalview Error",
\r
138 JOptionPane.WARNING_MESSAGE);
\r
139 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
140 " Service location failed\nfor URL :" + WsURL +
\r
143 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
154 String OutputHeader;
\r
155 vamsas.objects.simple.JpredResult result;
\r
156 vamsas.objects.simple.Sequence sequence;
\r
157 vamsas.objects.simple.Msfalignment msa;
\r
159 boolean jobComplete = false;
\r
160 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
162 JPredThread(SequenceI seq)
\r
164 OutputHeader = wsInfo.getProgressText();
\r
165 this.sequence = new vamsas.objects.simple.Sequence();
\r
166 this.sequence.setId(seq.getName());
\r
167 this.sequence.setSeq(AlignSeq.extractGaps("-. ", seq.getSequence()));
\r
170 JPredThread(SequenceI[] msf)
\r
172 OutputHeader = wsInfo.getProgressText();
\r
173 this.sequence = new vamsas.objects.simple.Sequence();
\r
174 this.sequence.setId(msf[0].getName());
\r
175 this.sequence.setSeq(AlignSeq.extractGaps("-. ",
\r
176 msf[0].getSequence()));
\r
178 this.msa = new vamsas.objects.simple.Msfalignment();
\r
179 jalview.io.PileUpfile pileup = new jalview.io.PileUpfile();
\r
180 msa.setMsf(pileup.print(msf));
\r
187 while (!jobComplete && (allowedServerExceptions > 0))
\r
191 if ( (result = server.getresult(jobId)) == null)
\r
193 throw (new Exception(
\r
194 "Timed out when communicating with server\nTry again later.\n"));
\r
196 if (result.getState()==0)
\r
197 jalview.bin.Cache.log.debug("Finished "+jobId);
\r
198 if (result.isRunning())
\r
200 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
202 if (result.isQueued())
\r
204 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
207 wsInfo.setProgressText(OutputHeader + "\n" +
\r
208 result.getStatus());
\r
210 if (result.isFinished())
\r
214 jobComplete = true;
\r
217 // catch exceptions
\r
218 if (! (result.isJobFailed() || result.isServerError()))
\r
222 Thread.sleep(5000);
\r
224 catch (InterruptedException ex1)
\r
228 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
232 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
234 jobComplete = true;
\r
238 catch (Exception ex)
\r
240 allowedServerExceptions--;
\r
241 wsInfo.appendProgressText("\nJPredWS Server exception!\n" +
\r
246 if (allowedServerExceptions > 0)
\r
248 Thread.sleep(5000);
\r
251 catch (InterruptedException ex1)
\r
255 catch (OutOfMemoryError er)
\r
257 jobComplete = true;
\r
258 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
259 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
260 "Out of memory handling result!!"
\r
262 "\nSee help files for increasing Java Virtual Machine memory."
\r
264 JOptionPane.WARNING_MESSAGE);
\r
265 System.out.println("JPredClient: "+er);
\r
270 if (! (result.isJobFailed() || result.isServerError()))
\r
272 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
276 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
286 jobId = server.predictOnMsa(msa);
\r
290 jobId = server.predict(sequence);
\r
295 if (jobId.startsWith("Broken"))
\r
297 throw new Exception("Submission " + jobId);
\r
301 System.out.println(WsURL + " Job Id '" + jobId + "'");
\r
306 throw new Exception("Server timed out - try again later\n");
\r
309 catch (Exception e)
\r
311 if (e.getMessage().indexOf("Exception")>-1) {
\r
312 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
313 wsInfo.setProgressText(
\r
314 "Failed to submit the prediction. (Just close the window)\n"
\r
316 "It is most likely that there is a problem with the server.\n");
\r
317 System.err.println(
\r
318 "JPredWS Client: Failed to submit the prediction. Quite possibly because of a server error - see below)\n" +
\r
319 e.getMessage() + "\n");
\r
321 jalview.bin.Cache.log.warn("Server Exception",e);
\r
323 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
324 // JBPNote - this could be a popup informing the user of the problem.
\r
325 wsInfo.setProgressText("Failed to submit the prediction:\n"
\r
327 wsInfo.getProgressText());
\r
329 jalview.bin.Cache.log.debug("Failed Submission",e);
\r
332 allowedServerExceptions = -1;
\r
333 jobComplete = true;
\r
340 /* private void addFloatAnnotations(Alignment al, int[] gapmap,
\r
341 Vector values, String Symname,
\r
342 String Visname, float min,
\r
343 float max, int winLength)
\r
345 Annotation[] annotations = new Annotation[al.getWidth()];
\r
347 for (int j = 0; j < values.size(); j++)
\r
349 float value = Float.parseFloat(values.get(j).toString());
\r
350 annotations[gapmap[j]] = new Annotation("", value + "", ' ',
\r
354 al.addAnnotation(new AlignmentAnnotation(Symname, Visname,
\r
355 annotations, min, max, winLength));
\r
360 // OutputHeader = output.getText();
\r
361 if (result.isFailed())
\r
363 OutputHeader += "Job failed.\n";
\r
366 if (result.getStatus() != null)
\r
368 OutputHeader += ("\n" + result.getStatus());
\r
371 if (result.getPredfile() != null)
\r
373 OutputHeader += ("\n" + result.getPredfile());
\r
375 // 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
378 if (result.getAligfile() != null)
\r
380 OutputHeader += ("\n" + result.getAligfile());
\r
383 wsInfo.setProgressText(OutputHeader+"Parsing...");
\r
387 jalview.bin.Cache.log.debug("Parsing output from JNet job.");
\r
388 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
389 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.
\r
392 SequenceI[] preds = prediction.getSeqsAsArray();
\r
393 jalview.bin.Cache.log.debug("Got prediction profile.");
\r
395 int FirstSeq; // the position of the query sequence in Alignment al
\r
396 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
398 if ( (this.msa != null) && (result.getAligfile() != null))
\r
400 jalview.bin.Cache.log.debug("Getting associated alignment.");
\r
401 // we ignore the returned alignment if we only predicted on a single sequence
\r
402 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(),
\r
405 if (jalview.io.FormatAdapter.formats.contains(format))
\r
407 al = new Alignment(new FormatAdapter().readFile(
\r
408 result.getAligfile(), "Paste", format));
\r
409 SequenceI sqs[] = new SequenceI[al.getHeight()];
\r
410 for (int i=0, j=al.getHeight(); i<j; i++) {
\r
411 sqs[i] = al.getSequenceAt(i);
\r
413 if (!jalview.analysis.SeqsetUtils.deuniquify(
\r
414 (Hashtable) SequenceInfo,sqs))
\r
416 throw (new Exception(
\r
417 "Couldn't recover sequence properties for alignment."));
\r
425 throw (new Exception(
\r
426 "Unknown format 'format' for file : \n" +
\r
427 result.getAligfile()));
\r
432 al = new Alignment(preds);
\r
433 FirstSeq = prediction.getQuerySeqPosition();
\r
434 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(
\r
435 al.getSequenceAt(FirstSeq), SequenceInfo))
\r
437 throw (new Exception(
\r
438 "Couldn't recover sequence properties for JNet Query sequence!"));
\r
443 AlignmentAnnotation annot;
\r
444 Annotation[] annotations = null;
\r
446 int width = preds[0].getSequence().length();
\r
448 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
450 if (gapmap.length != width)
\r
452 throw (new Exception(
\r
453 "Jnet Client Error\nNumber of residues in supposed query sequence :\n" +
\r
454 al.getSequenceAt(FirstSeq).getName() + "\n" +
\r
455 al.getSequenceAt(FirstSeq).getSequence() +
\r
456 "\nDiffer from number of prediction sites in \n" +
\r
457 result.getPredfile() + "\n"));
\r
460 // JBPNote Should also rename the query sequence sometime...
\r
463 while (i < preds.length)
\r
465 String id = preds[i].getName().toUpperCase();
\r
467 if (id.startsWith("LUPAS") || id.startsWith("JNET") ||
\r
468 id.startsWith("JPRED"))
\r
470 annotations = new Annotation[al.getWidth()];
\r
472 if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||
\r
473 id.equals("JNETFREQ") || id.equals("JNETHMM") ||
\r
474 id.equals("JNETALIGN") || id.equals("JPRED"))
\r
476 for (int j = 0; j < width; j++)
\r
478 annotations[gapmap[j]] = new Annotation("", "",
\r
479 preds[i].getCharAt(j), 0);
\r
482 else if (id.equals("JNETCONF"))
\r
484 for (int j = 0; j < width; j++)
\r
486 float value = Float.parseFloat(preds[i].getCharAt(
\r
488 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
489 j) + "", "", preds[i].getCharAt(j),
\r
495 for (int j = 0; j < width; j++)
\r
497 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
498 j) + "", "", ' ', 0);
\r
502 if (id.equals("JNETCONF"))
\r
504 annot = new AlignmentAnnotation(preds[i].getName(),
\r
505 "JNet Output", annotations, 0f,
\r
510 annot = new AlignmentAnnotation(preds[i].getName(),
\r
511 "JNet Output", annotations);
\r
514 al.addAnnotation(annot);
\r
518 al.deleteSequence(preds[i]);
\r
525 //Hashtable scores = prediction.getScores();
\r
527 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
528 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
530 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
531 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
533 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
534 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
537 wsInfo.setProgressText(OutputHeader);
\r
538 jalview.bin.Cache.log.debug("Finished parsing output.");
\r
539 AlignFrame af = new AlignFrame(al);
\r
541 Desktop.addInternalFrame(af, altitle,
\r
542 AlignFrame.NEW_WINDOW_WIDTH,
\r
543 AlignFrame.NEW_WINDOW_HEIGHT);
\r
545 catch (Exception ex)
\r
547 jalview.bin.Cache.log.warn("Exception whilst parsing JNet style secondary structure prediction.");
\r
548 jalview.bin.Cache.log.debug("Exception: ",ex);
\r