1 Clazz.declarePackage ("jalview.workers");
2 Clazz.load (["jalview.api.AlignCalcWorkerI", "jalview.workers.AlignCalcWorker"], "jalview.workers.ConsensusThread", ["jalview.analysis.AAFrequency", "java.lang.Thread"], function () {
3 c$ = Clazz.declareType (jalview.workers, "ConsensusThread", jalview.workers.AlignCalcWorker, jalview.api.AlignCalcWorkerI);
4 Clazz.overrideMethod (c$, "run",
6 if (this.calcMan.isPending (this)) {
8 }this.calcMan.notifyStart (this);
9 var started = System.currentTimeMillis ();
11 var consensus = this.getConsensusAnnotation ();
12 if (consensus == null || this.calcMan.isPending (this)) {
13 this.calcMan.workerComplete (this);
15 }while (!this.calcMan.notifyWorking (this)) {
17 if (this.ap != null) {
18 this.ap.paintAlignment (false);
21 if (Clazz.exceptionOf (ex, Exception)) {
22 ex.printStackTrace ();
28 if (this.alignViewport.isClosed ()) {
29 this.abortAndDestroy ();
31 }var alignment = this.alignViewport.getAlignment ();
33 if (alignment == null || (aWidth = alignment.getWidth ()) < 0) {
34 this.calcMan.workerComplete (this);
36 }this.eraseConsensus (aWidth);
37 this.computeConsensus (alignment);
38 this.updateResultAnnotation (true);
39 if (this.ap != null) {
40 this.ap.paintAlignment (true);
42 if (Clazz.exceptionOf (error, OutOfMemoryError)) {
43 this.calcMan.workerCannotRun (this);
44 this.ap.raiseOOMWarning ("calculating consensus", error);
49 this.calcMan.workerComplete (this);
52 Clazz.defineMethod (c$, "eraseConsensus",
54 var consensus = this.getConsensusAnnotation ();
55 consensus.annotations = new Array (aWidth);
57 Clazz.defineMethod (c$, "computeConsensus",
58 function (alignment) {
59 var hconsensus = new Array (alignment.getWidth ());
60 var aseqs = this.getSequences ();
61 jalview.analysis.AAFrequency.calculate (aseqs, 0, alignment.getWidth (), hconsensus, true);
62 this.alignViewport.setSequenceConsensusHash (hconsensus);
63 this.setColourSchemeConsensus (hconsensus);
64 }, "jalview.datamodel.AlignmentI");
65 Clazz.defineMethod (c$, "getSequences",
67 return this.alignViewport.getAlignment ().getSequencesArray ();
69 Clazz.defineMethod (c$, "setColourSchemeConsensus",
70 function (hconsensus) {
71 var globalColourScheme = this.alignViewport.getGlobalColourScheme ();
72 if (globalColourScheme != null) {
73 globalColourScheme.setConsensus (hconsensus);
75 Clazz.defineMethod (c$, "getConsensusAnnotation",
77 return this.alignViewport.getAlignmentConsensusAnnotation ();
79 Clazz.overrideMethod (c$, "updateAnnotation",
81 this.updateResultAnnotation (false);
83 Clazz.defineMethod (c$, "updateResultAnnotation",
84 function (immediate) {
85 var consensus = this.getConsensusAnnotation ();
86 var hconsensus = this.getViewportConsensus ();
87 if (immediate || !this.calcMan.isWorking (this) && consensus != null && hconsensus != null) {
88 this.deriveConsensus (consensus, hconsensus);
90 Clazz.defineMethod (c$, "deriveConsensus",
91 function (consensusAnnotation, consensusData) {
92 var nseq = this.getSequences ().length;
93 jalview.analysis.AAFrequency.completeConsensus (consensusAnnotation, consensusData, 0, consensusData.length, this.alignViewport.isIgnoreGapsConsensus (), this.alignViewport.isShowSequenceLogo (), nseq);
94 }, "jalview.datamodel.AlignmentAnnotation,~A");
95 Clazz.defineMethod (c$, "getViewportConsensus",
97 return this.alignViewport.getSequenceConsensusHash ();