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.
27 import jalview.analysis.*;
28 import jalview.datamodel.*;
30 import jalview.util.MessageManager;
31 import uk.ac.ebi.www.*;
39 public class WSWUBlastClient
45 CutAndPasteTransfer output = new CutAndPasteTransfer();
49 Vector suggestedIds = new Vector();
52 * Creates a new WSWUBlastClient object.
59 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
63 output.setText(MessageManager
64 .getString("label.wswublast_client_credits"));
66 Desktop.addInternalFrame(output, MessageManager
67 .getString("label.blasting_for_unidentified_sequence"), 800,
70 for (int i = 0; i < ids.size(); i++)
72 Sequence sequence = (Sequence) ids.get(i);
73 System.out.println(sequence.getName());
75 BlastThread thread = new BlastThread(sequence);
80 ImageTwirler thread = new ImageTwirler();
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(
119 data.indexOf("(") + 1, data.indexOf("%")));
121 if (value >= maxFound)
124 buffer.append(" " + id2 + " " + value + "%; ");
125 suggestedIds.addElement(new Object[]
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(Desktop.desktop,
141 "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.DBRefEntry(
170 jalview.datamodel.DBRefSource.UNIPROT, "0", entries[0]
175 ap.paintAlignment(true);
179 class ImageTwirler extends Thread
181 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(
192 "/images/dna" + (i + 1) + ".gif");
196 imageIcon[i] = new ImageIcon(url);
203 while (jobsRunning > 0)
210 output.setFrameIcon(imageIcon[imageIndex]);
211 output.setTitle(MessageManager.formatMessage("label.blasting_for_unidentified_sequence_jobs_running", new String[]{Integer.valueOf(jobsRunning).toString()}));
212 } catch (Exception ex)
217 if (jobsRunning == 0)
224 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
263 } catch (Exception ex)
271 InputParams params = new InputParams();
273 params.setProgram("blastp");
274 params.setDatabase("uniprot");
275 params.setMatrix("pam10");
278 params.setSensitivity("low");
279 params.setSort("totalscore");
280 params.setOutformat("txt");
281 params.setAsync(true);
285 Data inputs[] = new Data[1];
286 Data input = new Data();
287 input.setType("sequence");
288 input.setContent(AlignSeq.extractGaps("-. ",
289 sequence.getSequenceAsString()));
292 WSWUBlastService service = new WSWUBlastServiceLocator();
293 WSWUBlast wublast = service.getWSWUBlast();
294 jobid = wublast.runWUBlast(params, inputs);
295 } catch (Exception exp)
299 System.err.println("WSWUBlastClient error:\n" + exp.toString());
300 exp.printStackTrace();