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(false);
\r
16 int jobsRunning = 0;
\r
18 public WSWUBlastClient(AlignmentI al, ArrayList ids)
\r
21 output.formatForOutput();
\r
22 outputFrame.setContentPane(output);
\r
23 output.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered."
\r
24 +"\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
25 Desktop.addInternalFrame(outputFrame, "BLASTing for unidentified sequences ", 800,300);
\r
27 for(int i=0; i<ids.size(); i++)
\r
29 SequenceI sequence = al.findName( ids.get(i).toString() );
\r
30 StringBuffer nonGapped = new StringBuffer();
\r
31 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
33 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
34 nonGapped.append(sequence.getCharAt(n));
\r
37 BlastThread thread = new BlastThread(ids.get(i).toString(), nonGapped.toString());
\r
41 ImageTwirler thread = new ImageTwirler();
\r
45 class ImageTwirler extends Thread
\r
47 ImageIcon [] imageIcon;
\r
49 public ImageTwirler()
\r
51 imageIcon = new ImageIcon[9];
\r
52 for(int i=0; i<9; i++)
\r
54 java.net.URL url = getClass().getResource("/dna" + (i+1) + ".gif");
\r
56 imageIcon[i] = new ImageIcon(url);
\r
62 while(jobsRunning>0)
\r
68 outputFrame.setFrameIcon( imageIcon[imageIndex]);
\r
69 outputFrame.setTitle("BLASTing for unidentified sequences - "+jobsRunning+" jobs running.");
\r
71 }catch(Exception ex){}
\r
80 class BlastThread extends Thread
\r
85 boolean jobComplete = false;
\r
87 BlastThread(String id, String sequence)
\r
89 this.sequence = sequence;
\r
97 while (!jobComplete)
\r
101 Call call = (Call)new Service().createCall();
\r
102 call.setTargetEndpointAddress(new java.net.URL(
\r
103 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
104 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
105 String result = (String) call.invoke(new Object[]
\r
107 if(result.indexOf("JOB PENDING")==-1 && result.indexOf("JOB RUNNING")==-1)
\r
109 parseResult(seqid, result);
\r
110 jobComplete = true;
\r
113 Thread.sleep(5000);
\r
114 System.out.println("I'm alive "+seqid+" "+jobid);
\r
116 catch (Exception ex)
\r
123 HashMap params = new HashMap();
\r
124 params.put("database", "uniprot");
\r
125 params.put("sensitivity", "low");
\r
126 params.put("sort", "totalscore");
\r
127 params.put("matrix", "pam10");
\r
128 params.put("program", "blastp");
\r
129 params.put("alignments", "5");
\r
130 params.put("outformat", "xml");
\r
131 params.put("searchtype", "1");
\r
132 byte[] seqbytes = sequence.getBytes();
\r
136 Call call = (Call)new Service().createCall();
\r
137 call.setTargetEndpointAddress(new java.net.URL(
\r
138 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
139 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
140 String result = (String) call.invoke(new Object[]
\r
141 {params, seqbytes});
\r
143 System.out.println(jobid);
\r
146 catch (Exception exp)
\r
148 System.err.println("ERROR:\n" + exp.toString());
\r
149 exp.printStackTrace();
\r
154 void parseResult(String id1, String res)
\r
156 StringTokenizer st = new StringTokenizer(res, "\n");
\r
160 StringBuffer buffer = new StringBuffer("\n\n"+id1+" :");
\r
162 while( st.hasMoreTokens() )
\r
164 data = st.nextToken();
\r
166 if(data.indexOf("database=\"uniprot\" id=")>-1)
\r
168 int index = data.indexOf("database=\"uniprot\" id=")+ 23;
\r
169 id2 = data.substring( index, data.indexOf("\"", index) );
\r
170 while( data.indexOf("</alignment>")==-1)
\r
172 data = st.nextToken();
\r
173 if(data.indexOf("<identity>")>-1)
\r
175 int value = Integer.parseInt( data.substring(data.indexOf("<identity>")+10, data.indexOf("</identity>")));
\r
176 if(value>=maxFound)
\r
179 buffer.append(" "+ id2 + " " + value+"%; ");
\r
189 output.setText(output.getText()+buffer.toString());
\r