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.bin.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.datamodel.Alignment;
\r
30 import jalview.datamodel.AlignmentView;
\r
31 import jalview.gui.*;
\r
32 import jalview.io.*;
\r
33 import jalview.util.*;
\r
34 import jalview.ws.WSThread.*;
\r
35 import vamsas.objects.simple.*;
\r
37 public class JPredClient
\r
40 AlignFrame parentFrame=null;
\r
42 * crate a new GUI JPred Job
\r
43 * @param sh ServiceHandle
\r
44 * @param title String
\r
45 * @param msa boolean - true - submit alignment as a sequence profile
\r
46 * @param alview AlignmentView
\r
48 public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa, AlignmentView alview, AlignFrame parentFrame) {
\r
49 wsInfo=setWebService(sh);
\r
50 this.parentFrame=parentFrame;
\r
51 startJPredClient(title, msa, alview);
\r
58 * @param title String
\r
59 * @param msa boolean
\r
60 * @param alview AlignmentView
\r
62 private void startJPredClient(String title, boolean msa,
\r
63 jalview.datamodel.AlignmentView alview)
\r
67 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq, AlignFrame parentFrame)
\r
69 wsInfo = setWebService(sh);
\r
70 this.parentFrame=parentFrame;
\r
71 startJPredClient(title, seq);
\r
74 public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa, AlignFrame parentFrame)
\r
76 wsInfo = setWebService(sh);
\r
77 this.parentFrame=parentFrame;
\r
78 startJPredClient(title, msa);
\r
81 public JPredClient(String title, SequenceI[] msf)
\r
83 startJPredClient(title, msf);
\r
86 public JPredClient(String title, SequenceI seq)
\r
88 startJPredClient(title, seq);
\r
91 private void startJPredClient(String title, SequenceI[] msf)
\r
95 wsInfo = setWebService();
\r
98 SequenceI seq = msf[0];
\r
100 String altitle = "JNet prediction on " + seq.getName() +
\r
101 " using alignment from " + title;
\r
103 wsInfo.setProgressText("Job details for MSA based prediction (" +
\r
104 title + ") on sequence :\n>" + seq.getName() + "\n" +
\r
105 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
107 SequenceI aln[] = new SequenceI[msf.length];
\r
108 for (int i = 0, j = msf.length; i < j; i++)
\r
110 aln[i] = new jalview.datamodel.Sequence(msf[i]);
\r
113 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
\r
115 Jpred server = locateWebService();
\r
121 JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo, aln);
\r
122 wsInfo.setthisService(jthread);
\r
126 public void startJPredClient(String title, SequenceI seq)
\r
128 if (wsInfo == null)
\r
130 wsInfo = setWebService();
\r
132 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
\r
133 seq.getName() + "\n" +
\r
134 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
136 String altitle = "JNet prediction for sequence " + seq.getName() + " from " +
\r
139 Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
141 Jpred server = locateWebService();
\r
147 JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo, seq);
\r
148 wsInfo.setthisService(jthread);
\r
152 private WebserviceInfo setWebService()
\r
154 WebServiceName = "JNetWS";
\r
155 WebServiceJobTitle = "JNet secondary structure prediction";
\r
156 WebServiceReference =
\r
157 "\"Cuff J. A and Barton G.J (2000) Application of " +
\r
158 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
\r
159 "Proteins 40:502-511\".";
\r
160 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
162 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
\r
163 WebServiceReference);
\r
168 private ext.vamsas.Jpred locateWebService()
\r
170 ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
\r
171 ext.vamsas.Jpred server=null;
\r
174 server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
175 ( (JpredSoapBindingStub)server).setTimeout(60000); // one minute stub
\r
176 //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);
\r
179 catch (Exception ex)
\r
181 JOptionPane.showMessageDialog(Desktop.desktop,
\r
182 "The Secondary Structure Prediction Service named " +
\r
183 WebServiceName + " at " + WsURL +
\r
184 " couldn't be located.",
\r
185 "Internal Jalview Error",
\r
186 JOptionPane.WARNING_MESSAGE);
\r
187 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
188 " Service location failed\nfor URL :" + WsURL +
\r
191 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
200 implements WSClientI
\r
203 extends WSThread.WSJob
\r
206 vamsas.objects.simple.Sequence sequence;
\r
207 vamsas.objects.simple.Msfalignment msa;
\r
208 java.util.Hashtable SequenceInfo = null;
\r
211 * @return true if getResultSet will return a valid alignment and prediction result.
\r
213 public boolean hasResults()
\r
215 if (subjobComplete && result != null && result.isFinished()
\r
216 && ( (JpredResult) result).getPredfile() != null &&
\r
217 ( (JpredResult) result).getAligfile() != null)
\r
224 boolean hasValidInput()
\r
226 if (sequence != null)
\r
233 public Alignment getResultSet()
\r
236 if (result == null || !result.isFinished())
\r
240 Alignment al = null;
\r
241 int FirstSeq = -1; // the position of the query sequence in Alignment al
\r
242 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
244 JpredResult result = (JpredResult)this.result;
\r
246 jalview.bin.Cache.log.debug("Parsing output from JNet job.");
\r
247 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
248 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.
\r
251 SequenceI[] preds = prediction.getSeqsAsArray();
\r
252 jalview.bin.Cache.log.debug("Got prediction profile.");
\r
254 if ( (this.msa != null) && (result.getAligfile() != null))
\r
256 jalview.bin.Cache.log.debug("Getting associated alignment.");
\r
257 // we ignore the returned alignment if we only predicted on a single sequence
\r
258 String format = new jalview.io.IdentifyFile().Identify(result.
\r
262 if (jalview.io.FormatAdapter.isValidFormat(format))
\r
264 al = new Alignment(new FormatAdapter().readFile(result.getAligfile(),
\r
266 SequenceI sqs[] = new SequenceI[al.getHeight()];
\r
267 for (int i = 0, j = al.getHeight(); i < j; i++)
\r
269 sqs[i] = al.getSequenceAt(i);
\r
271 if (!jalview.analysis.SeqsetUtils.deuniquify( (Hashtable)
\r
272 SequenceInfo, sqs))
\r
274 throw (new Exception(
\r
275 "Couldn't recover sequence properties for alignment."));
\r
283 throw (new Exception(
\r
284 "Unknown format "+format+" for file : \n" +
\r
285 result.getAligfile()));
\r
290 al = new Alignment(preds);
\r
291 FirstSeq = prediction.getQuerySeqPosition();
\r
292 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(
\r
293 al.getSequenceAt(FirstSeq), SequenceInfo))
\r
295 throw (new Exception(
\r
296 "Couldn't recover sequence properties for JNet Query sequence!"));
\r
300 al.setDataset(null);
\r
302 jalview.io.JnetAnnotationMaker.add_annotation(prediction, al, FirstSeq,
\r
304 return al; // , FirstSeq, noMsa};
\r
306 public JPredJob(Hashtable SequenceInfo, SequenceI seq)
\r
309 String sq = AlignSeq.extractGaps(Comparison.GapChars, seq.getSequence());
\r
310 if (sq.length() >= 20)
\r
312 this.SequenceInfo = SequenceInfo;
\r
313 sequence = new vamsas.objects.simple.Sequence();
\r
314 sequence.setId(seq.getName());
\r
315 sequence.setSeq(sq);
\r
319 public JPredJob(Hashtable SequenceInfo, SequenceI[] msf)
\r
321 this(SequenceInfo, msf[0]);
\r
322 if (sequence != null)
\r
324 if (msf.length > 1)
\r
326 msa = new vamsas.objects.simple.Msfalignment();
\r
327 jalview.io.PileUpfile pileup = new jalview.io.PileUpfile();
\r
328 msa.setMsf(pileup.print(msf));
\r
333 ext.vamsas.Jpred server;
\r
334 String altitle = "";
\r
335 JPredThread(WebserviceInfo wsinfo, String altitle, ext.vamsas.Jpred server) {
\r
336 this.altitle = altitle;
\r
337 this.server = server;
\r
338 this.wsInfo = wsinfo;
\r
341 // String OutputHeader;
\r
342 // vamsas.objects.simple.JpredResult result;
\r
344 JPredThread(WebserviceInfo wsinfo, String altitle, ext.vamsas.Jpred server, Hashtable SequenceInfo,SequenceI seq)
\r
346 this(wsinfo, altitle, server);
\r
347 JPredJob job = new JPredJob(SequenceInfo, seq);
\r
348 if (job.hasValidInput())
\r
350 OutputHeader = wsInfo.getProgressText();
\r
358 JPredThread(WebserviceInfo wsinfo, String altitle, ext.vamsas.Jpred server, Hashtable SequenceInfo, SequenceI[] msf)
\r
360 this(wsinfo, altitle, server);
\r
361 JPredJob job = new JPredJob(SequenceInfo, msf);
\r
362 if (job.hasValidInput())
\r
367 OutputHeader = wsInfo.getProgressText();
\r
377 while (!jobComplete && (allowedServerExceptions > 0))
\r
381 if ( (result = server.getresult(jobId)) == null)
\r
383 throw (new Exception(
\r
384 "Timed out when communicating with server\nTry again later.\n"));
\r
386 if (result.getState()==0)
\r
387 jalview.bin.Cache.log.debug("Finished "+jobId);
\r
388 if (result.isRunning())
\r
390 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
392 if (result.isQueued())
\r
394 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
397 wsInfo.setProgressText(OutputHeader + "\n" +
\r
398 result.getStatus());
\r
400 if (result.isFinished())
\r
404 jobComplete = true;
\r
407 // catch exceptions
\r
408 if (! (result.isJobFailed() || result.isServerError()))
\r
412 Thread.sleep(5000);
\r
414 catch (InterruptedException ex1)
\r
418 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
422 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
424 jobComplete = true;
\r
428 catch (Exception ex)
\r
430 allowedServerExceptions--;
\r
432 wsInfo.appendProgressText("\nJPredWS Server exception!\n" +
\r
437 if (allowedServerExceptions > 0)
\r
439 Thread.sleep(5000);
\r
442 catch (InterruptedException ex1)
\r
446 catch (OutOfMemoryError er)
\r
448 jobComplete = true;
\r
449 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
450 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
451 "Out of memory handling result!!"
\r
453 "\nSee help files for increasing Java Virtual Machine memory."
\r
455 JOptionPane.WARNING_MESSAGE);
\r
456 System.out.println("JPredClient: "+er);
\r
461 if (! (result.isJobFailed() || result.isServerError()))
\r
463 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
467 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
471 void StartJob(WSJob j)
\r
473 if (! (j instanceof JPredJob))
\r
475 throw new Error("Implementation error - StartJob(JpredJob) called on " +
\r
480 JPredJob job = (JPredJob) j;
\r
481 if (job.msa != null)
\r
483 job.jobId = server.predictOnMsa(job.msa);
\r
486 if (job.sequence!=null)
\r
488 job.jobId = server.predict(job.sequence);
\r
491 if (job.jobId != null)
\r
493 if (job.jobId.startsWith("Broken"))
\r
495 job.result = (vamsas.objects.simple.Result)new JpredResult();
\r
496 job.result.setInvalid(true);
\r
497 job.result.setStatus("Submission " + job.jobId);
\r
501 job.submitted = true;
\r
502 job.subjobComplete = false;
\r
503 Cache.log.info(WsURL + " Job Id '" + job.jobId + "'");
\r
508 throw new Exception("Server timed out - try again later\n");
\r
511 catch (Exception e)
\r
513 if (e.getMessage().indexOf("Exception") > -1)
\r
515 wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
516 wsInfo.setProgressText(j.jobnum,
\r
517 "Failed to submit the prediction. (Just close the window)\n"
\r
519 "It is most likely that there is a problem with the server.\n");
\r
520 System.err.println(
\r
521 "JPredWS Client: Failed to submit the prediction. Quite possibly because of a server error - see below)\n" +
\r
522 e.getMessage() + "\n");
\r
524 jalview.bin.Cache.log.warn("Server Exception", e);
\r
528 wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
\r
529 // JBPNote - this could be a popup informing the user of the problem.
\r
530 wsInfo.appendProgressText(j.jobnum,
\r
531 "Failed to submit the prediction:\n"
\r
533 wsInfo.getProgressText());
\r
535 jalview.bin.Cache.log.debug("Failed Submission of job " + j.jobnum, e);
\r
538 j.allowedServerExceptions = -1;
\r
539 j.subjobComplete = true;
\r
543 /* private void addFloatAnnotations(Alignment al, int[] gapmap,
\r
544 Vector values, String Symname,
\r
545 String Visname, float min,
\r
546 float max, int winLength)
\r
548 Annotation[] annotations = new Annotation[al.getWidth()];
\r
550 for (int j = 0; j < values.size(); j++)
\r
552 float value = Float.parseFloat(values.get(j).toString());
\r
553 annotations[gapmap[j]] = new Annotation("", value + "", ' ',
\r
557 al.addAnnotation(new AlignmentAnnotation(Symname, Visname,
\r
558 annotations, min, max, winLength));
\r
563 int results = 0; // number of result sets received
\r
564 JobStateSummary finalState = new JobStateSummary();
\r
567 for (int j = 0; j < jobs.length; j++)
\r
569 finalState.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
\r
570 if (jobs[j].submitted && jobs[j].subjobComplete && jobs[j].hasResults())
\r
576 catch (Exception ex)
\r
579 Cache.log.error("Unexpected exception when processing results for " +
\r
581 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
585 wsInfo.showResultsNewFrame
\r
586 .addActionListener(new java.awt.event.ActionListener()
\r
588 public void actionPerformed(
\r
589 java.awt.event.ActionEvent evt)
\r
591 displayResults(true);
\r
594 wsInfo.mergeResults
\r
595 .addActionListener(new java.awt.event.ActionListener()
\r
597 public void actionPerformed(
\r
598 java.awt.event.ActionEvent evt)
\r
600 displayResults(false);
\r
603 wsInfo.setResultsReady();
\r
607 wsInfo.setFinishedNoResults();
\r
611 void displayResults(boolean newWindow)
\r
615 Alignment res = null;
\r
616 for (int jn = 0; jn < jobs.length; jn++)
\r
618 Alignment jobres = null;
\r
619 JPredJob j = (JPredJob) jobs[jn];
\r
621 if (j.hasResults())
\r
625 jalview.bin.Cache.log.debug("Parsing output of job " + jn);
\r
626 jobres = j.getResultSet();
\r
627 jalview.bin.Cache.log.debug("Finished parsing output.");
\r
628 if (jobs.length==1)
\r
631 // do merge with other job results
\r
634 catch (Exception e)
\r
636 jalview.bin.Cache.log.error(
\r
637 "JNet Client: JPred Annotation Parse Error",
\r
639 wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
\r
640 wsInfo.appendProgressText(j.jobnum,
\r
641 OutputHeader + "\n" +
\r
642 j.result.getStatus() +
\r
643 "\nInvalid JNet job result data!\n" +
\r
645 j.result.setBroken(true);
\r
654 AlignFrame af = new AlignFrame(res);
\r
655 Desktop.addInternalFrame(af, altitle,
\r
656 AlignFrame.NEW_WINDOW_WIDTH,
\r
657 AlignFrame.NEW_WINDOW_HEIGHT);
\r
661 Cache.log.info("Append results onto existing alignment.");
\r
666 void pollJob(WSJob job)
\r
669 job.result = server.getresult(job.jobId);
\r
671 public boolean isCancellable()
\r
676 public void cancelJob()
\r
678 throw new Error("Implementation error!");
\r
681 public boolean canMergeResults()
\r