X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fws%2FMsaWSThread.java;h=93a76d06ecf6d76608b95872cc4f6c4ebe329018;hb=297480d2e19bf7737f6ad250e044aafe64fa63e7;hp=9706c182b5a7b9bd951c5fbbdcb8318063a7f3a3;hpb=49685e6426d5ac136dce4907196751680c667670;p=jalview.git diff --git a/src/jalview/ws/MsaWSThread.java b/src/jalview/ws/MsaWSThread.java index 9706c18..93a76d0 100644 --- a/src/jalview/ws/MsaWSThread.java +++ b/src/jalview/ws/MsaWSThread.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2) + * Copyright (C) 2009 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 @@ -31,24 +31,23 @@ import vamsas.objects.simple.MsaResult; *
* Title: *
- * + * ** Description: *
- * + * ** Copyright: Copyright (c) 2004 *
- * + * ** Company: Dundee University *
- * + * * @author not attributable * @version 1.0 */ -class MsaWSThread - extends WSThread implements WSClientI +class MsaWSThread extends WSThread implements WSClientI { boolean submitGaps = false; // pass sequences including gaps to alignment @@ -58,20 +57,18 @@ class MsaWSThread // order - class MsaWSJob - extends WSThread.WSJob + class MsaWSJob extends WSThread.WSJob { // hold special input for this - vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple. - SequenceSet(); + vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple.SequenceSet(); /** * MsaWSJob - * + * * @param jobNum - * int + * int * @param jobId - * String + * String */ public MsaWSJob(int jobNum, SequenceI[] inSeqs) { @@ -88,11 +85,16 @@ class MsaWSThread } Hashtable SeqNames = new Hashtable(); + Vector emptySeqs = new Vector(); + /** * prepare input sequences for MsaWS service - * @param seqs jalview sequences to be prepared - * @param minlen minimum number of residues required for this MsaWS service + * + * @param seqs + * jalview sequences to be prepared + * @param minlen + * minimum number of residues required for this MsaWS service * @return true if seqs contains sequences to be submitted to service. */ private boolean prepareInput(SequenceI[] seqs, int minlen) @@ -100,7 +102,8 @@ class MsaWSThread int nseqs = 0; if (minlen < 0) { - throw new Error("Implementation error: minlen must be zero or more."); + throw new Error( + "Implementation error: minlen must be zero or more."); } for (int i = 0; i < seqs.length; i++) { @@ -110,10 +113,8 @@ class MsaWSThread } } boolean valid = nseqs > 1; // need at least two seqs - vamsas.objects.simple.Sequence[] seqarray = - (valid) - ? new vamsas.objects.simple.Sequence[nseqs] - : null; + vamsas.objects.simple.Sequence[] seqarray = (valid) ? new vamsas.objects.simple.Sequence[nseqs] + : null; for (int i = 0, n = 0; i < seqs.length; i++) { @@ -122,28 +123,26 @@ class MsaWSThread // any // subjob SeqNames.put(newname, jalview.analysis.SeqsetUtils - .SeqCharacterHash(seqs[i])); + .SeqCharacterHash(seqs[i])); if (valid && seqs[i].getEnd() - seqs[i].getStart() > minlen - 1) { seqarray[n] = new vamsas.objects.simple.Sequence(); seqarray[n].setId(newname); - seqarray[n++].setSeq( (submitGaps) ? seqs[i].getSequenceAsString() - : AlignSeq.extractGaps( - jalview.util.Comparison.GapChars, seqs[i] - .getSequenceAsString())); + seqarray[n++].setSeq((submitGaps) ? seqs[i].getSequenceAsString() + : AlignSeq.extractGaps(jalview.util.Comparison.GapChars, + seqs[i].getSequenceAsString())); } else { String empty = null; if (seqs[i].getEnd() >= seqs[i].getStart()) { - empty = (submitGaps) ? seqs[i].getSequenceAsString() - : AlignSeq.extractGaps( - jalview.util.Comparison.GapChars, seqs[i] - .getSequenceAsString()); + empty = (submitGaps) ? seqs[i].getSequenceAsString() : AlignSeq + .extractGaps(jalview.util.Comparison.GapChars, seqs[i] + .getSequenceAsString()); } emptySeqs.add(new String[] - {newname, empty}); + { newname, empty }); } } this.seqs = new vamsas.objects.simple.SequenceSet(); @@ -152,14 +151,14 @@ class MsaWSThread } /** - * + * * @return true if getAlignment will return a valid alignment result. */ public boolean hasResults() { if (subjobComplete && result != null && result.isFinished() - && ( (MsaResult) result).getMsa() != null && - ( (MsaResult) result).getMsa().getSeqs() != null) + && ((MsaResult) result).getMsa() != null + && ((MsaResult) result).getMsa().getSeqs() != null) { return true; } @@ -174,10 +173,11 @@ class MsaWSThread SequenceI[] alseqs = null; char alseq_gapchar = '-'; int alseq_l = 0; - if ( ( (MsaResult) result).getMsa() != null) + if (((MsaResult) result).getMsa() != null) { - alseqs = getVamsasAlignment( ( (MsaResult) result).getMsa()); - alseq_gapchar = ( (MsaResult) result).getMsa().getGapchar().charAt(0); + alseqs = getVamsasAlignment(((MsaResult) result).getMsa()); + alseq_gapchar = ((MsaResult) result).getMsa().getGapchar() + .charAt(0); alseq_l = alseqs.length; } if (emptySeqs.size() > 0) @@ -225,8 +225,8 @@ class MsaWSThread if (nw > sw) { // pad at end - alseqs[i].setSequence(t_alseqs[i].getSequenceAsString() + - insbuff.substring(0, sw - nw)); + alseqs[i].setSequence(t_alseqs[i].getSequenceAsString() + + insbuff.substring(0, sw - nw)); } } } @@ -235,23 +235,22 @@ class MsaWSThread String[] es = (String[]) emptySeqs.get(i); if (es[1] == null) { - t_alseqs[i + - alseq_l] = new jalview.datamodel.Sequence(es[0], - insbuff.toString(), 1, 0); + t_alseqs[i + alseq_l] = new jalview.datamodel.Sequence(es[0], + insbuff.toString(), 1, 0); } else { if (es[1].length() < nw) { - t_alseqs[i + - alseq_l] = new jalview.datamodel.Sequence(es[0], - es[1] + insbuff.substring(0, nw - es[1].length()), 1, - 1 + es[1].length()); + t_alseqs[i + alseq_l] = new jalview.datamodel.Sequence( + es[0], + es[1] + insbuff.substring(0, nw - es[1].length()), + 1, 1 + es[1].length()); } else { - t_alseqs[i + - alseq_l] = new jalview.datamodel.Sequence(es[0], es[1]); + t_alseqs[i + alseq_l] = new jalview.datamodel.Sequence( + es[0], es[1]); } } } @@ -263,8 +262,7 @@ class MsaWSThread // account for any missing sequences jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs); return new Object[] - { - alseqs, msaorder}; + { alseqs, msaorder }; } return null; } @@ -280,7 +278,7 @@ class MsaWSThread } /** - * + * * @return boolean true if job can be submitted. */ boolean hasValidInput() @@ -294,23 +292,25 @@ class MsaWSThread } String alTitle; // name which will be used to form new alignment window. + Alignment dataset; // dataset to which the new alignment will be // associated. ext.vamsas.MuscleWS server = null; + /** * set basic options for this (group) of Msa jobs - * + * * @param subgaps - * boolean + * boolean * @param presorder - * boolean + * boolean */ MsaWSThread(ext.vamsas.MuscleWS server, String wsUrl, - WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame, - AlignmentView alview, - String wsname, boolean subgaps, boolean presorder) + WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame, + AlignmentView alview, String wsname, boolean subgaps, + boolean presorder) { super(alFrame, wsinfo, alview, wsname, wsUrl); this.server = server; @@ -320,22 +320,22 @@ class MsaWSThread /** * create one or more Msa jobs to align visible seuqences in _msa - * + * * @param title - * String + * String * @param _msa - * AlignmentView + * AlignmentView * @param subgaps - * boolean + * boolean * @param presorder - * boolean + * boolean * @param seqset - * Alignment + * Alignment */ MsaWSThread(ext.vamsas.MuscleWS server, String wsUrl, - WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame, - String wsname, String title, AlignmentView _msa, boolean subgaps, - boolean presorder, Alignment seqset) + WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame, + String wsname, String title, AlignmentView _msa, boolean subgaps, + boolean presorder, Alignment seqset) { this(server, wsUrl, wsinfo, alFrame, _msa, wsname, subgaps, presorder); OutputHeader = wsInfo.getProgressText(); @@ -359,7 +359,9 @@ class MsaWSThread } if (njobs > 0) { - wsinfo.setProgressName("region " + jobs[j].jobnum, jobs[j].jobnum); + wsinfo + .setProgressName("region " + jobs[j].jobnum, + jobs[j].jobnum); } wsinfo.setProgressText(jobs[j].jobnum, OutputHeader); } @@ -384,23 +386,22 @@ class MsaWSThread try { vamsas.objects.simple.WsJobId cancelledJob = server - .cancel(jobs[job].jobId); + .cancel(jobs[job].jobId); if (cancelledJob.getStatus() == 2) { // CANCELLED_JOB cancelledMessage = "Job cancelled."; - ( (MsaWSJob) jobs[job]).cancel(); + ((MsaWSJob) jobs[job]).cancel(); wsInfo.setStatus(jobs[job].jobnum, - WebserviceInfo.STATE_CANCELLED_OK); + WebserviceInfo.STATE_CANCELLED_OK); } else if (cancelledJob.getStatus() == 3) { // VALID UNSTOPPABLE JOB - cancelledMessage += - "Server cannot cancel this job. just close the window.\n"; + cancelledMessage += "Server cannot cancel this job. just close the window.\n"; cancelled = false; // wsInfo.setStatus(jobs[job].jobnum, - // WebserviceInfo.STATE_RUNNING); + // WebserviceInfo.STATE_RUNNING); } if (cancelledJob.getJobId() != null) @@ -409,17 +410,15 @@ class MsaWSThread } cancelledMessage += "\n"; - } - catch (Exception exc) + } catch (Exception exc) { - cancelledMessage += - ("\nProblems cancelling the job : Exception received...\n" - + exc + "\n"); - Cache.log.warn("Exception whilst cancelling " + jobs[job].jobId, - exc); + cancelledMessage += ("\nProblems cancelling the job : Exception received...\n" + + exc + "\n"); + Cache.log.warn( + "Exception whilst cancelling " + jobs[job].jobId, exc); } wsInfo.setProgressText(jobs[job].jobnum, OutputHeader - + cancelledMessage + "\n"); + + cancelledMessage + "\n"); } } if (cancelled) @@ -434,31 +433,31 @@ class MsaWSThread if (!jobComplete) { wsInfo - .setProgressText(OutputHeader - + "Server cannot cancel this job because it has not been submitted properly. just close the window.\n"); + .setProgressText(OutputHeader + + "Server cannot cancel this job because it has not been submitted properly. just close the window.\n"); } } } - void pollJob(WSJob job) - throws Exception + void pollJob(WSJob job) throws Exception { - ( (MsaWSJob) job).result = server.getResult( ( (MsaWSJob) job).jobId); + ((MsaWSJob) job).result = server.getResult(((MsaWSJob) job).jobId); } void StartJob(WSJob job) { - if (! (job instanceof MsaWSJob)) + if (!(job instanceof MsaWSJob)) { - throw new Error("StartJob(MsaWSJob) called on a WSJobInstance " + - job.getClass()); + throw new Error("StartJob(MsaWSJob) called on a WSJobInstance " + + job.getClass()); } MsaWSJob j = (MsaWSJob) job; if (j.submitted) { if (Cache.log.isDebugEnabled()) { - Cache.log.debug("Tried to submit an already submitted job " + j.jobId); + Cache.log.debug("Tried to submit an already submitted job " + + j.jobId); } return; } @@ -469,13 +468,13 @@ class MsaWSThread j.result = new MsaResult(); j.result.setFinished(true); j.result.setStatus("Empty Alignment Job"); - ( (MsaResult) j.result).setMsa(null); + ((MsaResult) j.result).setMsa(null); } try { vamsas.objects.simple.WsJobId jobsubmit = server.align(j.seqs); - if ( (jobsubmit != null) && (jobsubmit.getStatus() == 1)) + if ((jobsubmit != null) && (jobsubmit.getStatus() == 1)) { j.jobId = jobsubmit.getJobId(); j.submitted = true; @@ -487,50 +486,47 @@ class MsaWSThread if (jobsubmit == null) { throw new Exception( - "Server at " - + WsUrl - + - " returned null object, it probably cannot be contacted. Try again later ?"); + "Server at " + + WsUrl + + " returned null object, it probably cannot be contacted. Try again later ?"); } throw new Exception(jobsubmit.getJobId()); } - } - catch (Exception e) + } 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"); + .println(WebServiceName + + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n" + + "When contacting Server:" + WsUrl + "\n" + + e.toString() + "\n"); j.allowedServerExceptions = 0; wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_SERVERERROR); wsInfo - .appendProgressText( - j.jobnum, - "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"); + .appendProgressText( + j.jobnum, + "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.Alignment valign) { // TODO: refactor to helper class for vamsas.objects.simple objects vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs(); - jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs. - length]; + 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()); + .getSeq()); } return msa; @@ -545,54 +541,52 @@ class MsaWSThread for (int j = 0; j < jobs.length; j++) { finalState.updateJobPanelState(wsInfo, OutputHeader, jobs[j]); - if (jobs[j].submitted && jobs[j].subjobComplete && jobs[j].hasResults()) + if (jobs[j].submitted && jobs[j].subjobComplete + && jobs[j].hasResults()) { results++; - vamsas.objects.simple.Alignment valign = ( (MsaResult) jobs[j].result). - getMsa(); + vamsas.objects.simple.Alignment valign = ((MsaResult) jobs[j].result) + .getMsa(); if (valign != null) { wsInfo.appendProgressText(jobs[j].jobnum, - "\nAlignment Object Method Notes\n"); + "\nAlignment Object Method Notes\n"); String[] lines = valign.getMethod(); for (int line = 0; line < lines.length; line++) { wsInfo.appendProgressText(jobs[j].jobnum, lines[line] + "\n"); } // JBPNote The returned files from a webservice could be - // hidden behind icons in the monitor window that, + // hidden behind icons in the monitor window that, // when clicked, pop up their corresponding data } } } - } - catch (Exception ex) + } catch (Exception ex) { - Cache.log.error("Unexpected exception when processing results for " + - alTitle, ex); + Cache.log.error("Unexpected exception when processing results for " + + alTitle, ex); wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); } if (results > 0) { wsInfo.showResultsNewFrame - .addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed( - java.awt.event.ActionEvent evt) - { - displayResults(true); - } - }); + .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); - } - }); + .addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(java.awt.event.ActionEvent evt) + { + displayResults(false); + } + }); wsInfo.setResultsReady(); } else @@ -611,12 +605,12 @@ class MsaWSThread { if (jobs[j].hasResults()) { - Object[] res = ( (MsaWSJob) jobs[j]).getAlignment(); + Object[] res = ((MsaWSJob) jobs[j]).getAlignment(); alorders.add(res[1]); results[j] = (SequenceI[]) res[0]; orders[j] = (AlignmentOrder) res[1]; - -// SequenceI[] alignment = input.getUpdated + + // SequenceI[] alignment = input.getUpdated } else { @@ -633,7 +627,8 @@ class MsaWSThread SequenceI[] alignment = (SequenceI[]) newview[0]; ColumnSelection columnselection = (ColumnSelection) newview[1]; Alignment al = new Alignment(alignment); - // TODO: add 'provenance' property to alignment from the method notes accompanying each subjob + // TODO: add 'provenance' property to alignment from the method notes + // accompanying each subjob if (dataset != null) { al.setDataset(dataset); @@ -645,19 +640,17 @@ class MsaWSThread if (newFrame) { AlignFrame af = new AlignFrame(al, columnselection, - AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // initialise with same renderer settings as in parent alignframe. - af.getFeatureRenderer().transferSettings( - this.featureSettings); + af.getFeatureRenderer().transferSettings(this.featureSettings); // update orders if (alorders.size() > 0) { if (alorders.size() == 1) { af.addSortByOrderMenuItem(WebServiceName + " Ordering", - (AlignmentOrder) alorders.get(0)); + (AlignmentOrder) alorders.get(0)); } else { @@ -670,8 +663,8 @@ class MsaWSThread while (j < l) { - if ( ( (AlignmentOrder) alorders.get(i)).equals( ( ( - AlignmentOrder) alorders.get(j)))) + if (((AlignmentOrder) alorders.get(i)) + .equals(((AlignmentOrder) alorders.get(j)))) { alorders.remove(j); l--; @@ -695,22 +688,22 @@ class MsaWSThread for (int i = 0, l = alorders.size(); i < l; i++) { af.addSortByOrderMenuItem(WebServiceName - + ( (String) names.get(i)) + - " Ordering", - (AlignmentOrder) alorders.get(i)); + + ((String) names.get(i)) + " Ordering", + (AlignmentOrder) alorders.get(i)); } } } - Desktop.addInternalFrame(af, alTitle, - AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); + Desktop.addInternalFrame(af, alTitle, AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); } else { System.out.println("MERGE WITH OLD FRAME"); - // TODO: modify alignment in original frame, replacing old for new alignment using the commands.EditCommand model to ensure the update can be undone + // TODO: modify alignment in original frame, replacing old for new + // alignment using the commands.EditCommand model to ensure the update can + // be undone } }