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 StringBuffer nonGapped = new StringBuffer();
\r
70 for (int n = 0; n < sequence.getSequence().length(); n++)
\r
72 if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))
\r
74 nonGapped.append(sequence.getCharAt(n));
\r
78 BlastThread thread = new BlastThread(ids.get(i).toString(),
\r
79 nonGapped.toString());
\r
84 ImageTwirler thread = new ImageTwirler();
\r
92 * @param id1 DOCUMENT ME!
\r
93 * @param res DOCUMENT ME!
\r
95 void parseResult(String id1, String res)
\r
97 StringTokenizer st = new StringTokenizer(res, "\n");
\r
101 StringBuffer buffer = new StringBuffer("\n\n" + id1 + " :");
\r
103 while (st.hasMoreTokens())
\r
105 data = st.nextToken();
\r
107 if (data.indexOf(">UNIPROT") > -1)
\r
109 int index = data.indexOf(">UNIPROT") + 9;
\r
110 id2 = data.substring(index, data.indexOf(" ", index));
\r
112 boolean identitiesFound = false;
\r
113 while (!identitiesFound)
\r
115 data = st.nextToken();
\r
117 if (data.indexOf("Identities") > -1)
\r
119 identitiesFound = true;
\r
121 int value = Integer.parseInt(data.substring(data.indexOf(
\r
123 data.indexOf("%")));
\r
125 if (value >= maxFound)
\r
128 buffer.append(" " + id2 + " " + value + "%; ");
\r
129 suggestedIds.put(id1, id2);
\r
136 output.appendText(buffer.toString());
\r
141 int reply = JOptionPane.showConfirmDialog(
\r
142 Desktop.desktop, "Automatically update suggested ids?",
\r
143 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
\r
145 if (reply == JOptionPane.YES_OPTION)
\r
147 Enumeration keys = suggestedIds.keys();
\r
148 while(keys.hasMoreElements())
\r
150 String oldid = keys.nextElement().toString();
\r
151 SequenceI sequence = al.findName(oldid);
\r
152 sequence.setName( suggestedIds.get(oldid).toString() );
\r
154 sequence = sequence.getDatasetSequence();
\r
158 sequence.setName(suggestedIds.get(oldid).toString());
\r
160 Vector entries = sequence.getDBRef();
\r
163 DBRefEntry entry = (DBRefEntry) entries.elementAt(0);
\r
164 sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT",
\r
166 entry.getAccessionId()));
\r
169 System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid));
\r
176 class ImageTwirler extends Thread
\r
178 ImageIcon[] imageIcon;
\r
179 int imageIndex = 0;
\r
181 public ImageTwirler()
\r
183 imageIcon = new ImageIcon[9];
\r
185 for (int i = 0; i < 9; i++)
\r
187 java.net.URL url = getClass().getResource("/images/dna" +
\r
192 imageIcon[i] = new ImageIcon(url);
\r
199 while (jobsRunning > 0)
\r
206 output.setFrameIcon(imageIcon[imageIndex]);
\r
207 output.setTitle("BLASTing for unidentified sequences - " +
\r
208 jobsRunning + " jobs running.");
\r
210 catch (Exception ex)
\r
215 if (jobsRunning == 0)
\r
222 class BlastThread extends Thread
\r
227 boolean jobComplete = false;
\r
229 BlastThread(String id, String sequence)
\r
231 System.out.println("blasting for: "+id);
\r
232 this.sequence = sequence;
\r
240 while (!jobComplete)
\r
244 Call call = (Call) new Service().createCall();
\r
245 call.setTargetEndpointAddress(new java.net.URL(
\r
246 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
247 call.setOperationName(new QName("WSWUBlast", "polljob"));
\r
249 Object object = (String) call.invoke(new Object[]
\r
254 if(object instanceof String)
\r
256 parseResult(seqid, (String)object);
\r
257 jobComplete = true;
\r
261 Thread.sleep(5000);
\r
263 System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug
\r
265 catch (Exception ex)
\r
273 HashMap params = new HashMap();
\r
274 params.put("database", "uniprot");
\r
275 params.put("sensitivity", "low");
\r
276 params.put("sort", "totalscore");
\r
277 params.put("matrix", "pam10");
\r
278 params.put("program", "blastp");
\r
279 params.put("alignments", "5");
\r
280 params.put("type", "xml");
\r
281 params.put("async", "true");
\r
283 byte[] seqbytes = sequence.getBytes();
\r
287 Call call = (Call) new Service().createCall();
\r
288 call.setTargetEndpointAddress(new java.net.URL(
\r
289 "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));
\r
290 call.setOperationName(new QName("WSWUBlast", "doWUBlast"));
\r
292 Object object = call.invoke(new Object[]
\r
297 if(object instanceof byte[])
\r
298 jobid = new String( (byte[])object);
\r
302 jobComplete = true;
\r
304 parseResult(seqid, (String)object);
\r
308 catch (Exception exp)
\r
310 System.err.println("WSWUBlastClient error:\n" + exp.toString());
\r
311 exp.printStackTrace();
\r