JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jalview / workers / ConservationThread.js
1 Clazz.declarePackage ("jalview.workers");\r
2 Clazz.load (["jalview.api.AlignCalcWorkerI", "jalview.workers.AlignCalcWorker"], "jalview.workers.ConservationThread", ["jalview.analysis.Conservation", "jalview.schemes.ResidueProperties", "java.util.ArrayList"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.ConsPercGaps = 25;\r
5 this.cons = null;\r
6 this.conservation = null;\r
7 this.quality = null;\r
8 Clazz.instantialize (this, arguments);\r
9 }, jalview.workers, "ConservationThread", jalview.workers.AlignCalcWorker, jalview.api.AlignCalcWorkerI);\r
10 Clazz.overrideMethod (c$, "getNewWorker", \r
11 function () {\r
12 return  new jalview.workers.ConservationThread (this.alignViewport, this.ap);\r
13 });\r
14 Clazz.makeConstructor (c$, \r
15 function (alignViewport, alignPanel) {\r
16 Clazz.superConstructor (this, jalview.workers.ConservationThread, [alignViewport, alignPanel]);\r
17 this.ConsPercGaps = alignViewport.getConsPercGaps ();\r
18 }, "jalview.api.AlignViewportI,jalview.api.AlignmentViewPanel");\r
19 Clazz.overrideMethod (c$, "run1", \r
20 function (state) {\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 }var ourAnnot =  new java.util.ArrayList ();\r
49 this.alignment = this.alignViewport.getAlignment ();\r
50 this.conservation = this.alignViewport.getAlignmentConservationAnnotation ();\r
51 this.quality = this.alignViewport.getAlignmentQualityAnnot ();\r
52 ourAnnot.add (this.conservation);\r
53 ourAnnot.add (this.quality);\r
54 this.ourAnnots = ourAnnot;\r
55 this.ConsPercGaps = this.alignViewport.getConsPercGaps ();\r
56 if (this.alignment == null || (this.aWidth = this.alignment.getWidth ()) < 0) {\r
57 this.calcMan.workerComplete (this);\r
58 return;\r
59 }state = 4;\r
60 break;\r
61 case 4:\r
62 this.iFirst = this.iLast;\r
63 this.nPer = this.aWidth + 1;\r
64 this.iLast = Math.min (this.iLast + this.nPer, this.aWidth);\r
65 if (this.iLast == this.iFirst) {\r
66 state = 2;\r
67 } else {\r
68 this.computeConsensus ();\r
69 if (this.sleepAndReturn (0, state)) return;\r
70 }break;\r
71 case 2:\r
72 this.updateResultAnnotation (true);\r
73 this.notifyDone ();\r
74 return;\r
75 }\r
76 } catch (e$$) {\r
77 if (Clazz.exceptionOf (e$$, OutOfMemoryError)) {\r
78 var error = e$$;\r
79 {\r
80 this.calcMan.workerCannotRun (this);\r
81 this.ap.raiseOOMWarning ("calculating conservation", error);\r
82 }\r
83 } else {\r
84 var e = e$$;\r
85 {\r
86 System.out.println ("Error in ConsensusThread: " + e);\r
87 e.printStackTrace ();\r
88 this.calcMan.workerComplete (this);\r
89 }\r
90 }\r
91 }\r
92 }\r
93 }, "~N");\r
94 Clazz.defineMethod (c$, "computeConsensus", \r
95  function () {\r
96 this.cons = jalview.analysis.Conservation.calculateConservation ("All", jalview.schemes.ResidueProperties.propHash, 3, this.alignment.getSequences (), 0, this.aWidth - 1, false, this.ConsPercGaps, this.quality != null);\r
97 });\r
98 Clazz.defineMethod (c$, "updateResultAnnotation", \r
99  function (b) {\r
100 if (b || !this.calcMan.isWorking (this) && this.cons != null && this.conservation != null && this.quality != null) {\r
101 this.alignViewport.setConservation (this.cons);\r
102 this.cons.completeAnnotations (this.conservation, this.quality, 0, this.aWidth);\r
103 }}, "~B");\r
104 Clazz.overrideMethod (c$, "updateAnnotation", \r
105 function () {\r
106 this.updateResultAnnotation (false);\r
107 });\r
108 });\r