JAL-1807 test
[jalviewjs.git] / bin / jalview / analysis / PCA.js
index c9e885c..5effde0 100644 (file)
-Clazz.declarePackage ("jalview.analysis");\r
-Clazz.load (["java.lang.StringBuffer"], "jalview.analysis.PCA", ["jalview.datamodel.BinarySequence", "jalview.math.Matrix", "jalview.schemes.ResidueProperties"], function () {\r
-c$ = Clazz.decorateAsClass (function () {\r
-this.m = null;\r
-this.symm = null;\r
-this.m2 = null;\r
-this.eigenvalue = null;\r
-this.eigenvector = null;\r
-this.details = null;\r
-this.jvCalcMode = true;\r
-Clazz.instantialize (this, arguments);\r
-}, jalview.analysis, "PCA", null, Runnable);\r
-Clazz.prepareFields (c$, function () {\r
-this.details =  new StringBuffer ();\r
-});\r
-Clazz.makeConstructor (c$, \r
-function (s) {\r
-this.construct (s, false);\r
-}, "~A");\r
-Clazz.makeConstructor (c$, \r
-function (s, nucleotides) {\r
-this.construct (s, nucleotides, null);\r
-}, "~A,~B");\r
-Clazz.makeConstructor (c$, \r
-function (s, nucleotides, s_m) {\r
-var bs =  new Array (s.length);\r
-var ii = 0;\r
-while ((ii < s.length) && (s[ii] != null)) {\r
-bs[ii] =  new jalview.datamodel.BinarySequence (s[ii], nucleotides);\r
-bs[ii].encode ();\r
-ii++;\r
-}\r
-var bs2 =  new Array (s.length);\r
-ii = 0;\r
-var smtrx = null;\r
-var sm = s_m;\r
-if (sm != null) {\r
-smtrx = jalview.schemes.ResidueProperties.getScoreMatrix (sm);\r
-}if (smtrx == null) {\r
-smtrx = jalview.schemes.ResidueProperties.getScoreMatrix (sm = (nucleotides ? "DNA" : "BLOSUM62"));\r
-}this.details.append ("PCA calculation using " + sm + " sequence similarity matrix\n========\n\n");\r
-while ((ii < s.length) && (s[ii] != null)) {\r
-bs2[ii] =  new jalview.datamodel.BinarySequence (s[ii], nucleotides);\r
-if (smtrx != null) {\r
-try {\r
-bs2[ii].matrixEncode (smtrx);\r
-} catch (x) {\r
-if (Clazz.exceptionOf (x, jalview.datamodel.BinarySequence.InvalidSequenceTypeException)) {\r
-this.details.append ("Unexpected mismatch of sequence type and score matrix. Calculation will not be valid!\n\n");\r
-} else {\r
-throw x;\r
-}\r
-}\r
-}ii++;\r
-}\r
-var count = 0;\r
-while ((count < bs.length) && (bs[count] != null)) {\r
-count++;\r
-}\r
-var seqmat =  Clazz.newDoubleArray (count, bs[0].getDBinary ().length, 0);\r
-var seqmat2 =  Clazz.newDoubleArray (count, bs2[0].getDBinary ().length, 0);\r
-var i = 0;\r
-while (i < count) {\r
-seqmat[i] = bs[i].getDBinary ();\r
-seqmat2[i] = bs2[i].getDBinary ();\r
-i++;\r
-}\r
-this.m =  new jalview.math.Matrix (seqmat, count, bs[0].getDBinary ().length);\r
-this.m2 =  new jalview.math.Matrix (seqmat2, count, bs2[0].getDBinary ().length);\r
-}, "~A,~B,~S");\r
-Clazz.defineMethod (c$, "getM", \r
-function () {\r
-return this.m;\r
-});\r
-Clazz.defineMethod (c$, "getEigenvalue", \r
-function (i) {\r
-return this.eigenvector.d[i];\r
-}, "~N");\r
-Clazz.defineMethod (c$, "getComponents", \r
-function (l, n, mm, factor) {\r
-var out =  Clazz.newFloatArray (this.m.rows, 3, 0);\r
-for (var i = 0; i < this.m.rows; i++) {\r
-out[i][0] = this.component (i, l) * factor;\r
-out[i][1] = this.component (i, n) * factor;\r
-out[i][2] = this.component (i, mm) * factor;\r
-}\r
-return out;\r
-}, "~N,~N,~N,~N");\r
-Clazz.defineMethod (c$, "component", \r
-function (n) {\r
-var out =  Clazz.newDoubleArray (this.m.rows, 0);\r
-for (var i = 0; i < this.m.rows; i++) {\r
-out[i] = this.component (i, n);\r
-}\r
-return out;\r
-}, "~N");\r
-Clazz.defineMethod (c$, "component", \r
-function (row, n) {\r
-var out = 0.0;\r
-for (var i = 0; i < this.symm.cols; i++) {\r
-out += (this.symm.value[row][i] * this.eigenvector.value[i][n]);\r
-}\r
-return out / this.eigenvector.d[n];\r
-}, "~N,~N");\r
-Clazz.defineMethod (c$, "getDetails", \r
-function () {\r
-return this.details.toString ();\r
-});\r
-Clazz.overrideMethod (c$, "run", \r
-function () {\r
-var ps = ((Clazz.isClassDefined ("jalview.analysis.PCA$1") ? 0 : jalview.analysis.PCA.$PCA$1$ ()), Clazz.innerTypeInstance (jalview.analysis.PCA$1, this, null, System.out));\r
-try {\r
-this.details.append ("PCA Calculation Mode is " + (this.jvCalcMode ? "Jalview variant" : "Original SeqSpace") + "\n");\r
-var mt = this.m.transpose ();\r
-this.details.append (" --- OrigT * Orig ---- \n");\r
-if (!this.jvCalcMode) {\r
-this.eigenvector = mt.preMultiply (this.m);\r
-} else {\r
-this.eigenvector = mt.preMultiply (this.m2);\r
-}this.eigenvector.print (ps);\r
-this.symm = this.eigenvector.copy ();\r
-this.eigenvector.tred ();\r
-this.details.append (" ---Tridiag transform matrix ---\n");\r
-this.details.append (" --- D vector ---\n");\r
-this.eigenvector.printD (ps);\r
-ps.println ();\r
-this.details.append ("--- E vector ---\n");\r
-this.eigenvector.printE (ps);\r
-ps.println ();\r
-this.eigenvector.tqli ();\r
-} catch (q) {\r
-if (Clazz.exceptionOf (q, Exception)) {\r
-q.printStackTrace ();\r
-this.details.append ("\n*** Unexpected exception when performing PCA ***\n" + q.getLocalizedMessage ());\r
-this.details.append ("*** Matrices below may not be fully diagonalised. ***\n");\r
-} else {\r
-throw q;\r
-}\r
-}\r
-this.details.append (" --- New diagonalization matrix ---\n");\r
-this.eigenvector.print (ps);\r
-this.details.append (" --- Eigenvalues ---\n");\r
-this.eigenvector.printD (ps);\r
-ps.println ();\r
-});\r
-Clazz.defineMethod (c$, "setJvCalcMode", \r
-function (calcMode) {\r
-this.jvCalcMode = calcMode;\r
-}, "~B");\r
-c$.$PCA$1$ = function () {\r
-Clazz.pu$h ();\r
-c$ = Clazz.declareAnonymous (jalview.analysis, "PCA$1", java.io.PrintStream);\r
-Clazz.defineMethod (c$, "print", \r
-function (x) {\r
-this.b$["jalview.analysis.PCA"].details.append (x);\r
-}, "~S");\r
-Clazz.defineMethod (c$, "println", \r
-function () {\r
-this.b$["jalview.analysis.PCA"].details.append ("\n");\r
-});\r
-c$ = Clazz.p0p ();\r
-};\r
-});\r
+Clazz.declarePackage ("jalview.analysis");
+Clazz.load (["java.lang.StringBuffer"], "jalview.analysis.PCA", ["jalview.datamodel.BinarySequence", "jalview.math.Matrix", "jalview.schemes.ResidueProperties"], function () {
+c$ = Clazz.decorateAsClass (function () {
+this.m = null;
+this.symm = null;
+this.m2 = null;
+this.eigenvalue = null;
+this.eigenvector = null;
+this.details = null;
+this.jvCalcMode = true;
+Clazz.instantialize (this, arguments);
+}, jalview.analysis, "PCA", null, Runnable);
+Clazz.prepareFields (c$, function () {
+this.details =  new StringBuffer ();
+});
+Clazz.makeConstructor (c$, 
+function (s) {
+this.construct (s, false);
+}, "~A");
+Clazz.makeConstructor (c$, 
+function (s, nucleotides) {
+this.construct (s, nucleotides, null);
+}, "~A,~B");
+Clazz.makeConstructor (c$, 
+function (s, nucleotides, s_m) {
+var bs =  new Array (s.length);
+var ii = 0;
+while ((ii < s.length) && (s[ii] != null)) {
+bs[ii] =  new jalview.datamodel.BinarySequence (s[ii], nucleotides);
+bs[ii].encode ();
+ii++;
+}
+var bs2 =  new Array (s.length);
+ii = 0;
+var smtrx = null;
+var sm = s_m;
+if (sm != null) {
+smtrx = jalview.schemes.ResidueProperties.getScoreMatrix (sm);
+}if (smtrx == null) {
+smtrx = jalview.schemes.ResidueProperties.getScoreMatrix (sm = (nucleotides ? "DNA" : "BLOSUM62"));
+}this.details.append ("PCA calculation using " + sm + " sequence similarity matrix\n========\n\n");
+while ((ii < s.length) && (s[ii] != null)) {
+bs2[ii] =  new jalview.datamodel.BinarySequence (s[ii], nucleotides);
+if (smtrx != null) {
+try {
+bs2[ii].matrixEncode (smtrx);
+} catch (x) {
+if (Clazz.exceptionOf (x, jalview.datamodel.BinarySequence.InvalidSequenceTypeException)) {
+this.details.append ("Unexpected mismatch of sequence type and score matrix. Calculation will not be valid!\n\n");
+} else {
+throw x;
+}
+}
+}ii++;
+}
+var count = 0;
+while ((count < bs.length) && (bs[count] != null)) {
+count++;
+}
+var seqmat =  Clazz.newDoubleArray (count, bs[0].getDBinary ().length, 0);
+var seqmat2 =  Clazz.newDoubleArray (count, bs2[0].getDBinary ().length, 0);
+var i = 0;
+while (i < count) {
+seqmat[i] = bs[i].getDBinary ();
+seqmat2[i] = bs2[i].getDBinary ();
+i++;
+}
+this.m =  new jalview.math.Matrix (seqmat, count, bs[0].getDBinary ().length);
+this.m2 =  new jalview.math.Matrix (seqmat2, count, bs2[0].getDBinary ().length);
+}, "~A,~B,~S");
+Clazz.defineMethod (c$, "getM", 
+function () {
+return this.m;
+});
+Clazz.defineMethod (c$, "getEigenvalue", 
+function (i) {
+return this.eigenvector.d[i];
+}, "~N");
+Clazz.defineMethod (c$, "getComponents", 
+function (l, n, mm, factor) {
+var out =  Clazz.newFloatArray (this.m.rows, 3, 0);
+for (var i = 0; i < this.m.rows; i++) {
+out[i][0] = this.component (i, l) * factor;
+out[i][1] = this.component (i, n) * factor;
+out[i][2] = this.component (i, mm) * factor;
+}
+return out;
+}, "~N,~N,~N,~N");
+Clazz.defineMethod (c$, "component", 
+function (n) {
+var out =  Clazz.newDoubleArray (this.m.rows, 0);
+for (var i = 0; i < this.m.rows; i++) {
+out[i] = this.component (i, n);
+}
+return out;
+}, "~N");
+Clazz.defineMethod (c$, "component", 
+function (row, n) {
+var out = 0.0;
+for (var i = 0; i < this.symm.cols; i++) {
+out += (this.symm.value[row][i] * this.eigenvector.value[i][n]);
+}
+return out / this.eigenvector.d[n];
+}, "~N,~N");
+Clazz.defineMethod (c$, "getDetails", 
+function () {
+return this.details.toString ();
+});
+Clazz.overrideMethod (c$, "run", 
+function () {
+var ps = ((Clazz.isClassDefined ("jalview.analysis.PCA$1") ? 0 : jalview.analysis.PCA.$PCA$1$ ()), Clazz.innerTypeInstance (jalview.analysis.PCA$1, this, null, System.out));
+try {
+this.details.append ("PCA Calculation Mode is " + (this.jvCalcMode ? "Jalview variant" : "Original SeqSpace") + "\n");
+var mt = this.m.transpose ();
+this.details.append (" --- OrigT * Orig ---- \n");
+if (!this.jvCalcMode) {
+this.eigenvector = mt.preMultiply (this.m);
+} else {
+this.eigenvector = mt.preMultiply (this.m2);
+}this.eigenvector.print (ps);
+this.symm = this.eigenvector.copy ();
+this.eigenvector.tred ();
+this.details.append (" ---Tridiag transform matrix ---\n");
+this.details.append (" --- D vector ---\n");
+this.eigenvector.printD (ps);
+ps.println ();
+this.details.append ("--- E vector ---\n");
+this.eigenvector.printE (ps);
+ps.println ();
+this.eigenvector.tqli ();
+} catch (q) {
+if (Clazz.exceptionOf (q, Exception)) {
+q.printStackTrace ();
+this.details.append ("\n*** Unexpected exception when performing PCA ***\n" + q.getLocalizedMessage ());
+this.details.append ("*** Matrices below may not be fully diagonalised. ***\n");
+} else {
+throw q;
+}
+}
+this.details.append (" --- New diagonalization matrix ---\n");
+this.eigenvector.print (ps);
+this.details.append (" --- Eigenvalues ---\n");
+this.eigenvector.printD (ps);
+ps.println ();
+});
+Clazz.defineMethod (c$, "setJvCalcMode", 
+function (calcMode) {
+this.jvCalcMode = calcMode;
+}, "~B");
+c$.$PCA$1$ = function () {
+Clazz.pu$h ();
+c$ = Clazz.declareAnonymous (jalview.analysis, "PCA$1", java.io.PrintStream);
+Clazz.defineMethod (c$, "print", 
+function (x) {
+this.b$["jalview.analysis.PCA"].details.append (x);
+}, "~S");
+Clazz.defineMethod (c$, "println", 
+function () {
+this.b$["jalview.analysis.PCA"].details.append ("\n");
+});
+c$ = Clazz.p0p ();
+};
+});