2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignSeq;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.DBRefEntry;
26 import jalview.datamodel.Sequence;
27 import jalview.gui.AlignmentPanel;
28 import jalview.gui.CutAndPasteTransfer;
29 import jalview.gui.Desktop;
30 import jalview.gui.JvOptionPane;
31 import jalview.util.MessageManager;
33 import java.util.ArrayList;
34 import java.util.Enumeration;
35 import java.util.StringTokenizer;
36 import java.util.Vector;
38 import javax.swing.ImageIcon;
40 import uk.ac.ebi.www.Data;
41 import uk.ac.ebi.www.InputParams;
42 import uk.ac.ebi.www.WSFile;
43 import uk.ac.ebi.www.WSWUBlast;
44 import uk.ac.ebi.www.WSWUBlastService;
45 import uk.ac.ebi.www.WSWUBlastServiceLocator;
53 public class WSWUBlastClient
59 CutAndPasteTransfer output = new CutAndPasteTransfer();
63 Vector suggestedIds = new Vector();
66 * Creates a new WSWUBlastClient object.
73 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
78 MessageManager.getString("label.wswublast_client_credits"));
80 Desktop.addInternalFrame(output, MessageManager.getString(
81 "label.blasting_for_unidentified_sequence"), 800, 300);
83 for (int i = 0; i < ids.size(); i++)
85 Sequence sequence = (Sequence) ids.get(i);
86 System.out.println(sequence.getName());
88 BlastThread thread = new BlastThread(sequence);
93 ImageTwirler thread = new ImageTwirler();
105 void parseResult(Sequence seq, String res)
107 StringTokenizer st = new StringTokenizer(res, "\n");
111 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
113 while (st.hasMoreTokens())
115 data = st.nextToken();
117 if (data.indexOf(">UNIPROT") > -1)
119 int index = data.indexOf(">UNIPROT") + 9;
120 id2 = data.substring(index, data.indexOf(" ", index));
122 boolean identitiesFound = false;
123 while (!identitiesFound)
125 data = st.nextToken();
127 if (data.indexOf("Identities") > -1)
129 identitiesFound = true;
131 int value = Integer.parseInt(data
132 .substring(data.indexOf("(") + 1, data.indexOf("%")));
134 if (value >= maxFound)
137 buffer.append(" " + id2 + " " + value + "%; ");
138 suggestedIds.addElement(new Object[] { seq, id2 });
145 output.appendText(buffer.toString());
150 // This must be outside the run() body as java 1.5
151 // will not return any value from the OptionPane to the expired thread.
152 int reply = JvOptionPane.showConfirmDialog(Desktop.desktop,
153 "Automatically update suggested ids?",
154 "Auto replace sequence ids", JvOptionPane.YES_NO_OPTION);
156 if (reply == JvOptionPane.YES_OPTION)
158 Enumeration keys = suggestedIds.elements();
159 while (keys.hasMoreElements())
161 Object[] object = (Object[]) keys.nextElement();
163 Sequence oldseq = (Sequence) object[0];
165 oldseq.setName(object[1].toString());
167 // Oldseq is actually in the dataset, we must find the
168 // Visible seq and change its name also.
169 for (int i = 0; i < al.getHeight(); i++)
171 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
173 al.getSequenceAt(i).setName(oldseq.getName());
178 DBRefEntry[] entries = oldseq.getDBRefs();
181 oldseq.addDBRef(new jalview.datamodel.DBRefEntry(
182 jalview.datamodel.DBRefSource.UNIPROT, "0",
183 entries[0].getAccessionId()));
187 ap.paintAlignment(true, false);
191 class ImageTwirler extends Thread
193 ImageIcon[] imageIcon;
197 public ImageTwirler()
199 imageIcon = new ImageIcon[9];
201 for (int i = 0; i < 9; i++)
203 java.net.URL url = getClass()
204 .getResource("/images/dna" + (i + 1) + ".gif");
208 imageIcon[i] = new ImageIcon(url);
216 while (jobsRunning > 0)
223 output.setFrameIcon(imageIcon[imageIndex]);
224 output.setTitle(MessageManager.formatMessage(
225 "label.blasting_for_unidentified_sequence_jobs_running",
227 { Integer.valueOf(jobsRunning).toString() }));
228 } catch (Exception ex)
233 if (jobsRunning == 0)
240 class BlastThread extends Thread
246 boolean jobComplete = false;
248 BlastThread(Sequence sequence)
250 System.out.println("blasting for: " + sequence.getName());
251 this.sequence = sequence;
263 WSWUBlastService service = new WSWUBlastServiceLocator();
264 WSWUBlast wublast = service.getWSWUBlast();
265 WSFile[] results = wublast.getResults(jobid);
269 String result = new String(wublast.poll(jobid, "tooloutput"));
270 parseResult(sequence, result);
277 System.out.println("WSWuBlastClient: I'm alive "
278 + sequence.getName() + " " + jobid); // log.debug
280 } catch (Exception ex)
288 InputParams params = new InputParams();
290 params.setProgram("blastp");
291 params.setDatabase("uniprot");
292 params.setMatrix("pam10");
295 params.setSensitivity("low");
296 params.setSort("totalscore");
297 params.setOutformat("txt");
298 params.setAsync(true);
302 Data inputs[] = new Data[1];
303 Data input = new Data();
304 input.setType("sequence");
305 input.setContent(AlignSeq.extractGaps("-. ",
306 sequence.getSequenceAsString()));
309 WSWUBlastService service = new WSWUBlastServiceLocator();
310 WSWUBlast wublast = service.getWSWUBlast();
311 jobid = wublast.runWUBlast(params, inputs);
312 } catch (Exception exp)
316 System.err.println("WSWUBlastClient error:\n" + exp.toString());
317 exp.printStackTrace();