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