2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
25 import org.apache.axis.client.*;
31 import javax.xml.namespace.QName;
32 import jalview.analysis.AlignSeq;
34 import uk.ac.ebi.www.*;
42 public class WSWUBlastClient
46 CutAndPasteTransfer output = new CutAndPasteTransfer();
49 Vector suggestedIds = new Vector();
51 * Creates a new WSWUBlastClient object.
53 * @param al DOCUMENT ME!
54 * @param ids DOCUMENT ME!
56 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
61 "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();
89 * @param id1 DOCUMENT ME!
90 * @param res DOCUMENT ME!
92 void parseResult(Sequence seq, String res)
94 StringTokenizer st = new StringTokenizer(res, "\n");
98 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
100 while (st.hasMoreTokens())
102 data = st.nextToken();
104 if (data.indexOf(">UNIPROT") > -1)
106 int index = data.indexOf(">UNIPROT") + 9;
107 id2 = data.substring(index, data.indexOf(" ", index));
109 boolean identitiesFound = false;
110 while (!identitiesFound)
112 data = st.nextToken();
114 if (data.indexOf("Identities") > -1)
116 identitiesFound = true;
118 int value = Integer.parseInt(data.substring(data.indexOf(
122 if (value >= maxFound)
125 buffer.append(" " + id2 + " " + value + "%; ");
126 suggestedIds.addElement( new Object[]{seq, id2});
133 output.appendText(buffer.toString());
138 // This must be outside the run() body as java 1.5
139 // will not return any value from the OptionPane to the expired thread.
140 int reply = JOptionPane.showConfirmDialog(
141 Desktop.desktop, "Automatically update suggested ids?",
142 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
144 if (reply == JOptionPane.YES_OPTION)
146 Enumeration keys = suggestedIds.elements();
147 while(keys.hasMoreElements())
149 Object [] object = (Object[])keys.nextElement();
151 Sequence oldseq = (Sequence)object[0];
153 oldseq.setName( object[1].toString() );
155 // Oldseq is actually in the dataset, we must find the
156 // Visible seq and change its name also.
157 for (int i = 0; i < al.getHeight(); i++)
159 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
161 al.getSequenceAt(i).setName(oldseq.getName());
166 DBRefEntry [] entries = oldseq.getDBRef();
169 oldseq.addDBRef(new jalview.datamodel.
170 DBRefEntry(jalview.datamodel.DBRefSource.UNIPROT,
172 entries[0].getAccessionId()));
180 class ImageTwirler extends Thread
182 ImageIcon[] imageIcon;
185 public ImageTwirler()
187 imageIcon = new ImageIcon[9];
189 for (int i = 0; i < 9; i++)
191 java.net.URL url = getClass().getResource("/images/dna" +
196 imageIcon[i] = new ImageIcon(url);
203 while (jobsRunning > 0)
210 output.setFrameIcon(imageIcon[imageIndex]);
211 output.setTitle("BLASTing for unidentified sequences - " +
212 jobsRunning + " jobs running.");
219 if (jobsRunning == 0)
226 class BlastThread extends Thread
230 boolean jobComplete = false;
232 BlastThread(Sequence sequence)
234 System.out.println("blasting for: "+sequence.getName());
235 this.sequence = sequence;
246 WSWUBlastService service = new WSWUBlastServiceLocator();
247 WSWUBlast wublast = service.getWSWUBlast();
248 WSFile[] results = wublast.getResults(jobid);
252 String result = new String(wublast.poll(jobid, "tooloutput"));
253 parseResult(sequence, result);
260 System.out.println("WSWuBlastClient: I'm alive " +
261 sequence.getName() + " " + jobid); // log.debug
272 InputParams params = new InputParams();
274 params.setProgram("blastp");
275 params.setDatabase("uniprot");
276 params.setMatrix("pam10");
279 params.setSensitivity("low");
280 params.setSort("totalscore");
281 params.setOutformat("txt");
282 params.setAsync(true);
286 Data inputs[] = new Data[1];
287 Data input= new Data();
288 input.setType("sequence");
289 input.setContent(AlignSeq.extractGaps("-. ",sequence.getSequence()));
292 WSWUBlastService service = new WSWUBlastServiceLocator();
293 WSWUBlast wublast = service.getWSWUBlast();
294 jobid = wublast.runWUBlast(params, inputs);
296 catch (Exception exp)
300 System.err.println("WSWUBlastClient error:\n" + exp.toString());
301 exp.printStackTrace();