Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.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"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.rnaStruc = null;
5 this.strucConsensus = null;
6 this.hStrucConsensus = null;
7 this.nseq = -1;
8 this.aa = null;
9 this.arr = null;
10 Clazz.instantialize (this, arguments);
11 }, jalview.workers, "StrucConsensusThread", jalview.workers.AlignCalcWorker, jalview.api.AlignCalcWorkerI);
12 Clazz.overrideMethod (c$, "getNewWorker", 
13 function () {
14 return  new jalview.workers.StrucConsensusThread (this.alignViewport, this.ap);
15 });
16 Clazz.overrideMethod (c$, "run1", 
17 function (state) {
18 if (this.alignViewport.isClosed ()) {
19 this.abortAndDestroy ();
20 return;
21 }while (!Thread.interrupted ()) {
22 try {
23 switch (state) {
24 case 0:
25 if (this.calcMan.isPending (this)) return;
26 this.calcMan.notifyStart (this);
27 state = 3;
28 break;
29 case 3:
30 while (!this.calcMan.notifyWorking (this)) {
31 if (this.ap != null) {
32 this.ap.paintAlignment (false);
33 }try {
34 if (this.sleepAndReturn (200, state)) return;
35 } catch (e) {
36 if (Clazz.exceptionOf (e, InterruptedException)) {
37 state = 2;
38 break;
39 } else {
40 throw e;
41 }
42 }
43 }
44 if (this.alignViewport.isClosed ()) {
45 this.abortAndDestroy ();
46 state = 2;
47 break;
48 }this.alignment = this.alignViewport.getAlignment ();
49 this.aWidth = -1;
50 if (this.alignment == null || (this.aWidth = this.alignment.getWidth ()) < 0) {
51 state = 2;
52 }this.strucConsensus = this.alignViewport.getAlignmentStrucConsensusAnnotation ();
53 this.hStrucConsensus = this.alignViewport.getRnaStructureConsensusHash ();
54 this.strucConsensus.annotations = null;
55 this.strucConsensus.annotations =  new Array (this.aWidth);
56 this.hStrucConsensus =  new Array (this.aWidth);
57 this.aa = this.alignViewport.getAlignment ().getAlignmentAnnotation ();
58 for (var i = 0; i < this.aa.length; i++) {
59 if (this.aa[i].getRNAStruc () != null && this.aa[i].isValidStruc ()) {
60 this.rnaStruc = this.aa[i];
61 break;
62 }}
63 if (this.rnaStruc == null || !this.rnaStruc.isValidStruc ()) {
64 this.calcMan.workerComplete (this);
65 return;
66 }this.arr = this.alignment.getSequencesArray ();
67 this.nseq = this.arr.length;
68 state = 4;
69 break;
70 case 4:
71 this.iFirst = this.iLast;
72 this.iLast = Math.min (this.iLast + this.nPer, this.aWidth);
73 if (this.iLast == this.iFirst) {
74 state = 2;
75 } else {
76 jalview.analysis.StructureFrequency.calculate (this.arr, 0, this.alignment.getWidth (), this.hStrucConsensus, true, this.rnaStruc);
77 if (this.sleepAndReturn (0, state)) return;
78 }break;
79 case 2:
80 this.alignViewport.setRnaStructureConsensusHash (this.hStrucConsensus);
81 this.updateResultAnnotation (true);
82 if (this.alignViewport.getGlobalColourScheme () != null) {
83 this.alignViewport.getGlobalColourScheme ().setConsensus (this.hStrucConsensus);
84 }this.notifyDone ();
85 return;
86 }
87 } catch (e$$) {
88 if (Clazz.exceptionOf (e$$, OutOfMemoryError)) {
89 var error = e$$;
90 {
91 this.calcMan.workerCannotRun (this);
92 this.ap.raiseOOMWarning ("calculating RNA structure consensus", error);
93 }
94 } else {
95 var e = e$$;
96 {
97 System.out.println ("Error in ConsensusThread: " + e);
98 e.printStackTrace ();
99 this.calcMan.workerComplete (this);
100 }
101 }
102 }
103 }
104 }, "~N");
105 Clazz.overrideMethod (c$, "updateAnnotation", 
106 function () {
107 this.updateResultAnnotation (false);
108 });
109 Clazz.defineMethod (c$, "updateResultAnnotation", 
110 function (immediate) {
111 if (immediate || !this.calcMan.isWorking (this) && this.strucConsensus != null && this.hStrucConsensus != null) {
112 jalview.analysis.StructureFrequency.completeConsensus (this.strucConsensus, this.hStrucConsensus, 0, this.hStrucConsensus.length, this.alignViewport.isIgnoreGapsConsensus (), this.alignViewport.isShowSequenceLogo (), this.nseq);
113 }}, "~B");
114 });