Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
MsaWSThread | 44 | 145 | 57 | ||
MsaWSThread.MsaWSJob | 54 | 83 | 41 |
1 | /* | |
2 | * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) | |
3 | * Copyright (C) $$Year-Rel$$ The Jalview Authors | |
4 | * | |
5 | * This file is part of Jalview. | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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. | |
20 | */ | |
21 | package jalview.ws.jws1; | |
22 | ||
23 | import jalview.analysis.AlignSeq; | |
24 | import jalview.bin.Console; | |
25 | import jalview.datamodel.Alignment; | |
26 | import jalview.datamodel.AlignmentI; | |
27 | import jalview.datamodel.AlignmentOrder; | |
28 | import jalview.datamodel.AlignmentView; | |
29 | import jalview.datamodel.HiddenColumns; | |
30 | import jalview.datamodel.SequenceI; | |
31 | import jalview.gui.AlignFrame; | |
32 | import jalview.gui.Desktop; | |
33 | import jalview.gui.WebserviceInfo; | |
34 | import jalview.util.MessageManager; | |
35 | import jalview.ws.AWsJob; | |
36 | import jalview.ws.JobStateSummary; | |
37 | import jalview.ws.WSClientI; | |
38 | ||
39 | import java.util.Hashtable; | |
40 | import java.util.Vector; | |
41 | ||
42 | import vamsas.objects.simple.MsaResult; | |
43 | ||
44 | class MsaWSThread extends JWS1Thread implements WSClientI | |
45 | { | |
46 | boolean submitGaps = false; // pass sequences including gaps to alignment | |
47 | ||
48 | // service | |
49 | ||
50 | boolean preserveOrder = true; // and always store and recover sequence | |
51 | ||
52 | // order | |
53 | ||
54 | class MsaWSJob extends WSJob | |
55 | { | |
56 | // hold special input for this | |
57 | vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple.SequenceSet(); | |
58 | ||
59 | /** | |
60 | * MsaWSJob | |
61 | * | |
62 | * @param jobNum | |
63 | * int | |
64 | * @param jobId | |
65 | * String | |
66 | */ | |
67 | 0 | public MsaWSJob(int jobNum, SequenceI[] inSeqs) |
68 | { | |
69 | 0 | this.jobnum = jobNum; |
70 | 0 | if (!prepareInput(inSeqs, 2)) |
71 | { | |
72 | 0 | submitted = true; |
73 | 0 | subjobComplete = true; |
74 | 0 | result = new MsaResult(); |
75 | 0 | result.setFinished(true); |
76 | 0 | result.setStatus(MessageManager.getString("label.job_never_ran")); |
77 | } | |
78 | ||
79 | } | |
80 | ||
81 | Hashtable SeqNames = new Hashtable(); | |
82 | ||
83 | Vector emptySeqs = new Vector(); | |
84 | ||
85 | /** | |
86 | * prepare input sequences for MsaWS service | |
87 | * | |
88 | * @param seqs | |
89 | * jalview sequences to be prepared | |
90 | * @param minlen | |
91 | * minimum number of residues required for this MsaWS service | |
92 | * @return true if seqs contains sequences to be submitted to service. | |
93 | */ | |
94 | 0 | private boolean prepareInput(SequenceI[] seqs, int minlen) |
95 | { | |
96 | 0 | int nseqs = 0; |
97 | 0 | if (minlen < 0) |
98 | { | |
99 | 0 | throw new Error(MessageManager.getString( |
100 | "error.implementation_error_minlen_must_be_greater_zero")); | |
101 | } | |
102 | 0 | for (int i = 0; i < seqs.length; i++) |
103 | { | |
104 | 0 | if (seqs[i].getEnd() - seqs[i].getStart() > minlen - 1) |
105 | { | |
106 | 0 | nseqs++; |
107 | } | |
108 | } | |
109 | 0 | boolean valid = nseqs > 1; // need at least two seqs |
110 | 0 | vamsas.objects.simple.Sequence[] seqarray = (valid) |
111 | ? new vamsas.objects.simple.Sequence[nseqs] | |
112 | : null; | |
113 | 0 | for (int i = 0, n = 0; i < seqs.length; i++) |
114 | { | |
115 | ||
116 | 0 | String newname = jalview.analysis.SeqsetUtils.unique_name(i); // same |
117 | // for | |
118 | // any | |
119 | // subjob | |
120 | 0 | SeqNames.put(newname, |
121 | jalview.analysis.SeqsetUtils.SeqCharacterHash(seqs[i])); | |
122 | 0 | if (valid && seqs[i].getEnd() - seqs[i].getStart() > minlen - 1) |
123 | { | |
124 | 0 | seqarray[n] = new vamsas.objects.simple.Sequence(); |
125 | 0 | seqarray[n].setId(newname); |
126 | 0 | seqarray[n++].setSeq((submitGaps) ? seqs[i].getSequenceAsString() |
127 | : AlignSeq.extractGaps(jalview.util.Comparison.GapChars, | |
128 | seqs[i].getSequenceAsString())); | |
129 | } | |
130 | else | |
131 | { | |
132 | 0 | String empty = null; |
133 | 0 | if (seqs[i].getEnd() >= seqs[i].getStart()) |
134 | { | |
135 | 0 | empty = (submitGaps) ? seqs[i].getSequenceAsString() |
136 | : AlignSeq.extractGaps(jalview.util.Comparison.GapChars, | |
137 | seqs[i].getSequenceAsString()); | |
138 | } | |
139 | 0 | emptySeqs.add(new String[] { newname, empty }); |
140 | } | |
141 | } | |
142 | 0 | this.seqs = new vamsas.objects.simple.SequenceSet(); |
143 | 0 | this.seqs.setSeqs(seqarray); |
144 | 0 | return valid; |
145 | } | |
146 | ||
147 | /** | |
148 | * | |
149 | * @return true if getAlignment will return a valid alignment result. | |
150 | */ | |
151 | 0 | @Override |
152 | public boolean hasResults() | |
153 | { | |
154 | 0 | if (subjobComplete && result != null && result.isFinished() |
155 | && ((MsaResult) result).getMsa() != null | |
156 | && ((MsaResult) result).getMsa().getSeqs() != null) | |
157 | { | |
158 | 0 | return true; |
159 | } | |
160 | 0 | return false; |
161 | } | |
162 | ||
163 | 0 | public Object[] getAlignment() |
164 | { | |
165 | ||
166 | 0 | if (result != null && result.isFinished()) |
167 | { | |
168 | 0 | SequenceI[] alseqs = null; |
169 | 0 | char alseq_gapchar = '-'; |
170 | 0 | int alseq_l = 0; |
171 | 0 | if (((MsaResult) result).getMsa() != null) |
172 | { | |
173 | 0 | alseqs = getVamsasAlignment(((MsaResult) result).getMsa()); |
174 | 0 | alseq_gapchar = ((MsaResult) result).getMsa().getGapchar() |
175 | .charAt(0); | |
176 | 0 | alseq_l = alseqs.length; |
177 | } | |
178 | 0 | if (emptySeqs.size() > 0) |
179 | { | |
180 | 0 | SequenceI[] t_alseqs = new SequenceI[alseq_l + emptySeqs.size()]; |
181 | // get width | |
182 | 0 | int i, w = 0; |
183 | 0 | if (alseq_l > 0) |
184 | { | |
185 | 0 | for (i = 0, w = alseqs[0].getLength(); i < alseq_l; i++) |
186 | { | |
187 | 0 | if (w < alseqs[i].getLength()) |
188 | { | |
189 | 0 | w = alseqs[i].getLength(); |
190 | } | |
191 | 0 | t_alseqs[i] = alseqs[i]; |
192 | 0 | alseqs[i] = null; |
193 | } | |
194 | } | |
195 | // check that aligned width is at least as wide as emptySeqs width. | |
196 | 0 | int ow = w, nw = w; |
197 | 0 | for (i = 0, w = emptySeqs.size(); i < w; i++) |
198 | { | |
199 | 0 | String[] es = (String[]) emptySeqs.get(i); |
200 | 0 | if (es != null && es[1] != null) |
201 | { | |
202 | 0 | int sw = es[1].length(); |
203 | 0 | if (nw < sw) |
204 | { | |
205 | 0 | nw = sw; |
206 | } | |
207 | } | |
208 | } | |
209 | // make a gapped string. | |
210 | 0 | StringBuffer insbuff = new StringBuffer(w); |
211 | 0 | for (i = 0; i < nw; i++) |
212 | { | |
213 | 0 | insbuff.append(alseq_gapchar); |
214 | } | |
215 | 0 | if (ow < nw) |
216 | { | |
217 | 0 | for (i = 0; i < alseq_l; i++) |
218 | { | |
219 | 0 | int sw = t_alseqs[i].getLength(); |
220 | 0 | if (nw > sw) |
221 | { | |
222 | // pad at end | |
223 | 0 | alseqs[i].setSequence(t_alseqs[i].getSequenceAsString() |
224 | + insbuff.substring(0, sw - nw)); | |
225 | } | |
226 | } | |
227 | } | |
228 | 0 | for (i = 0, w = emptySeqs.size(); i < w; i++) |
229 | { | |
230 | 0 | String[] es = (String[]) emptySeqs.get(i); |
231 | 0 | if (es[1] == null) |
232 | { | |
233 | 0 | t_alseqs[i + alseq_l] = new jalview.datamodel.Sequence(es[0], |
234 | insbuff.toString(), 1, 0); | |
235 | } | |
236 | else | |
237 | { | |
238 | 0 | if (es[1].length() < nw) |
239 | { | |
240 | 0 | t_alseqs[i + alseq_l] = new jalview.datamodel.Sequence( |
241 | es[0], | |
242 | es[1] + insbuff.substring(0, nw - es[1].length()), | |
243 | 1, 1 + es[1].length()); | |
244 | } | |
245 | else | |
246 | { | |
247 | 0 | t_alseqs[i + alseq_l] = new jalview.datamodel.Sequence( |
248 | es[0], es[1]); | |
249 | } | |
250 | } | |
251 | } | |
252 | 0 | alseqs = t_alseqs; |
253 | } | |
254 | 0 | AlignmentOrder msaorder = new AlignmentOrder(alseqs); |
255 | // always recover the order - makes parseResult()'s life easier. | |
256 | 0 | jalview.analysis.AlignmentSorter.recoverOrder(alseqs); |
257 | // account for any missing sequences | |
258 | 0 | jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs); |
259 | 0 | return new Object[] { alseqs, msaorder }; |
260 | } | |
261 | 0 | return null; |
262 | } | |
263 | ||
264 | /** | |
265 | * mark subjob as cancelled and set result object appropriatly | |
266 | */ | |
267 | 0 | void cancel() |
268 | { | |
269 | 0 | cancelled = true; |
270 | 0 | subjobComplete = true; |
271 | 0 | result = null; |
272 | } | |
273 | ||
274 | /** | |
275 | * | |
276 | * @return boolean true if job can be submitted. | |
277 | */ | |
278 | 0 | @Override |
279 | public boolean hasValidInput() | |
280 | { | |
281 | 0 | if (seqs.getSeqs() != null) |
282 | { | |
283 | 0 | return true; |
284 | } | |
285 | 0 | return false; |
286 | } | |
287 | } | |
288 | ||
289 | String alTitle; // name which will be used to form new alignment window. | |
290 | ||
291 | AlignmentI dataset; // dataset to which the new alignment will be | |
292 | ||
293 | // associated. | |
294 | ||
295 | ext.vamsas.MuscleWS server = null; | |
296 | ||
297 | /** | |
298 | * set basic options for this (group) of Msa jobs | |
299 | * | |
300 | * @param subgaps | |
301 | * boolean | |
302 | * @param presorder | |
303 | * boolean | |
304 | */ | |
305 | 0 | MsaWSThread(ext.vamsas.MuscleWS server, String wsUrl, |
306 | WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame, | |
307 | AlignmentView alview, String wsname, boolean subgaps, | |
308 | boolean presorder) | |
309 | { | |
310 | 0 | super(alFrame, wsinfo, alview, wsname, wsUrl); |
311 | 0 | this.server = server; |
312 | 0 | this.submitGaps = subgaps; |
313 | 0 | this.preserveOrder = presorder; |
314 | } | |
315 | ||
316 | /** | |
317 | * create one or more Msa jobs to align visible seuqences in _msa | |
318 | * | |
319 | * @param title | |
320 | * String | |
321 | * @param _msa | |
322 | * AlignmentView | |
323 | * @param subgaps | |
324 | * boolean | |
325 | * @param presorder | |
326 | * boolean | |
327 | * @param seqset | |
328 | * Alignment | |
329 | */ | |
330 | 0 | MsaWSThread(ext.vamsas.MuscleWS server, String wsUrl, |
331 | WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame, | |
332 | String wsname, String title, AlignmentView _msa, boolean subgaps, | |
333 | boolean presorder, AlignmentI seqset) | |
334 | { | |
335 | 0 | this(server, wsUrl, wsinfo, alFrame, _msa, wsname, subgaps, presorder); |
336 | 0 | OutputHeader = wsInfo.getProgressText(); |
337 | 0 | alTitle = title; |
338 | 0 | dataset = seqset; |
339 | ||
340 | 0 | SequenceI[][] conmsa = _msa.getVisibleContigs('-'); |
341 | 0 | if (conmsa != null) |
342 | { | |
343 | 0 | int njobs = conmsa.length; |
344 | 0 | jobs = new MsaWSJob[njobs]; |
345 | 0 | for (int j = 0; j < njobs; j++) |
346 | { | |
347 | 0 | if (j != 0) |
348 | { | |
349 | 0 | jobs[j] = new MsaWSJob(wsinfo.addJobPane(), conmsa[j]); |
350 | } | |
351 | else | |
352 | { | |
353 | 0 | jobs[j] = new MsaWSJob(0, conmsa[j]); |
354 | } | |
355 | 0 | if (njobs > 0) |
356 | { | |
357 | 0 | wsinfo.setProgressName("region " + jobs[j].getJobnum(), |
358 | jobs[j].getJobnum()); | |
359 | } | |
360 | 0 | wsinfo.setProgressText(jobs[j].getJobnum(), OutputHeader); |
361 | } | |
362 | } | |
363 | } | |
364 | ||
365 | 0 | @Override |
366 | public boolean isCancellable() | |
367 | { | |
368 | 0 | return true; |
369 | } | |
370 | ||
371 | 0 | @Override |
372 | public void cancelJob() | |
373 | { | |
374 | 0 | if (!jobComplete && jobs != null) |
375 | { | |
376 | 0 | boolean cancelled = true; |
377 | 0 | for (int job = 0; job < jobs.length; job++) |
378 | { | |
379 | 0 | if (jobs[job].isSubmitted() && !jobs[job].isSubjobComplete()) |
380 | { | |
381 | 0 | String cancelledMessage = ""; |
382 | 0 | try |
383 | { | |
384 | 0 | vamsas.objects.simple.WsJobId cancelledJob = server |
385 | .cancel(jobs[job].getJobId()); | |
386 | 0 | if (cancelledJob.getStatus() == 2) |
387 | { | |
388 | // CANCELLED_JOB | |
389 | 0 | cancelledMessage = "Job cancelled."; |
390 | 0 | ((MsaWSJob) jobs[job]).cancel(); |
391 | 0 | wsInfo.setStatus(jobs[job].getJobnum(), |
392 | WebserviceInfo.STATE_CANCELLED_OK); | |
393 | } | |
394 | 0 | else if (cancelledJob.getStatus() == 3) |
395 | { | |
396 | // VALID UNSTOPPABLE JOB | |
397 | 0 | cancelledMessage += "Server cannot cancel this job. just close the window.\n"; |
398 | 0 | cancelled = false; |
399 | // wsInfo.setStatus(jobs[job].jobnum, | |
400 | // WebserviceInfo.STATE_RUNNING); | |
401 | } | |
402 | ||
403 | 0 | if (cancelledJob.getJobId() != null) |
404 | { | |
405 | 0 | cancelledMessage += ("[" + cancelledJob.getJobId() + "]"); |
406 | } | |
407 | ||
408 | 0 | cancelledMessage += "\n"; |
409 | } catch (Exception exc) | |
410 | { | |
411 | 0 | cancelledMessage += ("\nProblems cancelling the job : Exception received...\n" |
412 | + exc + "\n"); | |
413 | 0 | Console.warn( |
414 | "Exception whilst cancelling " + jobs[job].getJobId(), | |
415 | exc); | |
416 | } | |
417 | 0 | wsInfo.setProgressText(jobs[job].getJobnum(), |
418 | OutputHeader + cancelledMessage + "\n"); | |
419 | } | |
420 | } | |
421 | 0 | if (cancelled) |
422 | { | |
423 | 0 | wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK); |
424 | 0 | jobComplete = true; |
425 | } | |
426 | 0 | this.interrupt(); // kick thread to update job states. |
427 | } | |
428 | else | |
429 | { | |
430 | 0 | if (!jobComplete) |
431 | { | |
432 | 0 | wsInfo.setProgressText(OutputHeader |
433 | + "Server cannot cancel this job because it has not been submitted properly. just close the window.\n"); | |
434 | } | |
435 | } | |
436 | } | |
437 | ||
438 | 0 | @Override |
439 | public void pollJob(AWsJob job) throws Exception | |
440 | { | |
441 | 0 | ((MsaWSJob) job).result = server.getResult(((MsaWSJob) job).getJobId()); |
442 | } | |
443 | ||
444 | 0 | @Override |
445 | public void StartJob(AWsJob job) | |
446 | { | |
447 | 0 | if (!(job instanceof MsaWSJob)) |
448 | { | |
449 | 0 | throw new Error(MessageManager.formatMessage( |
450 | "error.implementation_error_msawbjob_called", new String[] | |
451 | { job.getClass().toString() })); | |
452 | } | |
453 | 0 | MsaWSJob j = (MsaWSJob) job; |
454 | 0 | if (j.isSubmitted()) |
455 | { | |
456 | 0 | if (Console.isDebugEnabled()) |
457 | { | |
458 | 0 | Console.debug( |
459 | "Tried to submit an already submitted job " + j.getJobId()); | |
460 | } | |
461 | 0 | return; |
462 | } | |
463 | 0 | if (j.seqs.getSeqs() == null) |
464 | { | |
465 | // special case - selection consisted entirely of empty sequences... | |
466 | 0 | j.setSubmitted(true); |
467 | 0 | j.result = new MsaResult(); |
468 | 0 | j.result.setFinished(true); |
469 | 0 | j.result.setStatus( |
470 | MessageManager.getString("label.empty_alignment_job")); | |
471 | 0 | ((MsaResult) j.result).setMsa(null); |
472 | } | |
473 | 0 | try |
474 | { | |
475 | 0 | vamsas.objects.simple.WsJobId jobsubmit = server.align(j.seqs); |
476 | ||
477 | 0 | if ((jobsubmit != null) && (jobsubmit.getStatus() == 1)) |
478 | { | |
479 | 0 | j.setJobId(jobsubmit.getJobId()); |
480 | 0 | j.setSubmitted(true); |
481 | 0 | j.setSubjobComplete(false); |
482 | // jalview.bin.Console.outPrintln(WsURL + " Job Id '" + jobId + "'"); | |
483 | } | |
484 | else | |
485 | { | |
486 | 0 | if (jobsubmit == null) |
487 | { | |
488 | 0 | throw new Exception(MessageManager.formatMessage( |
489 | "exception.web_service_returned_null_try_later", | |
490 | new String[] | |
491 | { WsUrl })); | |
492 | } | |
493 | ||
494 | 0 | throw new Exception(jobsubmit.getJobId()); |
495 | } | |
496 | } catch (Exception e) | |
497 | { | |
498 | // TODO: JBPNote catch timeout or other fault types explicitly | |
499 | // For unexpected errors | |
500 | 0 | jalview.bin.Console.errPrintln(WebServiceName |
501 | + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n" | |
502 | + "When contacting Server:" + WsUrl + "\n" + e.toString() | |
503 | + "\n"); | |
504 | 0 | j.setAllowedServerExceptions(0); |
505 | 0 | wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); |
506 | 0 | wsInfo.setStatus(j.getJobnum(), |
507 | WebserviceInfo.STATE_STOPPED_SERVERERROR); | |
508 | 0 | wsInfo.appendProgressText(j.getJobnum(), MessageManager |
509 | .getString("info.failed_to_submit_sequences_for_alignment")); | |
510 | ||
511 | // e.printStackTrace(); // TODO: JBPNote DEBUG | |
512 | } | |
513 | } | |
514 | ||
515 | 0 | private jalview.datamodel.Sequence[] getVamsasAlignment( |
516 | vamsas.objects.simple.Alignment valign) | |
517 | { | |
518 | // TODO: refactor to helper class for vamsas.objects.simple objects | |
519 | 0 | vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs(); |
520 | 0 | jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs.length]; |
521 | ||
522 | 0 | for (int i = 0, j = seqs.length; i < j; i++) |
523 | { | |
524 | 0 | msa[i] = new jalview.datamodel.Sequence(seqs[i].getId(), |
525 | seqs[i].getSeq()); | |
526 | } | |
527 | ||
528 | 0 | return msa; |
529 | } | |
530 | ||
531 | 0 | @Override |
532 | public void parseResult() | |
533 | { | |
534 | 0 | int results = 0; // number of result sets received |
535 | 0 | JobStateSummary finalState = new JobStateSummary(); |
536 | 0 | try |
537 | { | |
538 | 0 | for (int j = 0; j < jobs.length; j++) |
539 | { | |
540 | 0 | finalState.updateJobPanelState(wsInfo, OutputHeader, jobs[j]); |
541 | 0 | if (jobs[j].isSubmitted() && jobs[j].isSubjobComplete() |
542 | && jobs[j].hasResults()) | |
543 | { | |
544 | 0 | results++; |
545 | // if (Cache.isDebugEnabled()) | |
546 | // { | |
547 | // jalview.bin.Console.outPrintln("Job lob for job | |
548 | // "+jobs[j].getJobId()+":"+jobs[j].getJobnum()); | |
549 | // jalview.bin.Console.outPrintln(jobs[j].getStatus()); | |
550 | // } | |
551 | ||
552 | 0 | vamsas.objects.simple.Alignment valign = ((MsaResult) ((MsaWSJob) jobs[j]).result) |
553 | .getMsa(); | |
554 | 0 | if (valign != null) |
555 | { | |
556 | 0 | wsInfo.appendProgressText(jobs[j].getJobnum(), MessageManager |
557 | .getString("info.alignment_object_method_notes")); | |
558 | 0 | String[] lines = valign.getMethod(); |
559 | 0 | for (int line = 0; line < lines.length; line++) |
560 | { | |
561 | 0 | wsInfo.appendProgressText(jobs[j].getJobnum(), |
562 | lines[line] + "\n"); | |
563 | } | |
564 | // JBPNote The returned files from a webservice could be | |
565 | // hidden behind icons in the monitor window that, | |
566 | // when clicked, pop up their corresponding data | |
567 | ||
568 | } | |
569 | } | |
570 | } | |
571 | } catch (Exception ex) | |
572 | { | |
573 | ||
574 | 0 | Console.error( |
575 | "Unexpected exception when processing results for " + alTitle, | |
576 | ex); | |
577 | 0 | wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); |
578 | } | |
579 | 0 | if (results > 0) |
580 | { | |
581 | 0 | wsInfo.showResultsNewFrame |
582 | .addActionListener(new java.awt.event.ActionListener() | |
583 | { | |
584 | 0 | @Override |
585 | public void actionPerformed(java.awt.event.ActionEvent evt) | |
586 | { | |
587 | 0 | displayResults(true); |
588 | } | |
589 | }); | |
590 | 0 | wsInfo.mergeResults |
591 | .addActionListener(new java.awt.event.ActionListener() | |
592 | { | |
593 | 0 | @Override |
594 | public void actionPerformed(java.awt.event.ActionEvent evt) | |
595 | { | |
596 | 0 | displayResults(false); |
597 | } | |
598 | }); | |
599 | 0 | wsInfo.setResultsReady(); |
600 | } | |
601 | else | |
602 | { | |
603 | 0 | wsInfo.setFinishedNoResults(); |
604 | } | |
605 | } | |
606 | ||
607 | 0 | void displayResults(boolean newFrame) |
608 | { | |
609 | // view input or result data for each block | |
610 | 0 | Vector alorders = new Vector(); |
611 | 0 | SequenceI[][] results = new SequenceI[jobs.length][]; |
612 | 0 | AlignmentOrder[] orders = new AlignmentOrder[jobs.length]; |
613 | 0 | for (int j = 0; j < jobs.length; j++) |
614 | { | |
615 | 0 | if (jobs[j].hasResults()) |
616 | { | |
617 | 0 | Object[] res = ((MsaWSJob) jobs[j]).getAlignment(); |
618 | 0 | alorders.add(res[1]); |
619 | 0 | results[j] = (SequenceI[]) res[0]; |
620 | 0 | orders[j] = (AlignmentOrder) res[1]; |
621 | ||
622 | // SequenceI[] alignment = input.getUpdated | |
623 | } | |
624 | else | |
625 | { | |
626 | 0 | results[j] = null; |
627 | } | |
628 | } | |
629 | 0 | Object[] newview = input.getUpdatedView(results, orders, getGapChar()); |
630 | // trash references to original result data | |
631 | 0 | for (int j = 0; j < jobs.length; j++) |
632 | { | |
633 | 0 | results[j] = null; |
634 | 0 | orders[j] = null; |
635 | } | |
636 | 0 | SequenceI[] alignment = (SequenceI[]) newview[0]; |
637 | 0 | HiddenColumns hidden = (HiddenColumns) newview[1]; |
638 | 0 | Alignment al = new Alignment(alignment); |
639 | // TODO: add 'provenance' property to alignment from the method notes | |
640 | // accompanying each subjob | |
641 | 0 | if (dataset != null) |
642 | { | |
643 | 0 | al.setDataset(dataset); |
644 | } | |
645 | ||
646 | 0 | propagateDatasetMappings(al); |
647 | // JBNote- TODO: warn user if a block is input rather than aligned data ? | |
648 | ||
649 | 0 | if (newFrame) |
650 | { | |
651 | 0 | AlignFrame af = new AlignFrame(al, hidden, AlignFrame.DEFAULT_WIDTH, |
652 | AlignFrame.DEFAULT_HEIGHT); | |
653 | ||
654 | // initialise with same renderer settings as in parent alignframe. | |
655 | 0 | af.getFeatureRenderer().transferSettings(this.featureSettings); |
656 | // update orders | |
657 | 0 | if (alorders.size() > 0) |
658 | { | |
659 | 0 | if (alorders.size() == 1) |
660 | { | |
661 | 0 | af.addSortByOrderMenuItem(WebServiceName + " Ordering", |
662 | (AlignmentOrder) alorders.get(0)); | |
663 | } | |
664 | else | |
665 | { | |
666 | // construct a non-redundant ordering set | |
667 | 0 | Vector names = new Vector(); |
668 | 0 | for (int i = 0, l = alorders.size(); i < l; i++) |
669 | { | |
670 | 0 | String orderName = new String(" Region " + i); |
671 | 0 | int j = i + 1; |
672 | ||
673 | 0 | while (j < l) |
674 | { | |
675 | 0 | if (((AlignmentOrder) alorders.get(i)) |
676 | .equals((alorders.get(j)))) | |
677 | { | |
678 | 0 | alorders.remove(j); |
679 | 0 | l--; |
680 | 0 | orderName += "," + j; |
681 | } | |
682 | else | |
683 | { | |
684 | 0 | j++; |
685 | } | |
686 | } | |
687 | ||
688 | 0 | if (i == 0 && j == 1) |
689 | { | |
690 | 0 | names.add(new String("")); |
691 | } | |
692 | else | |
693 | { | |
694 | 0 | names.add(orderName); |
695 | } | |
696 | } | |
697 | 0 | for (int i = 0, l = alorders.size(); i < l; i++) |
698 | { | |
699 | 0 | af.addSortByOrderMenuItem( |
700 | WebServiceName + ((String) names.get(i)) + " Ordering", | |
701 | (AlignmentOrder) alorders.get(i)); | |
702 | } | |
703 | } | |
704 | } | |
705 | ||
706 | 0 | Desktop.addInternalFrame(af, alTitle, AlignFrame.DEFAULT_WIDTH, |
707 | AlignFrame.DEFAULT_HEIGHT); | |
708 | ||
709 | } | |
710 | else | |
711 | { | |
712 | 0 | jalview.bin.Console.outPrintln("MERGE WITH OLD FRAME"); |
713 | // TODO: modify alignment in original frame, replacing old for new | |
714 | // alignment using the commands.EditCommand model to ensure the update can | |
715 | // be undone | |
716 | } | |
717 | } | |
718 | ||
719 | 0 | @Override |
720 | public boolean canMergeResults() | |
721 | { | |
722 | 0 | return false; |
723 | } | |
724 | } |