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