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 (2000) Application of " +
\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 = new 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
442 al.setDataset(null);
\r
444 AlignmentAnnotation annot;
\r
445 Annotation[] annotations = null;
\r
447 int width = preds[0].getSequence().length();
\r
449 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
451 if (gapmap.length != width)
\r
453 throw (new Exception(
\r
454 "Jnet Client Error\nNumber of residues in supposed query sequence :\n" +
\r
455 al.getSequenceAt(FirstSeq).getName() + "\n" +
\r
456 al.getSequenceAt(FirstSeq).getSequence() +
\r
457 "\nDiffer from number of prediction sites in \n" +
\r
458 result.getPredfile() + "\n"));
\r
461 // JBPNote Should also rename the query sequence sometime...
\r
464 SequenceI seqRef = al.getSequenceAt(FirstSeq);
\r
466 while (i < preds.length)
\r
468 String id = preds[i].getName().toUpperCase();
\r
470 if (id.startsWith("LUPAS") || id.startsWith("JNET") ||
\r
471 id.startsWith("JPRED"))
\r
473 annotations = new Annotation[al.getWidth()];
\r
475 if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||
\r
476 id.equals("JNETFREQ") || id.equals("JNETHMM") ||
\r
477 id.equals("JNETALIGN") || id.equals("JPRED"))
\r
479 for (int j = 0; j < width; j++)
\r
481 annotations[gapmap[j]] = new Annotation("", "",
\r
482 preds[i].getCharAt(j), 0);
\r
485 else if (id.equals("JNETCONF"))
\r
487 for (int j = 0; j < width; j++)
\r
489 float value = Float.parseFloat(preds[i].getCharAt(
\r
491 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
492 j) + "", "", preds[i].getCharAt(j),
\r
498 for (int j = 0; j < width; j++)
\r
500 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
501 j) + "", "", ' ', 0);
\r
505 if (id.equals("JNETCONF"))
\r
507 annot = new AlignmentAnnotation(preds[i].getName(),
\r
508 "JNet Output", annotations, 0f,
\r
510 AlignmentAnnotation.BAR_GRAPH);
\r
514 annot = new AlignmentAnnotation(preds[i].getName(),
\r
515 "JNet Output", annotations);
\r
518 al.addAnnotation(annot, seqRef);
\r
522 al.deleteSequence(preds[i]);
\r
529 //Hashtable scores = prediction.getScores();
\r
531 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
532 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
534 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
535 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
537 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
538 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
541 wsInfo.setProgressText(OutputHeader);
\r
542 jalview.bin.Cache.log.debug("Finished parsing output.");
\r
543 AlignFrame af = new AlignFrame(al);
\r
545 Desktop.addInternalFrame(af, altitle,
\r
546 AlignFrame.NEW_WINDOW_WIDTH,
\r
547 AlignFrame.NEW_WINDOW_HEIGHT);
\r
549 catch (Exception ex)
\r
551 jalview.bin.Cache.log.warn("Exception whilst parsing JNet style secondary structure prediction.",ex);
\r