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.List;
36 import java.util.StringTokenizer;
37 import java.util.Vector;
39 import javax.swing.ImageIcon;
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)
79 MessageManager.getString("label.wswublast_client_credits"));
81 Desktop.addInternalFrame(output, MessageManager.getString(
82 "label.blasting_for_unidentified_sequence"), 800, 300);
84 for (int i = 0; i < ids.size(); i++)
86 Sequence sequence = (Sequence) ids.get(i);
87 System.out.println(sequence.getName());
89 BlastThread thread = new BlastThread(sequence);
94 ImageTwirler thread = new ImageTwirler();
106 void parseResult(Sequence seq, String res)
108 StringTokenizer st = new StringTokenizer(res, "\n");
112 StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :");
114 while (st.hasMoreTokens())
116 data = st.nextToken();
118 if (data.indexOf(">UNIPROT") > -1)
120 int index = data.indexOf(">UNIPROT") + 9;
121 id2 = data.substring(index, data.indexOf(" ", index));
123 boolean identitiesFound = false;
124 while (!identitiesFound)
126 data = st.nextToken();
128 if (data.indexOf("Identities") > -1)
130 identitiesFound = true;
132 int value = Integer.parseInt(data
133 .substring(data.indexOf("(") + 1, data.indexOf("%")));
135 if (value >= maxFound)
138 buffer.append(" " + id2 + " " + value + "%; ");
139 suggestedIds.addElement(new Object[] { seq, id2 });
146 output.appendText(buffer.toString());
151 // This must be outside the run() body as java 1.5
152 // will not return any value from the OptionPane to the expired thread.
153 int reply = JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(),
154 "Automatically update suggested ids?",
155 "Auto replace sequence ids", JvOptionPane.YES_NO_OPTION);
157 if (reply == JvOptionPane.YES_OPTION)
159 Enumeration keys = suggestedIds.elements();
160 while (keys.hasMoreElements())
162 Object[] object = (Object[]) keys.nextElement();
164 Sequence oldseq = (Sequence) object[0];
166 oldseq.setName(object[1].toString());
168 // Oldseq is actually in the dataset, we must find the
169 // Visible seq and change its name also.
170 for (int i = 0; i < al.getHeight(); i++)
172 if (al.getSequenceAt(i).getDatasetSequence() == oldseq)
174 al.getSequenceAt(i).setName(oldseq.getName());
179 List<DBRefEntry> entries = oldseq.getDBRefs();
180 // BH 2019.01.25 check for 0-length was missing here
181 if (entries != null && entries.size() > 0)
183 oldseq.addDBRef(new jalview.datamodel.DBRefEntry(
184 jalview.datamodel.DBRefSource.UNIPROT, "0",
185 entries.get(0).getAccessionId()));
189 ap.paintAlignment(true, false);
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()
206 .getResource("/images/dna" + (i + 1) + ".gif");
210 imageIcon[i] = new ImageIcon(url);
218 while (jobsRunning > 0)
225 output.setFrameIcon(imageIcon[imageIndex]);
226 output.setTitle(MessageManager.formatMessage(
227 "label.blasting_for_unidentified_sequence_jobs_running",
229 { Integer.valueOf(jobsRunning).toString() }));
230 } catch (Exception ex)
235 if (jobsRunning == 0)
242 class BlastThread extends Thread
248 boolean jobComplete = false;
250 BlastThread(Sequence sequence)
252 System.out.println("blasting for: " + sequence.getName());
253 this.sequence = sequence;
265 WSWUBlastService service = new WSWUBlastServiceLocator();
266 WSWUBlast wublast = service.getWSWUBlast();
267 WSFile[] results = wublast.getResults(jobid);
271 String result = new String(wublast.poll(jobid, "tooloutput"));
272 parseResult(sequence, result);
279 System.out.println("WSWuBlastClient: I'm alive "
280 + sequence.getName() + " " + jobid); // log.debug
282 } catch (Exception ex)
290 InputParams params = new InputParams();
292 params.setProgram("blastp");
293 params.setDatabase("uniprot");
294 params.setMatrix("pam10");
297 params.setSensitivity("low");
298 params.setSort("totalscore");
299 params.setOutformat("txt");
300 params.setAsync(true);
304 Data inputs[] = new Data[1];
305 Data input = new Data();
306 input.setType("sequence");
307 input.setContent(AlignSeq.extractGaps("-. ",
308 sequence.getSequenceAsString()));
311 WSWUBlastService service = new WSWUBlastServiceLocator();
312 WSWUBlast wublast = service.getWSWUBlast();
313 jobid = wublast.runWUBlast(params, inputs);
314 } catch (Exception exp)
318 System.err.println("WSWUBlastClient error:\n" + exp.toString());
319 exp.printStackTrace();