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
21 import jalview.datamodel.*;
\r
23 import jalview.gui.*;
\r
25 import org.apache.axis.client.*;
\r
31 import javax.swing.*;
\r
33 import javax.xml.namespace.QName;
\r
40 * @version $Revision$
\r
42 public class WSWUBlastClient
\r
44 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
45 int jobsRunning = 0;
\r
48 * Creates a new WSWUBlastClient object.
\r
50 * @param al DOCUMENT ME!
\r
51 * @param ids DOCUMENT ME!
\r
53 public WSWUBlastClient(AlignmentI al, ArrayList ids)
\r
56 "To display sequence features an exact Uniprot id with 100% sequence identity match must be entered." +
\r
57 "\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
58 Desktop.addInternalFrame(output,
\r
59 "BLASTing for unidentified sequences ", 800, 300);
\r
61 for (int i = 0; i < ids.size(); i++)
\r
63 SequenceI sequence = al.findName(ids.get(i).toString());
\r
64 StringBuffer nonGapped = new StringBuffer();
\r
66 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
68 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
70 nonGapped.append(sequence.getCharAt(n));
\r
74 BlastThread thread = new BlastThread(ids.get(i).toString(),
\r
75 nonGapped.toString());
\r
80 ImageTwirler thread = new ImageTwirler();
\r
87 * @param id1 DOCUMENT ME!
\r
88 * @param res DOCUMENT ME!
\r
90 void parseResult(String id1, String res)
\r
92 StringTokenizer st = new StringTokenizer(res, "\n");
\r
96 StringBuffer buffer = new StringBuffer("\n\n" + id1 + " :");
\r
98 while (st.hasMoreTokens())
\r
100 data = st.nextToken();
\r
102 if (data.indexOf("database=\"uniprot\" id=") > -1)
\r
104 int index = data.indexOf("database=\"uniprot\" id=") + 23;
\r
105 id2 = data.substring(index, data.indexOf("\"", index));
\r
107 while (data.indexOf("</alignment>") == -1)
\r
109 data = st.nextToken();
\r
111 if (data.indexOf("<identity>") > -1)
\r
113 int value = Integer.parseInt(data.substring(data.indexOf(
\r
114 "<identity>") + 10,
\r
115 data.indexOf("</identity>")));
\r
117 if (value >= maxFound)
\r
120 buffer.append(" " + id2 + " " + value + "%; ");
\r
127 output.setText(output.getText() + buffer.toString());
\r
130 class ImageTwirler extends Thread
\r
132 ImageIcon[] imageIcon;
\r
133 int imageIndex = 0;
\r
135 public ImageTwirler()
\r
137 imageIcon = new ImageIcon[9];
\r
139 for (int i = 0; i < 9; i++)
\r
141 java.net.URL url = getClass().getResource("/images/dna" +
\r
146 imageIcon[i] = new ImageIcon(url);
\r
153 while (jobsRunning > 0)
\r
160 output.setFrameIcon(imageIcon[imageIndex]);
\r
161 output.setTitle("BLASTing for unidentified sequences - " +
\r
162 jobsRunning + " jobs running.");
\r
164 catch (Exception ex)
\r
171 class BlastThread extends Thread
\r
176 boolean jobComplete = false;
\r
178 BlastThread(String id, String sequence)
\r
180 this.sequence = sequence;
\r
188 while (!jobComplete)
\r
192 Call call = (Call) new Service().createCall();
\r
193 call.setTargetEndpointAddress(new java.net.URL(
\r
194 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
195 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
197 String result = (String) call.invoke(new Object[]
\r
202 if ((result.indexOf("JOB PENDING") == -1) &&
\r
203 (result.indexOf("JOB RUNNING") == -1))
\r
205 parseResult(seqid, result);
\r
206 jobComplete = true;
\r
210 Thread.sleep(5000);
\r
212 // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
214 catch (Exception ex)
\r
222 HashMap params = new HashMap();
\r
223 params.put("database", "uniprot");
\r
224 params.put("sensitivity", "low");
\r
225 params.put("sort", "totalscore");
\r
226 params.put("matrix", "pam10");
\r
227 params.put("program", "blastp");
\r
228 params.put("alignments", "5");
\r
229 params.put("outformat", "xml");
\r
230 params.put("searchtype", "1");
\r
232 byte[] seqbytes = sequence.getBytes();
\r
236 Call call = (Call) new Service().createCall();
\r
237 call.setTargetEndpointAddress(new java.net.URL(
\r
238 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
239 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
241 String result = (String) call.invoke(new Object[]
\r
246 System.out.println(
\r
247 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '" +
\r
250 catch (Exception exp)
\r
252 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
253 exp.printStackTrace();
\r