2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 import jalview.analysis.*;
26 import jalview.datamodel.*;
28 import uk.ac.ebi.www.*;
36 public class WSWUBlastClient
42 CutAndPasteTransfer output = new CutAndPasteTransfer();
46 Vector suggestedIds = new Vector();
49 * Creates a new WSWUBlastClient object.
56 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
61 .setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered."
62 + "\nIn order to display these features, try changing the names of your sequences to the ids suggested below."
63 + "\n\nRunning WSWUBlast at EBI."
64 + "\nPlease quote Pillai S., Silventoinen V., Kallio K., Senger M., Sobhany S., Tate J., Velankar S., Golovin A., Henrick K., Rice P., Stoehr P., Lopez R."
65 + "\nSOAP-based services provided by the European Bioinformatics Institute."
66 + "\nNucleic Acids Res. 33(1):W25-W28 (2005));");
68 Desktop.addInternalFrame(output,
69 "BLASTing for unidentified sequences ", 800, 300);
71 for (int i = 0; i < ids.size(); i++)
73 Sequence sequence = (Sequence) ids.get(i);
74 System.out.println(sequence.getName());
76 BlastThread thread = new BlastThread(sequence);
81 ImageTwirler thread = new ImageTwirler();
93 void parseResult(Sequence seq, String res)
95 StringTokenizer st = new StringTokenizer(res, "\n");
99 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
101 while (st.hasMoreTokens())
103 data = st.nextToken();
105 if (data.indexOf(">UNIPROT") > -1)
107 int index = data.indexOf(">UNIPROT") + 9;
108 id2 = data.substring(index, data.indexOf(" ", index));
110 boolean identitiesFound = false;
111 while (!identitiesFound)
113 data = st.nextToken();
115 if (data.indexOf("Identities") > -1)
117 identitiesFound = true;
119 int value = Integer.parseInt(data.substring(
120 data.indexOf("(") + 1, data.indexOf("%")));
122 if (value >= maxFound)
125 buffer.append(" " + id2 + " " + value + "%; ");
126 suggestedIds.addElement(new Object[]
134 output.appendText(buffer.toString());
139 // This must be outside the run() body as java 1.5
140 // will not return any value from the OptionPane to the expired thread.
141 int reply = JOptionPane.showConfirmDialog(Desktop.desktop,
142 "Automatically update suggested ids?",
143 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
145 if (reply == JOptionPane.YES_OPTION)
147 Enumeration keys = suggestedIds.elements();
148 while (keys.hasMoreElements())
150 Object[] object = (Object[]) keys.nextElement();
152 Sequence oldseq = (Sequence) object[0];
154 oldseq.setName(object[1].toString());
156 // Oldseq is actually in the dataset, we must find the
157 // Visible seq and change its name also.
158 for (int i = 0; i < al.getHeight(); i++)
160 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
162 al.getSequenceAt(i).setName(oldseq.getName());
167 DBRefEntry[] entries = oldseq.getDBRef();
170 oldseq.addDBRef(new jalview.datamodel.DBRefEntry(
171 jalview.datamodel.DBRefSource.UNIPROT, "0", entries[0]
176 ap.paintAlignment(true);
180 class ImageTwirler extends Thread
182 ImageIcon[] imageIcon;
186 public ImageTwirler()
188 imageIcon = new ImageIcon[9];
190 for (int i = 0; i < 9; i++)
192 java.net.URL url = getClass().getResource(
193 "/images/dna" + (i + 1) + ".gif");
197 imageIcon[i] = new ImageIcon(url);
204 while (jobsRunning > 0)
211 output.setFrameIcon(imageIcon[imageIndex]);
212 output.setTitle("BLASTing for unidentified sequences - "
213 + jobsRunning + " jobs running.");
214 } catch (Exception ex)
219 if (jobsRunning == 0)
226 class BlastThread extends Thread
232 boolean jobComplete = false;
234 BlastThread(Sequence sequence)
236 System.out.println("blasting for: " + sequence.getName());
237 this.sequence = sequence;
248 WSWUBlastService service = new WSWUBlastServiceLocator();
249 WSWUBlast wublast = service.getWSWUBlast();
250 WSFile[] results = wublast.getResults(jobid);
254 String result = new String(wublast.poll(jobid, "tooloutput"));
255 parseResult(sequence, result);
262 System.out.println("WSWuBlastClient: I'm alive "
263 + sequence.getName() + " " + jobid); // log.debug
265 } catch (Exception ex)
273 InputParams params = new InputParams();
275 params.setProgram("blastp");
276 params.setDatabase("uniprot");
277 params.setMatrix("pam10");
280 params.setSensitivity("low");
281 params.setSort("totalscore");
282 params.setOutformat("txt");
283 params.setAsync(true);
287 Data inputs[] = new Data[1];
288 Data input = new Data();
289 input.setType("sequence");
290 input.setContent(AlignSeq.extractGaps("-. ", sequence
291 .getSequenceAsString()));
294 WSWUBlastService service = new WSWUBlastServiceLocator();
295 WSWUBlast wublast = service.getWSWUBlast();
296 jobid = wublast.runWUBlast(params, inputs);
297 } catch (Exception exp)
301 System.err.println("WSWUBlastClient error:\n" + exp.toString());
302 exp.printStackTrace();