X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FWSWUBlastClient.java;h=33d6d9289db1cef413e2448e581d2e50cf594768;hb=8a18973f7e4521c7dd3705ebd8fabd3ca08cfcaf;hp=29a0900aa4ed54d1b0d1590a0c668326a3cc1211;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/io/WSWUBlastClient.java b/src/jalview/io/WSWUBlastClient.java index 29a0900..33d6d92 100755 --- a/src/jalview/io/WSWUBlastClient.java +++ b/src/jalview/io/WSWUBlastClient.java @@ -33,23 +33,40 @@ import javax.swing.*; import javax.xml.namespace.QName; -public class WSWUBlastClient { +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class WSWUBlastClient +{ CutAndPasteTransfer output = new CutAndPasteTransfer(); int jobsRunning = 0; - public WSWUBlastClient(AlignmentI al, ArrayList ids) { + /** + * Creates a new WSWUBlastClient object. + * + * @param al DOCUMENT ME! + * @param ids DOCUMENT ME! + */ + public WSWUBlastClient(AlignmentI al, ArrayList ids) + { 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(output, "BLASTing for unidentified sequences ", 800, 300); - for (int i = 0; i < ids.size(); i++) { + for (int i = 0; i < ids.size(); i++) + { SequenceI sequence = al.findName(ids.get(i).toString()); StringBuffer nonGapped = new StringBuffer(); - for (int n = 0; n < sequence.getSequence().length(); n++) { - if (!jalview.util.Comparison.isGap(sequence.getCharAt(n))) { + for (int n = 0; n < sequence.getSequence().length(); n++) + { + if (!jalview.util.Comparison.isGap(sequence.getCharAt(n))) + { nonGapped.append(sequence.getCharAt(n)); } } @@ -64,29 +81,41 @@ public class WSWUBlastClient { thread.start(); } - void parseResult(String id1, String res) { + /** + * DOCUMENT ME! + * + * @param id1 DOCUMENT ME! + * @param res DOCUMENT ME! + */ + void parseResult(String id1, String res) + { StringTokenizer st = new StringTokenizer(res, "\n"); String data; String id2; int maxFound = 90; StringBuffer buffer = new StringBuffer("\n\n" + id1 + " :"); - while (st.hasMoreTokens()) { + while (st.hasMoreTokens()) + { data = st.nextToken(); - if (data.indexOf("database=\"uniprot\" id=") > -1) { + if (data.indexOf("database=\"uniprot\" id=") > -1) + { int index = data.indexOf("database=\"uniprot\" id=") + 23; id2 = data.substring(index, data.indexOf("\"", index)); - while (data.indexOf("") == -1) { + while (data.indexOf("") == -1) + { data = st.nextToken(); - if (data.indexOf("") > -1) { + if (data.indexOf("") > -1) + { int value = Integer.parseInt(data.substring(data.indexOf( "") + 10, data.indexOf(""))); - if (value >= maxFound) { + if (value >= maxFound) + { maxFound = value; buffer.append(" " + id2 + " " + value + "%; "); } @@ -98,65 +127,81 @@ public class WSWUBlastClient { output.setText(output.getText() + buffer.toString()); } - class ImageTwirler extends Thread { + class ImageTwirler extends Thread + { ImageIcon[] imageIcon; int imageIndex = 0; - public ImageTwirler() { + public ImageTwirler() + { imageIcon = new ImageIcon[9]; - for (int i = 0; i < 9; i++) { + for (int i = 0; i < 9; i++) + { java.net.URL url = getClass().getResource("/images/dna" + (i + 1) + ".gif"); - if (url != null) { + if (url != null) + { imageIcon[i] = new ImageIcon(url); } } } - public void run() { - while (jobsRunning > 0) { - try { + public void run() + { + while (jobsRunning > 0) + { + try + { Thread.sleep(100); imageIndex++; imageIndex %= 9; output.setFrameIcon(imageIcon[imageIndex]); output.setTitle("BLASTing for unidentified sequences - " + jobsRunning + " jobs running."); - } catch (Exception ex) { + } + catch (Exception ex) + { } } } } - class BlastThread extends Thread { + class BlastThread extends Thread + { String sequence; String seqid; String jobid; boolean jobComplete = false; - BlastThread(String id, String sequence) { + BlastThread(String id, String sequence) + { this.sequence = sequence; seqid = id; } - public void run() { + public void run() + { StartJob(); - while (!jobComplete) { - try { + 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[] { + String result = (String) call.invoke(new Object[] + { jobid, "xml" }); if ((result.indexOf("JOB PENDING") == -1) && - (result.indexOf("JOB RUNNING") == -1)) { + (result.indexOf("JOB RUNNING") == -1)) + { parseResult(seqid, result); jobComplete = true; jobsRunning--; @@ -165,12 +210,15 @@ public class WSWUBlastClient { Thread.sleep(5000); // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug - } catch (Exception ex) { + } + catch (Exception ex) + { } } } - void StartJob() { + void StartJob() + { HashMap params = new HashMap(); params.put("database", "uniprot"); params.put("sensitivity", "low"); @@ -183,20 +231,24 @@ public class WSWUBlastClient { byte[] seqbytes = sequence.getBytes(); - try { + 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[] { + String result = (String) call.invoke(new Object[] + { params, seqbytes }); jobid = result; System.out.println( "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '" + jobid + "'"); - } catch (Exception exp) { + } + catch (Exception exp) + { System.err.println("WSWUBlastClient error:\n" + exp.toString()); exp.printStackTrace(); }