From 4f561ae47b0155fe5a76831f09c0812498f10ea3 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 9 Feb 2005 15:29:57 +0000 Subject: [PATCH] Blasts asynchronously --- src/jalview/io/WSWUBlastClient.java | 145 ++++++++++++++++++++++++++--------- 1 file changed, 109 insertions(+), 36 deletions(-) diff --git a/src/jalview/io/WSWUBlastClient.java b/src/jalview/io/WSWUBlastClient.java index ed29f89..f2c2047 100755 --- a/src/jalview/io/WSWUBlastClient.java +++ b/src/jalview/io/WSWUBlastClient.java @@ -6,19 +6,23 @@ import java.util.*; import jalview.datamodel.*; import jalview.gui.*; import javax.swing.*; +import java.util.*; +import java.awt.*; public class WSWUBlastClient { - CutAndPasteTransfer cap = new CutAndPasteTransfer(false); + JInternalFrame outputFrame = new JInternalFrame(); + CutAndPasteTransfer output = new CutAndPasteTransfer(false); + int jobsRunning = 0; public WSWUBlastClient(AlignmentI al, ArrayList ids) { - JInternalFrame frame = new JInternalFrame(); - cap.formatForOutput(); - frame.setContentPane(cap); - cap.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered." + + output.formatForOutput(); + outputFrame.setContentPane(output); + output.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered." +"\nIn order to display these features, try changing the names of your sequences to the ids suggested below."); - Desktop.addInternalFrame(frame, "BLASTing for unidentified sequences ", 800,300); + Desktop.addInternalFrame(outputFrame, "BLASTing for unidentified sequences ", 800,300); for(int i=0; i0) + { + try{ + Thread.sleep(100); + imageIndex++; + imageIndex %=9; + outputFrame.setFrameIcon( imageIcon[imageIndex]); + outputFrame.setTitle("BLASTing for unidentified sequences - "+jobsRunning+" jobs running."); + }catch(Exception ex){} + + } + } } + + + class BlastThread extends Thread { String sequence; - String id; + String seqid; + String jobid; + boolean jobComplete = false; + BlastThread(String id, String sequence) { this.sequence = sequence; - this.id = id; + seqid = id; } public void run() { - FindUniprotIDFromUnknownSequence(id, sequence); - } - } + StartJob(); - public void FindUniprotIDFromUnknownSequence (String id, String s) - { - HashMap params = new HashMap(); - params.put("database", "uniprot"); - params.put("sensitivity","low"); - params.put("sort","totalscore"); - params.put("matrix","pam10"); - params.put("program","blastp"); - params.put("alignments","5"); - params.put("outformat","xml"); - byte[] sequence = s.getBytes(); - - try { - Call call = (Call) new Service().createCall(); - call.setTargetEndpointAddress (new java.net.URL("http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast")); - call.setOperationName(new QName("WSWUBlast", "doWUBlast")); - - String result = (String) call.invoke(new Object[] {params,sequence}); - parseResult(id, result); - } - catch (Exception exp) { - System.err.println ("ERROR:\n" + exp.toString()); - exp.printStackTrace(); + while (!jobComplete) + { + try + { + Call call = (Call)new Service().createCall(); + call.setTargetEndpointAddress(new java.net.URL( + "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast")); + call.setOperationName(new QName("WSWUBlast", "polljob")); + String result = (String) call.invoke(new Object[] + {jobid, "xml"}); + if(result.indexOf("JOB PENDING")==-1 && result.indexOf("JOB RUNNING")==-1) + { + parseResult(seqid, result); + jobComplete = true; + jobsRunning --; + } + Thread.sleep(5000); + System.out.println("I'm alive "+seqid+" "+jobid); } + catch (Exception ex) + {} + } + } + + void StartJob() + { + HashMap params = new HashMap(); + params.put("database", "uniprot"); + params.put("sensitivity", "low"); + params.put("sort", "totalscore"); + params.put("matrix", "pam10"); + params.put("program", "blastp"); + params.put("alignments", "5"); + params.put("outformat", "xml"); + params.put("searchtype", "1"); + byte[] seqbytes = sequence.getBytes(); + + try + { + Call call = (Call)new Service().createCall(); + call.setTargetEndpointAddress(new java.net.URL( + "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast")); + call.setOperationName(new QName("WSWUBlast", "doWUBlast")); + String result = (String) call.invoke(new Object[] + {params, seqbytes}); + jobid = result; + System.out.println(jobid); + + } + catch (Exception exp) + { + System.err.println("ERROR:\n" + exp.toString()); + exp.printStackTrace(); + } } + } void parseResult(String id1, String res) { @@ -113,7 +186,7 @@ public class WSWUBlastClient } - cap.setText(cap.getText()+buffer.toString()); + output.setText(output.getText()+buffer.toString()); } } -- 1.7.10.2