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.DBRefSource;
27 import jalview.datamodel.Sequence;
28 import jalview.gui.AlignmentPanel;
29 import jalview.gui.CutAndPasteTransfer;
30 import jalview.gui.Desktop;
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;
39 import javax.swing.JOptionPane;
41 import uk.ac.ebi.www.Data;
42 import uk.ac.ebi.www.InputParams;
43 import uk.ac.ebi.www.WSFile;
44 import uk.ac.ebi.www.WSWUBlast;
45 import uk.ac.ebi.www.WSWUBlastService;
46 import uk.ac.ebi.www.WSWUBlastServiceLocator;
54 public class WSWUBlastClient
60 CutAndPasteTransfer output = new CutAndPasteTransfer();
64 Vector suggestedIds = new Vector();
67 * Creates a new WSWUBlastClient object.
74 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
78 output.setText(MessageManager
79 .getString("label.wswublast_client_credits"));
81 Desktop.addInternalFrame(output, MessageManager
82 .getString("label.blasting_for_unidentified_sequence"), 800,
85 for (int i = 0; i < ids.size(); i++)
87 Sequence sequence = (Sequence) ids.get(i);
88 System.out.println(sequence.getName());
90 BlastThread thread = new BlastThread(sequence);
95 ImageTwirler thread = new ImageTwirler();
107 void parseResult(Sequence seq, String res)
109 StringTokenizer st = new StringTokenizer(res, "\n");
113 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
115 while (st.hasMoreTokens())
117 data = st.nextToken();
119 if (data.indexOf(">UNIPROT") > -1)
121 int index = data.indexOf(">UNIPROT") + 9;
122 id2 = data.substring(index, data.indexOf(" ", index));
124 boolean identitiesFound = false;
125 while (!identitiesFound)
127 data = st.nextToken();
129 if (data.indexOf("Identities") > -1)
131 identitiesFound = true;
133 int value = Integer.parseInt(data.substring(
134 data.indexOf("(") + 1, data.indexOf("%")));
136 if (value >= maxFound)
139 buffer.append(" " + id2 + " " + value + "%; ");
140 suggestedIds.addElement(new Object[]
148 output.appendText(buffer.toString());
153 // This must be outside the run() body as java 1.5
154 // will not return any value from the OptionPane to the expired thread.
155 int reply = JOptionPane.showConfirmDialog(Desktop.desktop,
156 "Automatically update suggested ids?",
157 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
159 if (reply == JOptionPane.YES_OPTION)
161 Enumeration keys = suggestedIds.elements();
162 while (keys.hasMoreElements())
164 Object[] object = (Object[]) keys.nextElement();
166 Sequence oldseq = (Sequence) object[0];
168 oldseq.setName(object[1].toString());
170 // Oldseq is actually in the dataset, we must find the
171 // Visible seq and change its name also.
172 for (int i = 0; i < al.getHeight(); i++)
174 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
176 al.getSequenceAt(i).setName(oldseq.getName());
181 DBRefEntry[] entries = oldseq.getDBRef();
184 oldseq.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "0",
185 entries[0].getAccessionId()));
189 ap.paintAlignment(true);
193 class ImageTwirler extends Thread
195 ImageIcon[] imageIcon;
199 public ImageTwirler()
201 imageIcon = new ImageIcon[9];
203 for (int i = 0; i < 9; i++)
205 java.net.URL url = getClass().getResource(
206 "/images/dna" + (i + 1) + ".gif");
210 imageIcon[i] = new ImageIcon(url);
217 while (jobsRunning > 0)
224 output.setFrameIcon(imageIcon[imageIndex]);
225 output.setTitle(MessageManager.formatMessage("label.blasting_for_unidentified_sequence_jobs_running", new String[]{Integer.valueOf(jobsRunning).toString()}));
226 } catch (Exception ex)
231 if (jobsRunning == 0)
238 class BlastThread extends Thread
244 boolean jobComplete = false;
246 BlastThread(Sequence sequence)
248 System.out.println("blasting for: " + sequence.getName());
249 this.sequence = sequence;
260 WSWUBlastService service = new WSWUBlastServiceLocator();
261 WSWUBlast wublast = service.getWSWUBlast();
262 WSFile[] results = wublast.getResults(jobid);
266 String result = new String(wublast.poll(jobid, "tooloutput"));
267 parseResult(sequence, result);
274 System.out.println("WSWuBlastClient: I'm alive "
275 + sequence.getName() + " " + jobid); // log.debug
277 } catch (Exception ex)
285 InputParams params = new InputParams();
287 params.setProgram("blastp");
288 params.setDatabase("uniprot");
289 params.setMatrix("pam10");
292 params.setSensitivity("low");
293 params.setSort("totalscore");
294 params.setOutformat("txt");
295 params.setAsync(true);
299 Data inputs[] = new Data[1];
300 Data input = new Data();
301 input.setType("sequence");
302 input.setContent(AlignSeq.extractGaps("-. ",
303 sequence.getSequenceAsString()));
306 WSWUBlastService service = new WSWUBlastServiceLocator();
307 WSWUBlast wublast = service.getWSWUBlast();
308 jobid = wublast.runWUBlast(params, inputs);
309 } catch (Exception exp)
313 System.err.println("WSWUBlastClient error:\n" + exp.toString());
314 exp.printStackTrace();