2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.getString("label.wswublast_client_credits"));
65 Desktop.addInternalFrame(output,
66 MessageManager.getString("label.blasting_for_unidentified_sequence"), 800, 300);
68 for (int i = 0; i < ids.size(); i++)
70 Sequence sequence = (Sequence) ids.get(i);
71 System.out.println(sequence.getName());
73 BlastThread thread = new BlastThread(sequence);
78 ImageTwirler thread = new ImageTwirler();
90 void parseResult(Sequence seq, String res)
92 StringTokenizer st = new StringTokenizer(res, "\n");
96 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
98 while (st.hasMoreTokens())
100 data = st.nextToken();
102 if (data.indexOf(">UNIPROT") > -1)
104 int index = data.indexOf(">UNIPROT") + 9;
105 id2 = data.substring(index, data.indexOf(" ", index));
107 boolean identitiesFound = false;
108 while (!identitiesFound)
110 data = st.nextToken();
112 if (data.indexOf("Identities") > -1)
114 identitiesFound = true;
116 int value = Integer.parseInt(data.substring(
117 data.indexOf("(") + 1, data.indexOf("%")));
119 if (value >= maxFound)
122 buffer.append(" " + id2 + " " + value + "%; ");
123 suggestedIds.addElement(new Object[]
131 output.appendText(buffer.toString());
136 // This must be outside the run() body as java 1.5
137 // will not return any value from the OptionPane to the expired thread.
138 int reply = JOptionPane.showConfirmDialog(Desktop.desktop,
139 "Automatically update suggested ids?",
140 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
142 if (reply == JOptionPane.YES_OPTION)
144 Enumeration keys = suggestedIds.elements();
145 while (keys.hasMoreElements())
147 Object[] object = (Object[]) keys.nextElement();
149 Sequence oldseq = (Sequence) object[0];
151 oldseq.setName(object[1].toString());
153 // Oldseq is actually in the dataset, we must find the
154 // Visible seq and change its name also.
155 for (int i = 0; i < al.getHeight(); i++)
157 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
159 al.getSequenceAt(i).setName(oldseq.getName());
164 DBRefEntry[] entries = oldseq.getDBRef();
167 oldseq.addDBRef(new jalview.datamodel.DBRefEntry(
168 jalview.datamodel.DBRefSource.UNIPROT, "0", entries[0]
173 ap.paintAlignment(true);
177 class ImageTwirler extends Thread
179 ImageIcon[] imageIcon;
183 public ImageTwirler()
185 imageIcon = new ImageIcon[9];
187 for (int i = 0; i < 9; i++)
189 java.net.URL url = getClass().getResource(
190 "/images/dna" + (i + 1) + ".gif");
194 imageIcon[i] = new ImageIcon(url);
201 while (jobsRunning > 0)
208 output.setFrameIcon(imageIcon[imageIndex]);
209 output.setTitle("BLASTing for unidentified sequences - "
210 + jobsRunning + " jobs running.");
211 } catch (Exception ex)
216 if (jobsRunning == 0)
223 class BlastThread extends Thread
229 boolean jobComplete = false;
231 BlastThread(Sequence sequence)
233 System.out.println("blasting for: " + sequence.getName());
234 this.sequence = sequence;
245 WSWUBlastService service = new WSWUBlastServiceLocator();
246 WSWUBlast wublast = service.getWSWUBlast();
247 WSFile[] results = wublast.getResults(jobid);
251 String result = new String(wublast.poll(jobid, "tooloutput"));
252 parseResult(sequence, result);
259 System.out.println("WSWuBlastClient: I'm alive "
260 + sequence.getName() + " " + jobid); // log.debug
262 } catch (Exception ex)
270 InputParams params = new InputParams();
272 params.setProgram("blastp");
273 params.setDatabase("uniprot");
274 params.setMatrix("pam10");
277 params.setSensitivity("low");
278 params.setSort("totalscore");
279 params.setOutformat("txt");
280 params.setAsync(true);
284 Data inputs[] = new Data[1];
285 Data input = new Data();
286 input.setType("sequence");
287 input.setContent(AlignSeq.extractGaps("-. ",
288 sequence.getSequenceAsString()));
291 WSWUBlastService service = new WSWUBlastServiceLocator();
292 WSWUBlast wublast = service.getWSWUBlast();
293 jobid = wublast.runWUBlast(params, inputs);
294 } catch (Exception exp)
298 System.err.println("WSWUBlastClient error:\n" + exp.toString());
299 exp.printStackTrace();