JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jalview / schemes / Consensus.js
1 Clazz.declarePackage ("jalview.schemes");\r
2 Clazz.load (null, "jalview.schemes.Consensus", ["jalview.schemes.ResidueProperties"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.mask = null;\r
5 this.threshold = 0;\r
6 this.maskstr = null;\r
7 Clazz.instantialize (this, arguments);\r
8 }, jalview.schemes, "Consensus");\r
9 Clazz.makeConstructor (c$, \r
10 function (mask, threshold) {\r
11 this.maskstr = mask;\r
12 this.setMask (mask);\r
13 this.threshold = threshold;\r
14 }, "~S,~N");\r
15 Clazz.defineMethod (c$, "setMask", \r
16 function (s) {\r
17 this.mask = this.setNums (s);\r
18 }, "~S");\r
19 Clazz.defineMethod (c$, "isConserved", \r
20 function (cons2, col, size) {\r
21 return this.isConserved (cons2, col, size, true);\r
22 }, "~A,~N,~N");\r
23 Clazz.defineMethod (c$, "isConserved", \r
24 function (cons2, col, size, includeGaps) {\r
25 var tot = 0;\r
26 if (!includeGaps) {\r
27 size -= cons2[col][cons2[col].length - 1];\r
28 }for (var i = 0; i < this.mask.length; i++) {\r
29 tot += cons2[col][this.mask[i]];\r
30 }\r
31 if (tot > ((this.threshold * size) / 100)) {\r
32 return true;\r
33 }return false;\r
34 }, "~A,~N,~N,~B");\r
35 Clazz.defineMethod (c$, "setNums", \r
36 function (s) {\r
37 var out =  Clazz.newIntArray (s.length, 0);\r
38 var i = 0;\r
39 while (i < s.length) {\r
40 out[i] = jalview.schemes.ResidueProperties.aaIndex[s.charCodeAt (i)];\r
41 i++;\r
42 }\r
43 return out;\r
44 }, "~S");\r
45 });\r