JAL-1807
[jalview.git] / site / j2s / jalview / workers / StrucConsensusThread.js
1 Clazz.declarePackage ("jalview.workers");
2 Clazz.load (["jalview.api.AlignCalcWorkerI", "jalview.workers.AlignCalcWorker"], "jalview.workers.StrucConsensusThread", ["jalview.analysis.StructureFrequency", "java.lang.Thread"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.strucConsensus = null;
5 this.hStrucConsensus = null;
6 this.nseq = -1;
7 Clazz.instantialize (this, arguments);
8 }, jalview.workers, "StrucConsensusThread", jalview.workers.AlignCalcWorker, jalview.api.AlignCalcWorkerI);
9 Clazz.overrideMethod (c$, "run", 
10 function () {
11 try {
12 if (this.calcMan.isPending (this)) {
13 return;
14 }this.calcMan.notifyStart (this);
15 while (!this.calcMan.notifyWorking (this)) {
16 try {
17 if (this.ap != null) {
18 }Thread.sleep (200);
19 } catch (ex) {
20 if (Clazz.exceptionOf (ex, Exception)) {
21 ex.printStackTrace ();
22 } else {
23 throw ex;
24 }
25 }
26 }
27 if (this.alignViewport.isClosed ()) {
28 this.abortAndDestroy ();
29 return;
30 }var alignment = this.alignViewport.getAlignment ();
31 var aWidth = -1;
32 if (alignment == null || (aWidth = alignment.getWidth ()) < 0) {
33 this.calcMan.workerComplete (this);
34 return;
35 }this.strucConsensus = this.alignViewport.getAlignmentStrucConsensusAnnotation ();
36 this.hStrucConsensus = this.alignViewport.getRnaStructureConsensusHash ();
37 this.strucConsensus.annotations = null;
38 this.strucConsensus.annotations =  new Array (aWidth);
39 this.hStrucConsensus =  new Array (aWidth);
40 var aa = this.alignViewport.getAlignment ().getAlignmentAnnotation ();
41 var rnaStruc = null;
42 for (var i = 0; i < aa.length; i++) {
43 if (aa[i].getRNAStruc () != null && aa[i].isValidStruc ()) {
44 rnaStruc = aa[i];
45 break;
46 }}
47 if (rnaStruc == null || !rnaStruc.isValidStruc ()) {
48 this.calcMan.workerComplete (this);
49 return;
50 }try {
51 var arr = alignment.getSequencesArray ();
52 this.nseq = arr.length;
53 jalview.analysis.StructureFrequency.calculate (arr, 0, alignment.getWidth (), this.hStrucConsensus, true, rnaStruc);
54 } catch (x) {
55 if (Clazz.exceptionOf (x, ArrayIndexOutOfBoundsException)) {
56 this.calcMan.workerComplete (this);
57 return;
58 } else {
59 throw x;
60 }
61 }
62 this.alignViewport.setRnaStructureConsensusHash (this.hStrucConsensus);
63 this.updateResultAnnotation (true);
64 if (this.alignViewport.getGlobalColourScheme () != null) {
65 this.alignViewport.getGlobalColourScheme ().setConsensus (this.hStrucConsensus);
66 }} catch (error) {
67 if (Clazz.exceptionOf (error, OutOfMemoryError)) {
68 this.calcMan.workerCannotRun (this);
69 this.ap.raiseOOMWarning ("calculating RNA structure consensus", error);
70 } else {
71 throw error;
72 }
73 } finally {
74 this.calcMan.workerComplete (this);
75 if (this.ap != null) {
76 this.ap.paintAlignment (true);
77 }}
78 });
79 Clazz.overrideMethod (c$, "updateAnnotation", 
80 function () {
81 this.updateResultAnnotation (false);
82 });
83 Clazz.defineMethod (c$, "updateResultAnnotation", 
84 function (immediate) {
85 if (immediate || !this.calcMan.isWorking (this) && this.strucConsensus != null && this.hStrucConsensus != null) {
86 jalview.analysis.StructureFrequency.completeConsensus (this.strucConsensus, this.hStrucConsensus, 0, this.hStrucConsensus.length, this.alignViewport.isIgnoreGapsConsensus (), this.alignViewport.isShowSequenceLogo (), this.nseq);
87 }}, "~B");
88 });