2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
24 import jalview.analysis.*;
25 import jalview.datamodel.*;
27 import jalview.util.MessageManager;
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)
60 output.setText(MessageManager.getString("label.wswublast_client_credits"));
62 Desktop.addInternalFrame(output,
63 MessageManager.getString("label.blasting_for_unidentified_sequence"), 800, 300);
65 for (int i = 0; i < ids.size(); i++)
67 Sequence sequence = (Sequence) ids.get(i);
68 System.out.println(sequence.getName());
70 BlastThread thread = new BlastThread(sequence);
75 ImageTwirler thread = new ImageTwirler();
87 void parseResult(Sequence seq, String res)
89 StringTokenizer st = new StringTokenizer(res, "\n");
93 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
95 while (st.hasMoreTokens())
97 data = st.nextToken();
99 if (data.indexOf(">UNIPROT") > -1)
101 int index = data.indexOf(">UNIPROT") + 9;
102 id2 = data.substring(index, data.indexOf(" ", index));
104 boolean identitiesFound = false;
105 while (!identitiesFound)
107 data = st.nextToken();
109 if (data.indexOf("Identities") > -1)
111 identitiesFound = true;
113 int value = Integer.parseInt(data.substring(
114 data.indexOf("(") + 1, data.indexOf("%")));
116 if (value >= maxFound)
119 buffer.append(" " + id2 + " " + value + "%; ");
120 suggestedIds.addElement(new Object[]
128 output.appendText(buffer.toString());
133 // This must be outside the run() body as java 1.5
134 // will not return any value from the OptionPane to the expired thread.
135 int reply = JOptionPane.showConfirmDialog(Desktop.desktop,
136 "Automatically update suggested ids?",
137 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
139 if (reply == JOptionPane.YES_OPTION)
141 Enumeration keys = suggestedIds.elements();
142 while (keys.hasMoreElements())
144 Object[] object = (Object[]) keys.nextElement();
146 Sequence oldseq = (Sequence) object[0];
148 oldseq.setName(object[1].toString());
150 // Oldseq is actually in the dataset, we must find the
151 // Visible seq and change its name also.
152 for (int i = 0; i < al.getHeight(); i++)
154 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
156 al.getSequenceAt(i).setName(oldseq.getName());
161 DBRefEntry[] entries = oldseq.getDBRef();
164 oldseq.addDBRef(new jalview.datamodel.DBRefEntry(
165 jalview.datamodel.DBRefSource.UNIPROT, "0", entries[0]
170 ap.paintAlignment(true);
174 class ImageTwirler extends Thread
176 ImageIcon[] imageIcon;
180 public ImageTwirler()
182 imageIcon = new ImageIcon[9];
184 for (int i = 0; i < 9; i++)
186 java.net.URL url = getClass().getResource(
187 "/images/dna" + (i + 1) + ".gif");
191 imageIcon[i] = new ImageIcon(url);
198 while (jobsRunning > 0)
205 output.setFrameIcon(imageIcon[imageIndex]);
206 output.setTitle("BLASTing for unidentified sequences - "
207 + jobsRunning + " jobs running.");
208 } catch (Exception ex)
213 if (jobsRunning == 0)
220 class BlastThread extends Thread
226 boolean jobComplete = false;
228 BlastThread(Sequence sequence)
230 System.out.println("blasting for: " + sequence.getName());
231 this.sequence = sequence;
242 WSWUBlastService service = new WSWUBlastServiceLocator();
243 WSWUBlast wublast = service.getWSWUBlast();
244 WSFile[] results = wublast.getResults(jobid);
248 String result = new String(wublast.poll(jobid, "tooloutput"));
249 parseResult(sequence, result);
256 System.out.println("WSWuBlastClient: I'm alive "
257 + sequence.getName() + " " + jobid); // log.debug
259 } catch (Exception ex)
267 InputParams params = new InputParams();
269 params.setProgram("blastp");
270 params.setDatabase("uniprot");
271 params.setMatrix("pam10");
274 params.setSensitivity("low");
275 params.setSort("totalscore");
276 params.setOutformat("txt");
277 params.setAsync(true);
281 Data inputs[] = new Data[1];
282 Data input = new Data();
283 input.setType("sequence");
284 input.setContent(AlignSeq.extractGaps("-. ",
285 sequence.getSequenceAsString()));
288 WSWUBlastService service = new WSWUBlastServiceLocator();
289 WSWUBlast wublast = service.getWSWUBlast();
290 jobid = wublast.runWUBlast(params, inputs);
291 } catch (Exception exp)
295 System.err.println("WSWUBlastClient error:\n" + exp.toString());
296 exp.printStackTrace();