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