2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
25 import jalview.analysis.*;
26 import jalview.datamodel.*;
28 import jalview.util.MessageManager;
29 import uk.ac.ebi.www.*;
37 public class WSWUBlastClient
43 CutAndPasteTransfer output = new CutAndPasteTransfer();
47 Vector suggestedIds = new Vector();
50 * Creates a new WSWUBlastClient object.
57 public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)
61 output.setText(MessageManager.getString("label.wswublast_client_credits"));
63 Desktop.addInternalFrame(output,
64 MessageManager.getString("label.blasting_for_unidentified_sequence"), 800, 300);
66 for (int i = 0; i < ids.size(); i++)
68 Sequence sequence = (Sequence) ids.get(i);
69 System.out.println(sequence.getName());
71 BlastThread thread = new BlastThread(sequence);
76 ImageTwirler thread = new ImageTwirler();
88 void parseResult(Sequence seq, String res)
90 StringTokenizer st = new StringTokenizer(res, "\n");
94 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
96 while (st.hasMoreTokens())
98 data = st.nextToken();
100 if (data.indexOf(">UNIPROT") > -1)
102 int index = data.indexOf(">UNIPROT") + 9;
103 id2 = data.substring(index, data.indexOf(" ", index));
105 boolean identitiesFound = false;
106 while (!identitiesFound)
108 data = st.nextToken();
110 if (data.indexOf("Identities") > -1)
112 identitiesFound = true;
114 int value = Integer.parseInt(data.substring(
115 data.indexOf("(") + 1, data.indexOf("%")));
117 if (value >= maxFound)
120 buffer.append(" " + id2 + " " + value + "%; ");
121 suggestedIds.addElement(new Object[]
129 output.appendText(buffer.toString());
134 // This must be outside the run() body as java 1.5
135 // will not return any value from the OptionPane to the expired thread.
136 int reply = JOptionPane.showConfirmDialog(Desktop.desktop,
137 "Automatically update suggested ids?",
138 "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);
140 if (reply == JOptionPane.YES_OPTION)
142 Enumeration keys = suggestedIds.elements();
143 while (keys.hasMoreElements())
145 Object[] object = (Object[]) keys.nextElement();
147 Sequence oldseq = (Sequence) object[0];
149 oldseq.setName(object[1].toString());
151 // Oldseq is actually in the dataset, we must find the
152 // Visible seq and change its name also.
153 for (int i = 0; i < al.getHeight(); i++)
155 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
157 al.getSequenceAt(i).setName(oldseq.getName());
162 DBRefEntry[] entries = oldseq.getDBRef();
165 oldseq.addDBRef(new jalview.datamodel.DBRefEntry(
166 jalview.datamodel.DBRefSource.UNIPROT, "0", entries[0]
171 ap.paintAlignment(true);
175 class ImageTwirler extends Thread
177 ImageIcon[] imageIcon;
181 public ImageTwirler()
183 imageIcon = new ImageIcon[9];
185 for (int i = 0; i < 9; i++)
187 java.net.URL url = getClass().getResource(
188 "/images/dna" + (i + 1) + ".gif");
192 imageIcon[i] = new ImageIcon(url);
199 while (jobsRunning > 0)
206 output.setFrameIcon(imageIcon[imageIndex]);
207 output.setTitle("BLASTing for unidentified sequences - "
208 + jobsRunning + " jobs running.");
209 } catch (Exception ex)
214 if (jobsRunning == 0)
221 class BlastThread extends Thread
227 boolean jobComplete = false;
229 BlastThread(Sequence sequence)
231 System.out.println("blasting for: " + sequence.getName());
232 this.sequence = sequence;
243 WSWUBlastService service = new WSWUBlastServiceLocator();
244 WSWUBlast wublast = service.getWSWUBlast();
245 WSFile[] results = wublast.getResults(jobid);
249 String result = new String(wublast.poll(jobid, "tooloutput"));
250 parseResult(sequence, result);
257 System.out.println("WSWuBlastClient: I'm alive "
258 + sequence.getName() + " " + jobid); // log.debug
260 } catch (Exception ex)
268 InputParams params = new InputParams();
270 params.setProgram("blastp");
271 params.setDatabase("uniprot");
272 params.setMatrix("pam10");
275 params.setSensitivity("low");
276 params.setSort("totalscore");
277 params.setOutformat("txt");
278 params.setAsync(true);
282 Data inputs[] = new Data[1];
283 Data input = new Data();
284 input.setType("sequence");
285 input.setContent(AlignSeq.extractGaps("-. ",
286 sequence.getSequenceAsString()));
289 WSWUBlastService service = new WSWUBlastServiceLocator();
290 WSWUBlast wublast = service.getWSWUBlast();
291 jobid = wublast.runWUBlast(params, inputs);
292 } catch (Exception exp)
296 System.err.println("WSWUBlastClient error:\n" + exp.toString());
297 exp.printStackTrace();