3 import org.apache.axis.client.*;
\r
4 import javax.xml.namespace.QName;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.gui.*;
\r
8 import javax.swing.*;
\r
12 public class WSWUBlastClient
\r
14 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
15 int jobsRunning = 0;
\r
17 public WSWUBlastClient(AlignmentI al, ArrayList ids)
\r
19 output.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered."
\r
20 +"\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
21 Desktop.addInternalFrame(output, "BLASTing for unidentified sequences ", 800,300);
\r
23 for(int i=0; i<ids.size(); i++)
\r
25 SequenceI sequence = al.findName( ids.get(i).toString() );
\r
26 StringBuffer nonGapped = new StringBuffer();
\r
27 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
29 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
30 nonGapped.append(sequence.getCharAt(n));
\r
33 BlastThread thread = new BlastThread(ids.get(i).toString(), nonGapped.toString());
\r
37 ImageTwirler thread = new ImageTwirler();
\r
41 class ImageTwirler extends Thread
\r
43 ImageIcon [] imageIcon;
\r
45 public ImageTwirler()
\r
47 imageIcon = new ImageIcon[9];
\r
48 for(int i=0; i<9; i++)
\r
50 java.net.URL url = getClass().getResource("/images/dna" + (i+1) + ".gif");
\r
52 imageIcon[i] = new ImageIcon(url);
\r
58 while(jobsRunning>0)
\r
64 output.setFrameIcon( imageIcon[imageIndex]);
\r
65 output.setTitle("BLASTing for unidentified sequences - "+jobsRunning+" jobs running.");
\r
67 }catch(Exception ex){}
\r
76 class BlastThread extends Thread
\r
81 boolean jobComplete = false;
\r
83 BlastThread(String id, String sequence)
\r
85 this.sequence = sequence;
\r
93 while (!jobComplete)
\r
97 Call call = (Call)new Service().createCall();
\r
98 call.setTargetEndpointAddress(new java.net.URL(
\r
99 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
100 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
101 String result = (String) call.invoke(new Object[]
\r
103 if(result.indexOf("JOB PENDING")==-1 && result.indexOf("JOB RUNNING")==-1)
\r
105 parseResult(seqid, result);
\r
106 jobComplete = true;
\r
109 Thread.sleep(5000);
\r
110 // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
112 catch (Exception ex)
\r
119 HashMap params = new HashMap();
\r
120 params.put("database", "uniprot");
\r
121 params.put("sensitivity", "low");
\r
122 params.put("sort", "totalscore");
\r
123 params.put("matrix", "pam10");
\r
124 params.put("program", "blastp");
\r
125 params.put("alignments", "5");
\r
126 params.put("outformat", "xml");
\r
127 params.put("searchtype", "1");
\r
128 byte[] seqbytes = sequence.getBytes();
\r
132 Call call = (Call)new Service().createCall();
\r
133 call.setTargetEndpointAddress(new java.net.URL(
\r
134 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
135 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
136 String result = (String) call.invoke(new Object[]
\r
137 {params, seqbytes});
\r
139 System.out.println("http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '"+jobid+"'");
\r
142 catch (Exception exp)
\r
144 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
145 exp.printStackTrace();
\r
150 void parseResult(String id1, String res)
\r
152 StringTokenizer st = new StringTokenizer(res, "\n");
\r
156 StringBuffer buffer = new StringBuffer("\n\n"+id1+" :");
\r
158 while( st.hasMoreTokens() )
\r
160 data = st.nextToken();
\r
162 if(data.indexOf("database=\"uniprot\" id=")>-1)
\r
164 int index = data.indexOf("database=\"uniprot\" id=")+ 23;
\r
165 id2 = data.substring( index, data.indexOf("\"", index) );
\r
166 while( data.indexOf("</alignment>")==-1)
\r
168 data = st.nextToken();
\r
169 if(data.indexOf("<identity>")>-1)
\r
171 int value = Integer.parseInt( data.substring(data.indexOf("<identity>")+10, data.indexOf("</identity>")));
\r
172 if(value>=maxFound)
\r
175 buffer.append(" "+ id2 + " " + value+"%; ");
\r
185 output.setText(output.getText()+buffer.toString());
\r