1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
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; |
32 |
|
|
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.Enumeration; |
35 |
|
import java.util.StringTokenizer; |
36 |
|
import java.util.Vector; |
37 |
|
|
38 |
|
import javax.swing.ImageIcon; |
39 |
|
|
40 |
|
import uk.ac.ebi.www.Data; |
41 |
|
import uk.ac.ebi.www.InputParams; |
42 |
|
import uk.ac.ebi.www.WSFile; |
43 |
|
import uk.ac.ebi.www.WSWUBlast; |
44 |
|
import uk.ac.ebi.www.WSWUBlastService; |
45 |
|
import uk.ac.ebi.www.WSWUBlastServiceLocator; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@author |
51 |
|
@version |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 73 (73) |
Complexity: 14 |
Complexity Density: 0.29 |
|
53 |
|
public class WSWUBlastClient |
54 |
|
{ |
55 |
|
AlignmentPanel ap; |
56 |
|
|
57 |
|
AlignmentI al; |
58 |
|
|
59 |
|
CutAndPasteTransfer output = new CutAndPasteTransfer(); |
60 |
|
|
61 |
|
int jobsRunning = 0; |
62 |
|
|
63 |
|
Vector suggestedIds = new Vector(); |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
|
70 |
|
@param |
71 |
|
|
72 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
73 |
0 |
public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)... |
74 |
|
{ |
75 |
0 |
this.ap = ap; |
76 |
0 |
this.al = al; |
77 |
0 |
output.setText( |
78 |
|
MessageManager.getString("label.wswublast_client_credits")); |
79 |
|
|
80 |
0 |
Desktop.addInternalFrame(output, MessageManager.getString( |
81 |
|
"label.blasting_for_unidentified_sequence"), 800, 300); |
82 |
|
|
83 |
0 |
for (int i = 0; i < ids.size(); i++) |
84 |
|
{ |
85 |
0 |
Sequence sequence = (Sequence) ids.get(i); |
86 |
0 |
System.out.println(sequence.getName()); |
87 |
|
|
88 |
0 |
BlastThread thread = new BlastThread(sequence); |
89 |
0 |
thread.start(); |
90 |
0 |
jobsRunning++; |
91 |
|
} |
92 |
|
|
93 |
0 |
ImageTwirler thread = new ImageTwirler(); |
94 |
0 |
thread.start(); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
|
102 |
|
@param |
103 |
|
|
104 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 6 |
Complexity Density: 0.29 |
|
105 |
0 |
void parseResult(Sequence seq, String res)... |
106 |
|
{ |
107 |
0 |
StringTokenizer st = new StringTokenizer(res, "\n"); |
108 |
0 |
String data; |
109 |
0 |
String id2; |
110 |
0 |
int maxFound = 90; |
111 |
0 |
StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :"); |
112 |
|
|
113 |
0 |
while (st.hasMoreTokens()) |
114 |
|
{ |
115 |
0 |
data = st.nextToken(); |
116 |
|
|
117 |
0 |
if (data.indexOf(">UNIPROT") > -1) |
118 |
|
{ |
119 |
0 |
int index = data.indexOf(">UNIPROT") + 9; |
120 |
0 |
id2 = data.substring(index, data.indexOf(" ", index)); |
121 |
|
|
122 |
0 |
boolean identitiesFound = false; |
123 |
0 |
while (!identitiesFound) |
124 |
|
{ |
125 |
0 |
data = st.nextToken(); |
126 |
|
|
127 |
0 |
if (data.indexOf("Identities") > -1) |
128 |
|
{ |
129 |
0 |
identitiesFound = true; |
130 |
|
|
131 |
0 |
int value = Integer.parseInt(data |
132 |
|
.substring(data.indexOf("(") + 1, data.indexOf("%"))); |
133 |
|
|
134 |
0 |
if (value >= maxFound) |
135 |
|
{ |
136 |
0 |
maxFound = value; |
137 |
0 |
buffer.append(" " + id2 + " " + value + "%; "); |
138 |
0 |
suggestedIds.addElement(new Object[] { seq, id2 }); |
139 |
|
} |
140 |
|
} |
141 |
|
} |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
0 |
output.appendText(buffer.toString()); |
146 |
|
} |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 6 |
Complexity Density: 0.4 |
|
148 |
0 |
void updateIds()... |
149 |
|
{ |
150 |
|
|
151 |
|
|
152 |
0 |
int reply = JvOptionPane.showConfirmDialog(Desktop.desktop, |
153 |
|
"Automatically update suggested ids?", |
154 |
|
"Auto replace sequence ids", JvOptionPane.YES_NO_OPTION); |
155 |
|
|
156 |
0 |
if (reply == JvOptionPane.YES_OPTION) |
157 |
|
{ |
158 |
0 |
Enumeration keys = suggestedIds.elements(); |
159 |
0 |
while (keys.hasMoreElements()) |
160 |
|
{ |
161 |
0 |
Object[] object = (Object[]) keys.nextElement(); |
162 |
|
|
163 |
0 |
Sequence oldseq = (Sequence) object[0]; |
164 |
|
|
165 |
0 |
oldseq.setName(object[1].toString()); |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
0 |
for (int i = 0; i < al.getHeight(); i++) |
170 |
|
{ |
171 |
0 |
if (al.getSequenceAt(i).getDatasetSequence() == oldseq) |
172 |
|
{ |
173 |
0 |
al.getSequenceAt(i).setName(oldseq.getName()); |
174 |
0 |
break; |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
0 |
DBRefEntry[] entries = oldseq.getDBRefs(); |
179 |
0 |
if (entries != null) |
180 |
|
{ |
181 |
0 |
oldseq.addDBRef(new jalview.datamodel.DBRefEntry( |
182 |
|
jalview.datamodel.DBRefSource.UNIPROT, "0", |
183 |
|
entries[0].getAccessionId())); |
184 |
|
} |
185 |
|
} |
186 |
|
} |
187 |
0 |
ap.paintAlignment(true, false); |
188 |
|
|
189 |
|
} |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.5 |
|
191 |
|
class ImageTwirler extends Thread |
192 |
|
{ |
193 |
|
ImageIcon[] imageIcon; |
194 |
|
|
195 |
|
int imageIndex = 0; |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
197 |
0 |
public ImageTwirler()... |
198 |
|
{ |
199 |
0 |
imageIcon = new ImageIcon[9]; |
200 |
|
|
201 |
0 |
for (int i = 0; i < 9; i++) |
202 |
|
{ |
203 |
0 |
java.net.URL url = getClass() |
204 |
|
.getResource("/images/dna" + (i + 1) + ".gif"); |
205 |
|
|
206 |
0 |
if (url != null) |
207 |
|
{ |
208 |
0 |
imageIcon[i] = new ImageIcon(url); |
209 |
|
} |
210 |
|
} |
211 |
|
} |
212 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
213 |
0 |
@Override... |
214 |
|
public void run() |
215 |
|
{ |
216 |
0 |
while (jobsRunning > 0) |
217 |
|
{ |
218 |
0 |
try |
219 |
|
{ |
220 |
0 |
Thread.sleep(100); |
221 |
0 |
imageIndex++; |
222 |
0 |
imageIndex %= 9; |
223 |
0 |
output.setFrameIcon(imageIcon[imageIndex]); |
224 |
0 |
output.setTitle(MessageManager.formatMessage( |
225 |
|
"label.blasting_for_unidentified_sequence_jobs_running", |
226 |
|
new String[] |
227 |
|
{ Integer.valueOf(jobsRunning).toString() })); |
228 |
|
} catch (Exception ex) |
229 |
|
{ |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
0 |
if (jobsRunning == 0) |
234 |
|
{ |
235 |
0 |
updateIds(); |
236 |
|
} |
237 |
|
} |
238 |
|
} |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 7 |
Complexity Density: 0.19 |
|
240 |
|
class BlastThread extends Thread |
241 |
|
{ |
242 |
|
Sequence sequence; |
243 |
|
|
244 |
|
String jobid; |
245 |
|
|
246 |
|
boolean jobComplete = false; |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
248 |
0 |
BlastThread(Sequence sequence)... |
249 |
|
{ |
250 |
0 |
System.out.println("blasting for: " + sequence.getName()); |
251 |
0 |
this.sequence = sequence; |
252 |
|
} |
253 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
254 |
0 |
@Override... |
255 |
|
public void run() |
256 |
|
{ |
257 |
0 |
StartJob(); |
258 |
|
|
259 |
0 |
while (!jobComplete) |
260 |
|
{ |
261 |
0 |
try |
262 |
|
{ |
263 |
0 |
WSWUBlastService service = new WSWUBlastServiceLocator(); |
264 |
0 |
WSWUBlast wublast = service.getWSWUBlast(); |
265 |
0 |
WSFile[] results = wublast.getResults(jobid); |
266 |
|
|
267 |
0 |
if (results != null) |
268 |
|
{ |
269 |
0 |
String result = new String(wublast.poll(jobid, "tooloutput")); |
270 |
0 |
parseResult(sequence, result); |
271 |
0 |
jobComplete = true; |
272 |
0 |
jobsRunning--; |
273 |
|
} |
274 |
|
else |
275 |
|
{ |
276 |
0 |
Thread.sleep(10000); |
277 |
0 |
System.out.println("WSWuBlastClient: I'm alive " |
278 |
|
+ sequence.getName() + " " + jobid); |
279 |
|
} |
280 |
|
} catch (Exception ex) |
281 |
|
{ |
282 |
|
} |
283 |
|
} |
284 |
|
} |
285 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 2 |
Complexity Density: 0.09 |
|
286 |
0 |
void StartJob()... |
287 |
|
{ |
288 |
0 |
InputParams params = new InputParams(); |
289 |
|
|
290 |
0 |
params.setProgram("blastp"); |
291 |
0 |
params.setDatabase("uniprot"); |
292 |
0 |
params.setMatrix("pam10"); |
293 |
|
|
294 |
0 |
params.setNumal(5); |
295 |
0 |
params.setSensitivity("low"); |
296 |
0 |
params.setSort("totalscore"); |
297 |
0 |
params.setOutformat("txt"); |
298 |
0 |
params.setAsync(true); |
299 |
|
|
300 |
0 |
try |
301 |
|
{ |
302 |
0 |
Data inputs[] = new Data[1]; |
303 |
0 |
Data input = new Data(); |
304 |
0 |
input.setType("sequence"); |
305 |
0 |
input.setContent(AlignSeq.extractGaps("-. ", |
306 |
|
sequence.getSequenceAsString())); |
307 |
0 |
inputs[0] = input; |
308 |
|
|
309 |
0 |
WSWUBlastService service = new WSWUBlastServiceLocator(); |
310 |
0 |
WSWUBlast wublast = service.getWSWUBlast(); |
311 |
0 |
jobid = wublast.runWUBlast(params, inputs); |
312 |
|
} catch (Exception exp) |
313 |
|
{ |
314 |
0 |
jobComplete = true; |
315 |
0 |
jobsRunning--; |
316 |
0 |
System.err.println("WSWUBlastClient error:\n" + exp.toString()); |
317 |
0 |
exp.printStackTrace(); |
318 |
|
} |
319 |
|
} |
320 |
|
} |
321 |
|
} |