2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
22 import org.apache.axis.client.*;
\r
23 import javax.xml.namespace.QName;
\r
25 import jalview.datamodel.*;
\r
26 import jalview.gui.*;
\r
27 import javax.swing.*;
\r
31 public class WSWUBlastClient
\r
33 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
34 int jobsRunning = 0;
\r
36 public WSWUBlastClient(AlignmentI al, ArrayList ids)
\r
38 output.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered."
\r
39 +"\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
40 Desktop.addInternalFrame(output, "BLASTing for unidentified sequences ", 800,300);
\r
42 for(int i=0; i<ids.size(); i++)
\r
44 SequenceI sequence = al.findName( ids.get(i).toString() );
\r
45 StringBuffer nonGapped = new StringBuffer();
\r
46 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
48 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
49 nonGapped.append(sequence.getCharAt(n));
\r
52 BlastThread thread = new BlastThread(ids.get(i).toString(), nonGapped.toString());
\r
56 ImageTwirler thread = new ImageTwirler();
\r
60 class ImageTwirler extends Thread
\r
62 ImageIcon [] imageIcon;
\r
64 public ImageTwirler()
\r
66 imageIcon = new ImageIcon[9];
\r
67 for(int i=0; i<9; i++)
\r
69 java.net.URL url = getClass().getResource("/images/dna" + (i+1) + ".gif");
\r
71 imageIcon[i] = new ImageIcon(url);
\r
77 while(jobsRunning>0)
\r
83 output.setFrameIcon( imageIcon[imageIndex]);
\r
84 output.setTitle("BLASTing for unidentified sequences - "+jobsRunning+" jobs running.");
\r
86 }catch(Exception ex){}
\r
95 class BlastThread extends Thread
\r
100 boolean jobComplete = false;
\r
102 BlastThread(String id, String sequence)
\r
104 this.sequence = sequence;
\r
112 while (!jobComplete)
\r
116 Call call = (Call)new Service().createCall();
\r
117 call.setTargetEndpointAddress(new java.net.URL(
\r
118 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
119 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
120 String result = (String) call.invoke(new Object[]
\r
122 if(result.indexOf("JOB PENDING")==-1 && result.indexOf("JOB RUNNING")==-1)
\r
124 parseResult(seqid, result);
\r
125 jobComplete = true;
\r
128 Thread.sleep(5000);
\r
129 // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
131 catch (Exception ex)
\r
138 HashMap params = new HashMap();
\r
139 params.put("database", "uniprot");
\r
140 params.put("sensitivity", "low");
\r
141 params.put("sort", "totalscore");
\r
142 params.put("matrix", "pam10");
\r
143 params.put("program", "blastp");
\r
144 params.put("alignments", "5");
\r
145 params.put("outformat", "xml");
\r
146 params.put("searchtype", "1");
\r
147 byte[] seqbytes = sequence.getBytes();
\r
151 Call call = (Call)new Service().createCall();
\r
152 call.setTargetEndpointAddress(new java.net.URL(
\r
153 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
154 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
155 String result = (String) call.invoke(new Object[]
\r
156 {params, seqbytes});
\r
158 System.out.println("http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '"+jobid+"'");
\r
161 catch (Exception exp)
\r
163 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
164 exp.printStackTrace();
\r
169 void parseResult(String id1, String res)
\r
171 StringTokenizer st = new StringTokenizer(res, "\n");
\r
175 StringBuffer buffer = new StringBuffer("\n\n"+id1+" :");
\r
177 while( st.hasMoreTokens() )
\r
179 data = st.nextToken();
\r
181 if(data.indexOf("database=\"uniprot\" id=")>-1)
\r
183 int index = data.indexOf("database=\"uniprot\" id=")+ 23;
\r
184 id2 = data.substring( index, data.indexOf("\"", index) );
\r
185 while( data.indexOf("</alignment>")==-1)
\r
187 data = st.nextToken();
\r
188 if(data.indexOf("<identity>")>-1)
\r
190 int value = Integer.parseInt( data.substring(data.indexOf("<identity>")+10, data.indexOf("</identity>")));
\r
191 if(value>=maxFound)
\r
194 buffer.append(" "+ id2 + " " + value+"%; ");
\r
204 output.setText(output.getText()+buffer.toString());
\r