1 Clazz.declarePackage ("jalview.workers");
2 Clazz.load (["jalview.api.AlignCalcWorkerI", "jalview.workers.AlignCalcWorker"], "jalview.workers.ConsensusThread", ["jalview.analysis.AAFrequency"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.hconsensus = null;
6 Clazz.instantialize (this, arguments);
7 }, jalview.workers, "ConsensusThread", jalview.workers.AlignCalcWorker, jalview.api.AlignCalcWorkerI);
8 Clazz.overrideMethod (c$, "getNewWorker",
10 return new jalview.workers.ConsensusThread (this.alignViewport, this.ap);
12 Clazz.overrideMethod (c$, "run1",
14 while (!Thread.interrupted ()) {
15 if (this.alignViewport.isClosed ()) {
16 this.abortAndDestroy ();
21 if (this.calcMan.isPending (this)) return;
22 this.calcMan.notifyStart (this);
23 var consensus = this.getConsensusAnnotation ();
24 if (consensus == null || this.calcMan.isPending (this)) {
25 this.calcMan.workerComplete (this);
30 while (!this.calcMan.notifyWorking (this)) {
31 if (this.ap != null) {
32 this.ap.paintAlignment (false);
34 if (this.sleepAndReturn (200, state)) return;
36 if (Clazz.exceptionOf (e, InterruptedException)) {
44 if (this.alignViewport.isClosed ()) {
45 this.abortAndDestroy ();
48 }this.alignment = this.alignViewport.getAlignment ();
50 if (this.alignment == null || (this.aWidth = this.alignment.getWidth ()) < 0) {
52 }this.eraseConsensus (this.aWidth);
53 state = (this.initializeCalc () ? 4 : 2);
56 this.iFirst = this.iLast;
57 this.iLast = Math.min (this.iLast + this.nPer, this.aWidth);
58 if (this.iLast == this.iFirst) {
61 this.computeConsensus ();
62 if (this.sleepAndReturn (0, state)) return;
66 this.updateAlignment ();
71 if (Clazz.exceptionOf (e$$, OutOfMemoryError)) {
74 this.calcMan.workerCannotRun (this);
75 this.ap.raiseOOMWarning ("calculating consensus", error);
80 System.out.println ("Error in ConsensusThread: " + e);
82 this.calcMan.workerComplete (this);
88 Clazz.defineMethod (c$, "initializeCalc",
91 this.hconsensus = new Array (this.aWidth);
92 this.aseqs = this.getSequences ();
95 Clazz.defineMethod (c$, "computeConsensus",
97 this.started = System.currentTimeMillis ();
98 jalview.analysis.AAFrequency.calculate (this.aseqs, this.iFirst, this.iLast, this.hconsensus, true);
99 if (System.currentTimeMillis () - this.started < 500) this.nPer *= 2;
101 Clazz.defineMethod (c$, "finalizeCalc",
103 this.alignViewport.setSequenceConsensusHash (this.hconsensus);
105 Clazz.defineMethod (c$, "updateAlignment",
107 this.setColourSchemeConsensus (this.hconsensus);
108 this.updateResultAnnotation (true);
110 Clazz.defineMethod (c$, "eraseConsensus",
112 var consensus = this.getConsensusAnnotation ();
113 consensus.annotations = new Array (aWidth);
115 Clazz.defineMethod (c$, "getSequences",
117 return this.alignViewport.getAlignment ().getSequencesArray ();
119 Clazz.defineMethod (c$, "setColourSchemeConsensus",
120 function (hconsensus) {
121 var globalColourScheme = this.alignViewport.getGlobalColourScheme ();
122 if (globalColourScheme != null) {
123 globalColourScheme.setConsensus (hconsensus);
125 Clazz.defineMethod (c$, "getConsensusAnnotation",
127 return this.alignViewport.getAlignmentConsensusAnnotation ();
129 Clazz.overrideMethod (c$, "updateAnnotation",
131 this.updateResultAnnotation (false);
133 Clazz.defineMethod (c$, "updateResultAnnotation",
134 function (immediate) {
135 var consensus = this.getConsensusAnnotation ();
136 var hconsensus = this.getViewportConsensus ();
137 if (immediate || !this.calcMan.isWorking (this) && consensus != null && hconsensus != null) {
138 this.deriveConsensus (consensus, hconsensus);
140 Clazz.defineMethod (c$, "deriveConsensus",
141 function (consensusAnnotation, consensusData) {
142 var nseq = this.getSequences ().length;
143 jalview.analysis.AAFrequency.completeConsensus (consensusAnnotation, consensusData, 0, consensusData.length, this.alignViewport.isIgnoreGapsConsensus (), this.alignViewport.isShowSequenceLogo (), nseq);
144 }, "jalview.datamodel.AlignmentAnnotation,~A");
145 Clazz.defineMethod (c$, "getViewportConsensus",
147 return this.alignViewport.getSequenceConsensusHash ();