JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jalview / datamodel / BinarySequence.js
1 Clazz.declarePackage ("jalview.datamodel");\r
2 Clazz.load (["jalview.datamodel.Sequence", "java.lang.Exception"], "jalview.datamodel.BinarySequence", ["jalview.schemes.ResidueProperties"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 if (!Clazz.isClassDefined ("jalview.datamodel.BinarySequence.InvalidSequenceTypeException")) {\r
5 jalview.datamodel.BinarySequence.$BinarySequence$InvalidSequenceTypeException$ ();\r
6 }\r
7 this.binary = null;\r
8 this.dbinary = null;\r
9 this.isNa = false;\r
10 Clazz.instantialize (this, arguments);\r
11 }, jalview.datamodel, "BinarySequence", jalview.datamodel.Sequence);\r
12 Clazz.makeConstructor (c$, \r
13 function (s, isNa) {\r
14 Clazz.superConstructor (this, jalview.datamodel.BinarySequence, ["", s, 0, s.length]);\r
15 this.isNa = isNa;\r
16 }, "~S,~B");\r
17 Clazz.defineMethod (c$, "initMatrixGetNoRes", \r
18  function () {\r
19 var nores = (this.isNa) ? 10 : 23;\r
20 this.dbinary =  Clazz.newDoubleArray (this.getSequence ().length * nores, 0);\r
21 for (var i = 0; i < this.dbinary.length; i++) {\r
22 this.dbinary[i] = 0.0;\r
23 }\r
24 return nores;\r
25 });\r
26 Clazz.defineMethod (c$, "getSymbolmatrix", \r
27  function () {\r
28 return (this.isNa) ? jalview.schemes.ResidueProperties.nucleotideIndex : jalview.schemes.ResidueProperties.aaIndex;\r
29 });\r
30 Clazz.defineMethod (c$, "encode", \r
31 function () {\r
32 var nores = this.initMatrixGetNoRes ();\r
33 var sindex = this.getSymbolmatrix ();\r
34 for (var i = 0; i < this.getSequence ().length; i++) {\r
35 var aanum = nores - 1;\r
36 try {\r
37 aanum = sindex[this.getCharAt (i).charCodeAt (0)];\r
38 } catch (e) {\r
39 if (Clazz.exceptionOf (e, NullPointerException)) {\r
40 aanum = nores - 1;\r
41 } else {\r
42 throw e;\r
43 }\r
44 }\r
45 if (aanum >= nores) {\r
46 aanum = nores - 1;\r
47 }this.dbinary[(i * nores) + aanum] = 1.0;\r
48 }\r
49 });\r
50 Clazz.defineMethod (c$, "matrixEncode", \r
51 function (matrix) {\r
52 if (this.isNa != matrix.isDNA ()) {\r
53 throw Clazz.innerTypeInstance (jalview.datamodel.BinarySequence.InvalidSequenceTypeException, this, null, "matrix " + matrix.getClass ().getCanonicalName () + " is not a valid matrix for " + (this.isNa ? "nucleotide" : "protein") + "sequences");\r
54 }this.matrixEncode (matrix.isDNA () ? jalview.schemes.ResidueProperties.nucleotideIndex : jalview.schemes.ResidueProperties.aaIndex, matrix.getMatrix ());\r
55 }, "jalview.schemes.ScoreMatrix");\r
56 Clazz.defineMethod (c$, "matrixEncode", \r
57  function (aaIndex, matrix) {\r
58 var nores = this.initMatrixGetNoRes ();\r
59 for (var i = 0, iSize = this.getSequence ().length; i < iSize; i++) {\r
60 var aanum = nores - 1;\r
61 try {\r
62 aanum = aaIndex[this.getCharAt (i).charCodeAt (0)];\r
63 } catch (e) {\r
64 if (Clazz.exceptionOf (e, NullPointerException)) {\r
65 aanum = nores - 1;\r
66 } else {\r
67 throw e;\r
68 }\r
69 }\r
70 if (aanum >= nores) {\r
71 aanum = nores - 1;\r
72 }for (var j = 0; j < nores; j++) {\r
73 this.dbinary[(i * nores) + j] = matrix[aanum][j];\r
74 }\r
75 }\r
76 }, "~A,~A");\r
77 Clazz.defineMethod (c$, "toBinaryString", \r
78 function () {\r
79 var out = "";\r
80 for (var i = 0; i < this.binary.length; i++) {\r
81 out += ( new Integer (this.binary[i])).toString ();\r
82 if (i < (this.binary.length - 1)) {\r
83 out += " ";\r
84 }}\r
85 return out;\r
86 });\r
87 Clazz.defineMethod (c$, "getDBinary", \r
88 function () {\r
89 return this.dbinary;\r
90 });\r
91 c$.$BinarySequence$InvalidSequenceTypeException$ = function () {\r
92 Clazz.pu$h(self.c$);\r
93 c$ = Clazz.decorateAsClass (function () {\r
94 Clazz.prepareCallback (this, arguments);\r
95 Clazz.instantialize (this, arguments);\r
96 }, jalview.datamodel.BinarySequence, "InvalidSequenceTypeException", Exception);\r
97 c$ = Clazz.p0p ();\r
98 };\r
99 });\r