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 JInternalFrame outputFrame = new JInternalFrame();
\r
15 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
16 int jobsRunning = 0;
\r
18 public WSWUBlastClient(AlignmentI al, ArrayList ids)
\r
20 outputFrame.setContentPane(output);
\r
21 output.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered."
\r
22 +"\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
23 Desktop.addInternalFrame(outputFrame, "BLASTing for unidentified sequences ", 800,300);
\r
25 for(int i=0; i<ids.size(); i++)
\r
27 SequenceI sequence = al.findName( ids.get(i).toString() );
\r
28 StringBuffer nonGapped = new StringBuffer();
\r
29 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
31 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
32 nonGapped.append(sequence.getCharAt(n));
\r
35 BlastThread thread = new BlastThread(ids.get(i).toString(), nonGapped.toString());
\r
39 ImageTwirler thread = new ImageTwirler();
\r
43 class ImageTwirler extends Thread
\r
45 ImageIcon [] imageIcon;
\r
47 public ImageTwirler()
\r
49 imageIcon = new ImageIcon[9];
\r
50 for(int i=0; i<9; i++)
\r
52 java.net.URL url = getClass().getResource("/images/dna" + (i+1) + ".gif");
\r
54 imageIcon[i] = new ImageIcon(url);
\r
60 while(jobsRunning>0)
\r
66 outputFrame.setFrameIcon( imageIcon[imageIndex]);
\r
67 outputFrame.setTitle("BLASTing for unidentified sequences - "+jobsRunning+" jobs running.");
\r
69 }catch(Exception ex){}
\r
78 class BlastThread extends Thread
\r
83 boolean jobComplete = false;
\r
85 BlastThread(String id, String sequence)
\r
87 this.sequence = sequence;
\r
95 while (!jobComplete)
\r
99 Call call = (Call)new Service().createCall();
\r
100 call.setTargetEndpointAddress(new java.net.URL(
\r
101 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
102 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
103 String result = (String) call.invoke(new Object[]
\r
105 if(result.indexOf("JOB PENDING")==-1 && result.indexOf("JOB RUNNING")==-1)
\r
107 parseResult(seqid, result);
\r
108 jobComplete = true;
\r
111 Thread.sleep(5000);
\r
112 // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
114 catch (Exception ex)
\r
121 HashMap params = new HashMap();
\r
122 params.put("database", "uniprot");
\r
123 params.put("sensitivity", "low");
\r
124 params.put("sort", "totalscore");
\r
125 params.put("matrix", "pam10");
\r
126 params.put("program", "blastp");
\r
127 params.put("alignments", "5");
\r
128 params.put("outformat", "xml");
\r
129 params.put("searchtype", "1");
\r
130 byte[] seqbytes = sequence.getBytes();
\r
134 Call call = (Call)new Service().createCall();
\r
135 call.setTargetEndpointAddress(new java.net.URL(
\r
136 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
137 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
138 String result = (String) call.invoke(new Object[]
\r
139 {params, seqbytes});
\r
141 System.out.println("http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '"+jobid+"'");
\r
144 catch (Exception exp)
\r
146 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
147 exp.printStackTrace();
\r
152 void parseResult(String id1, String res)
\r
154 StringTokenizer st = new StringTokenizer(res, "\n");
\r
158 StringBuffer buffer = new StringBuffer("\n\n"+id1+" :");
\r
160 while( st.hasMoreTokens() )
\r
162 data = st.nextToken();
\r
164 if(data.indexOf("database=\"uniprot\" id=")>-1)
\r
166 int index = data.indexOf("database=\"uniprot\" id=")+ 23;
\r
167 id2 = data.substring( index, data.indexOf("\"", index) );
\r
168 while( data.indexOf("</alignment>")==-1)
\r
170 data = st.nextToken();
\r
171 if(data.indexOf("<identity>")>-1)
\r
173 int value = Integer.parseInt( data.substring(data.indexOf("<identity>")+10, data.indexOf("</identity>")));
\r
174 if(value>=maxFound)
\r
177 buffer.append(" "+ id2 + " " + value+"%; ");
\r
187 output.setText(output.getText()+buffer.toString());
\r