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