adab626bf98deac38c04470884d822a1ee1e8ff2
[jalview.git] / ConsensusThread.js
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", 
5 function () {
6 if (this.calcMan.isPending (this)) {
7 return;
8 }this.calcMan.notifyStart (this);
9 var started = System.currentTimeMillis ();
10 try {
11 var consensus = this.getConsensusAnnotation ();
12 if (consensus == null || this.calcMan.isPending (this)) {
13 this.calcMan.workerComplete (this);
14 return;
15 }while (!this.calcMan.notifyWorking (this)) {
16 try {
17 if (this.ap != null) {
18 this.ap.paintAlignment (false);
19 }Thread.sleep (200);
20 } catch (ex) {
21 if (Clazz.exceptionOf (ex, Exception)) {
22 ex.printStackTrace ();
23 } else {
24 throw ex;
25 }
26 }
27 }
28 if (this.alignViewport.isClosed ()) {
29 this.abortAndDestroy ();
30 return;
31 }var alignment = this.alignViewport.getAlignment ();
32 var aWidth = -1;
33 if (alignment == null || (aWidth = alignment.getWidth ()) < 0) {
34 this.calcMan.workerComplete (this);
35 return;
36 }this.eraseConsensus (aWidth);
37 this.computeConsensus (alignment);
38 this.updateResultAnnotation (true);
39 if (this.ap != null) {
40 this.ap.paintAlignment (true);
41 }} catch (error) {
42 if (Clazz.exceptionOf (error, OutOfMemoryError)) {
43 this.calcMan.workerCannotRun (this);
44 this.ap.raiseOOMWarning ("calculating consensus", error);
45 } else {
46 throw error;
47 }
48 } finally {
49 this.calcMan.workerComplete (this);
50 }
51 });
52 Clazz.defineMethod (c$, "eraseConsensus", 
53 function (aWidth) {
54 var consensus = this.getConsensusAnnotation ();
55 consensus.annotations =  new Array (aWidth);
56 }, "~N");
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", 
66 function () {
67 return this.alignViewport.getAlignment ().getSequencesArray ();
68 });
69 Clazz.defineMethod (c$, "setColourSchemeConsensus", 
70 function (hconsensus) {
71 var globalColourScheme = this.alignViewport.getGlobalColourScheme ();
72 if (globalColourScheme != null) {
73 globalColourScheme.setConsensus (hconsensus);
74 }}, "~A");
75 Clazz.defineMethod (c$, "getConsensusAnnotation", 
76 function () {
77 return this.alignViewport.getAlignmentConsensusAnnotation ();
78 });
79 Clazz.overrideMethod (c$, "updateAnnotation", 
80 function () {
81 this.updateResultAnnotation (false);
82 });
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);
89 }}, "~B");
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", 
96 function () {
97 return this.alignViewport.getSequenceConsensusHash ();
98 });
99 });