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
36 public class WSWUBlastClient {
\r
37 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
38 int jobsRunning = 0;
\r
40 public WSWUBlastClient(AlignmentI al, ArrayList ids) {
\r
42 "To display sequence features an exact Uniprot id with 100% sequence identity match must be entered." +
\r
43 "\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
44 Desktop.addInternalFrame(output,
\r
45 "BLASTing for unidentified sequences ", 800, 300);
\r
47 for (int i = 0; i < ids.size(); i++) {
\r
48 SequenceI sequence = al.findName(ids.get(i).toString());
\r
49 StringBuffer nonGapped = new StringBuffer();
\r
51 for (int n = 0; n < sequence.getSequence().length(); n++) {
\r
52 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n))) {
\r
53 nonGapped.append(sequence.getCharAt(n));
\r
57 BlastThread thread = new BlastThread(ids.get(i).toString(),
\r
58 nonGapped.toString());
\r
63 ImageTwirler thread = new ImageTwirler();
\r
67 void parseResult(String id1, String res) {
\r
68 StringTokenizer st = new StringTokenizer(res, "\n");
\r
72 StringBuffer buffer = new StringBuffer("\n\n" + id1 + " :");
\r
74 while (st.hasMoreTokens()) {
\r
75 data = st.nextToken();
\r
77 if (data.indexOf("database=\"uniprot\" id=") > -1) {
\r
78 int index = data.indexOf("database=\"uniprot\" id=") + 23;
\r
79 id2 = data.substring(index, data.indexOf("\"", index));
\r
81 while (data.indexOf("</alignment>") == -1) {
\r
82 data = st.nextToken();
\r
84 if (data.indexOf("<identity>") > -1) {
\r
85 int value = Integer.parseInt(data.substring(data.indexOf(
\r
87 data.indexOf("</identity>")));
\r
89 if (value >= maxFound) {
\r
91 buffer.append(" " + id2 + " " + value + "%; ");
\r
98 output.setText(output.getText() + buffer.toString());
\r
101 class ImageTwirler extends Thread {
\r
102 ImageIcon[] imageIcon;
\r
103 int imageIndex = 0;
\r
105 public ImageTwirler() {
\r
106 imageIcon = new ImageIcon[9];
\r
108 for (int i = 0; i < 9; i++) {
\r
109 java.net.URL url = getClass().getResource("/images/dna" +
\r
113 imageIcon[i] = new ImageIcon(url);
\r
118 public void run() {
\r
119 while (jobsRunning > 0) {
\r
124 output.setFrameIcon(imageIcon[imageIndex]);
\r
125 output.setTitle("BLASTing for unidentified sequences - " +
\r
126 jobsRunning + " jobs running.");
\r
127 } catch (Exception ex) {
\r
133 class BlastThread extends Thread {
\r
137 boolean jobComplete = false;
\r
139 BlastThread(String id, String sequence) {
\r
140 this.sequence = sequence;
\r
144 public void run() {
\r
147 while (!jobComplete) {
\r
149 Call call = (Call) new Service().createCall();
\r
150 call.setTargetEndpointAddress(new java.net.URL(
\r
151 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
152 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
154 String result = (String) call.invoke(new Object[] {
\r
158 if ((result.indexOf("JOB PENDING") == -1) &&
\r
159 (result.indexOf("JOB RUNNING") == -1)) {
\r
160 parseResult(seqid, result);
\r
161 jobComplete = true;
\r
165 Thread.sleep(5000);
\r
167 // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
168 } catch (Exception ex) {
\r
174 HashMap params = new HashMap();
\r
175 params.put("database", "uniprot");
\r
176 params.put("sensitivity", "low");
\r
177 params.put("sort", "totalscore");
\r
178 params.put("matrix", "pam10");
\r
179 params.put("program", "blastp");
\r
180 params.put("alignments", "5");
\r
181 params.put("outformat", "xml");
\r
182 params.put("searchtype", "1");
\r
184 byte[] seqbytes = sequence.getBytes();
\r
187 Call call = (Call) new Service().createCall();
\r
188 call.setTargetEndpointAddress(new java.net.URL(
\r
189 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
190 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
192 String result = (String) call.invoke(new Object[] {
\r
196 System.out.println(
\r
197 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '" +
\r
199 } catch (Exception exp) {
\r
200 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
201 exp.printStackTrace();
\r