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
29 import javax.swing.*;
\r
31 import javax.xml.namespace.QName;
\r
38 * @version $Revision$
\r
40 public class WSWUBlastClient
\r
44 CutAndPasteTransfer output = new CutAndPasteTransfer();
\r
45 int jobsRunning = 0;
\r
47 Hashtable suggestedIds = new Hashtable();
\r
49 * Creates a new WSWUBlastClient object.
\r
51 * @param al DOCUMENT ME!
\r
52 * @param ids DOCUMENT ME!
\r
54 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
\r
59 "To display sequence features an exact Uniprot id with 100% sequence identity match must be entered." +
\r
60 "\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");
\r
61 Desktop.addInternalFrame(output,
\r
62 "BLASTing for unidentified sequences ", 800, 300);
\r
64 for (int i = 0; i < ids.size(); i++)
\r
66 SequenceI sequence = al.findName(ids.get(i).toString());
\r
67 System.out.println(ids.get(i).toString());
\r
68 StringBuffer nonGapped = new StringBuffer();
\r
71 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
73 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
75 nonGapped.append(sequence.getCharAt(n));
\r
79 BlastThread thread = new BlastThread(ids.get(i).toString(),
\r
80 nonGapped.toString());
\r
85 ImageTwirler thread = new ImageTwirler();
\r
93 * @param id1 DOCUMENT ME!
\r
94 * @param res DOCUMENT ME!
\r
96 void parseResult(String id1, String res)
\r
98 StringTokenizer st = new StringTokenizer(res, "\n");
\r
102 StringBuffer buffer = new StringBuffer("\n\n" + id1 + " :");
\r
104 while (st.hasMoreTokens())
\r
106 data = st.nextToken();
\r
108 if (data.indexOf(">UNIPROT") > -1)
\r
110 int index = data.indexOf(">UNIPROT") + 9;
\r
111 id2 = data.substring(index, data.indexOf(" ", index));
\r
113 boolean identitiesFound = false;
\r
114 while (!identitiesFound)
\r
116 data = st.nextToken();
\r
118 if (data.indexOf("Identities") > -1)
\r
120 identitiesFound = true;
\r
122 int value = Integer.parseInt(data.substring(data.indexOf(
\r
124 data.indexOf("%")));
\r
126 if (value >= maxFound)
\r
129 buffer.append(" " + id2 + " " + value + "%; ");
\r
130 if(!suggestedIds.containsKey(id1))
\r
132 suggestedIds.put(id1, id2);
\r
140 output.appendText(buffer.toString());
\r
145 // This must be outside the run() body as java 1.5
\r
146 // will not return any value from the OptionPane to the expired thread.
\r
147 int reply = JOptionPane.showConfirmDialog(
\r
148 Desktop.desktop, "Automatically update suggested ids?",
\r
149 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
\r
151 if (reply == JOptionPane.YES_OPTION)
\r
153 Enumeration keys = suggestedIds.keys();
\r
154 while(keys.hasMoreElements())
\r
156 String oldid = keys.nextElement().toString();
\r
157 SequenceI sequence = al.findName(oldid);
\r
158 sequence.setName( suggestedIds.get(oldid).toString() );
\r
160 sequence = sequence.getDatasetSequence();
\r
164 sequence.setName(suggestedIds.get(oldid).toString());
\r
166 Vector entries = sequence.getDBRef();
\r
169 DBRefEntry entry = (DBRefEntry) entries.elementAt(0);
\r
170 sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT",
\r
172 entry.getAccessionId()));
\r
175 System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid));
\r
182 class ImageTwirler extends Thread
\r
184 ImageIcon[] imageIcon;
\r
185 int imageIndex = 0;
\r
187 public ImageTwirler()
\r
189 imageIcon = new ImageIcon[9];
\r
191 for (int i = 0; i < 9; i++)
\r
193 java.net.URL url = getClass().getResource("/images/dna" +
\r
198 imageIcon[i] = new ImageIcon(url);
\r
205 while (jobsRunning > 0)
\r
212 output.setFrameIcon(imageIcon[imageIndex]);
\r
213 output.setTitle("BLASTing for unidentified sequences - " +
\r
214 jobsRunning + " jobs running.");
\r
216 catch (Exception ex)
\r
221 if (jobsRunning == 0)
\r
228 class BlastThread extends Thread
\r
233 boolean jobComplete = false;
\r
235 BlastThread(String id, String sequence)
\r
237 System.out.println("blasting for: "+id);
\r
238 this.sequence = sequence;
\r
246 while (!jobComplete)
\r
250 Call call = (Call) new Service().createCall();
\r
251 call.setTargetEndpointAddress(new java.net.URL(
\r
252 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
253 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
255 Object object = (String) call.invoke(new Object[]
\r
260 if(object instanceof String)
\r
262 parseResult(seqid, (String)object);
\r
263 jobComplete = true;
\r
267 Thread.sleep(5000);
\r
269 System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
271 catch (Exception ex)
\r
279 HashMap params = new HashMap();
\r
280 params.put("database", "uniprot");
\r
281 params.put("sensitivity", "low");
\r
282 params.put("sort", "totalscore");
\r
283 params.put("matrix", "pam10");
\r
284 params.put("program", "blastp");
\r
285 params.put("alignments", "5");
\r
286 params.put("type", "xml");
\r
287 params.put("async", "true");
\r
289 byte[] seqbytes = sequence.getBytes();
\r
293 Call call = (Call) new Service().createCall();
\r
294 call.setTargetEndpointAddress(new java.net.URL(
\r
295 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
296 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
298 Object object = call.invoke(new Object[]
\r
303 if(object instanceof byte[])
\r
304 jobid = new String( (byte[])object);
\r
308 jobComplete = true;
\r
310 parseResult(seqid, (String)object);
\r
314 catch (Exception exp)
\r
316 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
317 exp.printStackTrace();
\r