X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2FMsaWSClient.java;h=eb6ee388d91d90b1937bb9491b8a13d1d190ff1e;hb=aad4f693fc478138fd225741acf1f8d44defd162;hp=49c879b4d1d7748e515ee4b498cd4f0b8e79eb5d;hpb=7570956d4b58f313d402cdd0507737c0628f1544;p=jalview.git diff --git a/src/jalview/ws/MsaWSClient.java b/src/jalview/ws/MsaWSClient.java index 49c879b..eb6ee38 100755 --- a/src/jalview/ws/MsaWSClient.java +++ b/src/jalview/ws/MsaWSClient.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -63,7 +63,7 @@ public class MsaWSClient Alignment seqdataset, AlignFrame _alignFrame) { - + super(); alignFrame = _alignFrame; if (!sh.getAbstractName().equals("MsaWS")) { @@ -76,7 +76,7 @@ public class MsaWSClient return; } - if ((wsInfo = this.setWebService(sh))==null) + if ((wsInfo = setWebService(sh))==null) { JOptionPane.showMessageDialog(Desktop.desktop, "The Multiple Sequence Alignment Service named " + @@ -102,8 +102,10 @@ public class MsaWSClient wsInfo.setProgressText( ( (submitGaps) ? "Re-alignment" : "Alignment") + " of " + altitle + "\nJob details\n"); - MsaWSThread musclethread = new MsaWSThread(WebServiceName + - " alignment of " + altitle, msa, + MsaWSThread musclethread = new MsaWSThread(server, WsURL, wsInfo, alignFrame, + WebServiceName, + WebServiceName+" alignment of " + altitle, + msa, submitGaps, preserveOrder, seqdataset); wsInfo.setthisService(musclethread); musclethread.start(); @@ -150,393 +152,4 @@ public class MsaWSClient { return "Multiple Sequence Alignment"; } - - protected class MsaWSThread - extends Thread implements WSClientI - { - String ServiceName = WebServiceName; - String OutputHeader; - vamsas.objects.simple.MsaResult result = null; - vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple. - SequenceSet(); - Hashtable SeqNames = null; - boolean submitGaps = false; // pass sequences including gaps to alignment service - boolean preserveOrder = true; // and always store and recover sequence order - String jobId; - String alTitle; // name which will be used to form new alignment window. - int allowedServerExceptions = 3; // thread dies if too many exceptions. - boolean jobComplete = false; - - Alignment dataset; // dataset to which the new alignment will be associated. - - MsaWSThread(String title, AlignmentView _msa, boolean subgaps, - boolean presorder, Alignment seqset) - { - // jbpnote - transformation should be above here - this is per sequence set contig, not for many contigs. - alTitle = title; - submitGaps = subgaps; - preserveOrder = presorder; - dataset = seqset; - OutputHeader = wsInfo.getProgressText(); - SeqNames = new Hashtable(); - SeqCigar[] msa = _msa.getSequences(); - vamsas.objects.simple.Sequence[] seqarray = new vamsas.objects.simple. - Sequence[msa.length]; - - for (int i = 0,n=0; i < msa.length; i++) - { - String newname = jalview.analysis.SeqsetUtils.unique_name(i); - SequenceI mseq = msa[i].getSeq('-'); - // uniquify as we go - // TODO: JBPNote: this is a ubiquitous transformation - set of jalview seq objects to vamsas sequences with name preservation - SeqNames.put(newname, - jalview.analysis.SeqsetUtils.SeqCharacterHash(mseq)); - seqarray[i] = new vamsas.objects.simple.Sequence(); - seqarray[i].setId(newname); - seqarray[i].setSeq( (submitGaps) ? mseq.getSequence() - : AlignSeq.extractGaps( - jalview.util.Comparison.GapChars, - mseq.getSequence())); - } - - this.seqs = new vamsas.objects.simple.SequenceSet(); - this.seqs.setSeqs(seqarray); - } - - public boolean isCancellable() - { - return true; - } - - public void cancelJob() - { - if ( (jobId != null) && !jobId.equals("") && !jobComplete) - { - String cancelledMessage = ""; - - try - { - vamsas.objects.simple.WsJobId cancelledJob = server.cancel(jobId); - - if (cancelledJob.getStatus() == 2) - { - // CANCELLED_JOB - cancelledMessage = "Job cancelled."; - wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK); - jobComplete = true; - jobsRunning--; - result = null; - } - else if (cancelledJob.getStatus() == 3) - { - // VALID UNSTOPPABLE JOB - cancelledMessage += - "Server cannot cancel this job. just close the window.\n"; - } - - if (cancelledJob.getJobId() != null) - { - cancelledMessage += ("[" + cancelledJob.getJobId() + - "]"); - } - - cancelledMessage += "\n"; - } - catch (Exception exc) - { - cancelledMessage += - ("\nProblems cancelling the job : Exception received...\n" + - exc + "\n"); - exc.printStackTrace(); - } - - wsInfo.setProgressText(OutputHeader + cancelledMessage + "\n"); - } - else - { - if (!jobComplete) - { - wsInfo.setProgressText(OutputHeader + - "Server cannot cancel this job because it has not been submitted properly. just close the window.\n"); - } - } - } - - public void run() - { - StartJob(); - - while (!jobComplete && (allowedServerExceptions > 0)) - { - try - { - if ( (result = server.getResult(jobId)) == null) - { - throw (new Exception( - "Timed out when communicating with server\nTry again later.\n")); - } - jalview.bin.Cache.log.debug("Result state " + result.getState() + - "(ServerError=" + result.isServerError() + - ")"); - if (result.isRunning()) - { - wsInfo.setStatus(WebserviceInfo.STATE_RUNNING); - } - else if (result.isQueued()) - { - wsInfo.setStatus(WebserviceInfo.STATE_QUEUING); - } - - if (result.isFinished()) - { - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK); - wsInfo.showResultsNewFrame.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { - displayResults(true); - } - }); - wsInfo.mergeResults.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { - displayResults(false); - } - }); - wsInfo.setResultsReady(); - parseResult(); - jobComplete = true; - jobsRunning--; - } - else - { - if (result.getStatus() != null) - { - wsInfo.setProgressText(OutputHeader + "\n"+ result.getStatus()); - } - if (result.isServerError()) - { - jobComplete = true; - jobsRunning--; - - break; - } - if (! (result.isJobFailed() || result.isServerError() || - result.isBroken() || result.isFailed())) - { - Thread.sleep(5000); - - // System.out.println("I'm alive "+seqid+" "+jobid); - } - else - { - jobComplete = true; - jobsRunning--; - break; - } - } - } - catch (Exception ex) - { - allowedServerExceptions--; - wsInfo.appendProgressText("\n" + ServiceName + - " Server exception!\n" + ex.getMessage()); - System.err.println(ServiceName + " Server exception: " + - ex.getMessage()); - - // ex.printStackTrace(); JBPNote Debug - try - { - if (allowedServerExceptions > 0) - { - Thread.sleep(5000); - } - } - catch (InterruptedException ex1) - { - } - } - catch(OutOfMemoryError er) - { - jobComplete = true; - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory handling result!!" - +"\nSee help files for increasing Java Virtual Machine memory." - ,"Out of memory", JOptionPane.WARNING_MESSAGE ); - System.out.println("MsaWSClient: "+er); - System.gc(); - } - } - - if (allowedServerExceptions == 0) - { - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); - } - else - { - if (result != null) - { - if ( !(result.isJobFailed() || result.isServerError())) - { - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK); - } - - if (result.isBroken() || result.isFailed()) - { - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); - } - - if (result.isServerError()) - { - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); - } - } - } - } - - void StartJob() - { - try - { - vamsas.objects.simple.WsJobId jobsubmit = server.align(seqs); - - if ( (jobsubmit != null) && (jobsubmit.getStatus() == 1)) - { - jobId = jobsubmit.getJobId(); - System.out.println(WsURL + " Job Id '" + jobId + "'"); - } - else - { - if (jobsubmit == null) - { - throw new Exception("Server at " + WsURL + - " returned null object, it probably cannot be contacted. Try again later ?"); - } - - throw new Exception(jobsubmit.getJobId()); - } - } - catch (Exception e) - { - // TODO: JBPNote catch timeout or other fault types explicitly - // For unexpected errors - System.err.println(WebServiceName + - "Client: Failed to submit the sequences for alignment (probably a server side problem)\n" + - "When contacting Server:" + WsURL + "\n" + - e.toString() + - "\n"); - this.allowedServerExceptions = 0; - wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); - wsInfo.appendProgressText( - "Failed to submit sequences for alignment.\n" + - "It is most likely that there is a problem with the server.\n" + - "Just close the window\n"); - - // e.printStackTrace(); // TODO: JBPNote DEBUG - } - } - - private jalview.datamodel.Sequence[] getVamsasAlignment( - vamsas.objects.simple.Alignment valign) - { - vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs(); - jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs. - length]; - - for (int i = 0, j = seqs.length; i < j; i++) - { - msa[i] = new jalview.datamodel.Sequence(seqs[i].getId(), - seqs[i].getSeq()); - } - - return msa; - } - - void parseResult() - { - - try - { - // OutputHeader = output.getText(); - if (result.isFailed()) - { - OutputHeader += "Job failed.\n"; - } - - if (result.getStatus() != null) - { - OutputHeader += ("\n" + result.getStatus()); - } - - if (result.getMsa() != null) - { - OutputHeader += "\nAlignment Object Method Notes\n"; - - String[] lines = result.getMsa().getMethod(); - - for (int line = 0; line < lines.length; line++) - { - OutputHeader += (lines[line] + "\n"); - } - - // JBPNote The returned files from a webservice could be - // hidden behind icons in the monitor window that, - // when clicked, pop up their corresponding data - } - - wsInfo.setProgressText(OutputHeader); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - void displayResults(boolean newFrame) - { - SequenceI [] seqs = getVamsasAlignment(result.getMsa()); - - if (seqs != null) - { - AlignmentOrder msaorder = new AlignmentOrder(seqs); - - if (preserveOrder) - { - jalview.analysis.AlignmentSorter.recoverOrder(seqs); - } - - jalview.analysis.SeqsetUtils.deuniquify(SeqNames, seqs); - - Alignment al = new Alignment(seqs); - if (dataset!=null) - { - al.setDataset(dataset); - } - - if(newFrame) - { - // TODO: JBPNote Should also rename the query sequence sometime... - AlignFrame af = new AlignFrame(al); - - //>>>This is a fix for the moment, until a better solution is found!!<<< - af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer()); - - af.addSortByOrderMenuItem(ServiceName + " Ordering", - msaorder); - - Desktop.addInternalFrame(af, alTitle, - AlignFrame.NEW_WINDOW_WIDTH, - AlignFrame.NEW_WINDOW_HEIGHT); - - } - else - { - System.out.println("MERGE WITH OLD FRAME"); - - } - } - } - } }