JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / workers / StrucConsensusThread.js
1 Clazz.declarePackage ("jalview.workers");\r
2 Clazz.load (["jalview.api.AlignCalcWorkerI", "jalview.workers.AlignCalcWorker"], "jalview.workers.StrucConsensusThread", ["jalview.analysis.StructureFrequency", "java.lang.Thread"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.strucConsensus = null;\r
5 this.hStrucConsensus = null;\r
6 this.nseq = -1;\r
7 Clazz.instantialize (this, arguments);\r
8 }, jalview.workers, "StrucConsensusThread", jalview.workers.AlignCalcWorker, jalview.api.AlignCalcWorkerI);\r
9 Clazz.overrideMethod (c$, "getNewWorker", \r
10 function () {\r
11 return  new jalview.workers.StrucConsensusThread (this.alignViewport, this.ap);\r
12 });\r
13 Clazz.overrideMethod (c$, "run", \r
14 function () {\r
15 try {\r
16 if (this.calcMan.isPending (this)) {\r
17 return;\r
18 }this.calcMan.notifyStart (this);\r
19 while (!this.calcMan.notifyWorking (this)) {\r
20 try {\r
21 if (this.ap != null) {\r
22 }Thread.sleep (200);\r
23 } catch (ex) {\r
24 if (Clazz.exceptionOf (ex, Exception)) {\r
25 ex.printStackTrace ();\r
26 } else {\r
27 throw ex;\r
28 }\r
29 }\r
30 }\r
31 if (this.alignViewport.isClosed ()) {\r
32 this.abortAndDestroy ();\r
33 return;\r
34 }var alignment = this.alignViewport.getAlignment ();\r
35 var aWidth = -1;\r
36 if (alignment == null || (aWidth = alignment.getWidth ()) < 0) {\r
37 this.calcMan.workerComplete (this);\r
38 return;\r
39 }this.strucConsensus = this.alignViewport.getAlignmentStrucConsensusAnnotation ();\r
40 this.hStrucConsensus = this.alignViewport.getRnaStructureConsensusHash ();\r
41 this.strucConsensus.annotations = null;\r
42 this.strucConsensus.annotations =  new Array (aWidth);\r
43 this.hStrucConsensus =  new Array (aWidth);\r
44 var aa = this.alignViewport.getAlignment ().getAlignmentAnnotation ();\r
45 var rnaStruc = null;\r
46 for (var i = 0; i < aa.length; i++) {\r
47 if (aa[i].getRNAStruc () != null && aa[i].isValidStruc ()) {\r
48 rnaStruc = aa[i];\r
49 break;\r
50 }}\r
51 if (rnaStruc == null || !rnaStruc.isValidStruc ()) {\r
52 this.calcMan.workerComplete (this);\r
53 return;\r
54 }try {\r
55 var arr = alignment.getSequencesArray ();\r
56 this.nseq = arr.length;\r
57 jalview.analysis.StructureFrequency.calculate (arr, 0, alignment.getWidth (), this.hStrucConsensus, true, rnaStruc);\r
58 } catch (x) {\r
59 if (Clazz.exceptionOf (x, ArrayIndexOutOfBoundsException)) {\r
60 this.calcMan.workerComplete (this);\r
61 return;\r
62 } else {\r
63 throw x;\r
64 }\r
65 }\r
66 this.alignViewport.setRnaStructureConsensusHash (this.hStrucConsensus);\r
67 this.updateResultAnnotation (true);\r
68 if (this.alignViewport.getGlobalColourScheme () != null) {\r
69 this.alignViewport.getGlobalColourScheme ().setConsensus (this.hStrucConsensus);\r
70 }} catch (error) {\r
71 if (Clazz.exceptionOf (error, OutOfMemoryError)) {\r
72 this.calcMan.workerCannotRun (this);\r
73 this.ap.raiseOOMWarning ("calculating RNA structure consensus", error);\r
74 } else {\r
75 throw error;\r
76 }\r
77 } finally {\r
78 this.calcMan.workerComplete (this);\r
79 if (this.ap != null) {\r
80 this.ap.paintAlignment (true);\r
81 }}\r
82 });\r
83 Clazz.overrideMethod (c$, "updateAnnotation", \r
84 function () {\r
85 this.updateResultAnnotation (false);\r
86 });\r
87 Clazz.defineMethod (c$, "updateResultAnnotation", \r
88 function (immediate) {\r
89 if (immediate || !this.calcMan.isWorking (this) && this.strucConsensus != null && this.hStrucConsensus != null) {\r
90 jalview.analysis.StructureFrequency.completeConsensus (this.strucConsensus, this.hStrucConsensus, 0, this.hStrucConsensus.length, this.alignViewport.isIgnoreGapsConsensus (), this.alignViewport.isShowSequenceLogo (), this.nseq);\r
91 }}, "~B");\r
92 Clazz.overrideMethod (c$, "run1", \r
93 function (state) {\r
94 }, "~N");\r
95 });\r