1 Clazz.declarePackage ("jalview.analysis");
\r
2 Clazz.load (["java.lang.StringBuffer"], "jalview.analysis.PCA", ["jalview.datamodel.BinarySequence", "jalview.math.Matrix", "jalview.schemes.ResidueProperties"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
7 this.eigenvalue = null;
\r
8 this.eigenvector = null;
\r
10 this.jvCalcMode = true;
\r
11 Clazz.instantialize (this, arguments);
\r
12 }, jalview.analysis, "PCA", null, Runnable);
\r
13 Clazz.prepareFields (c$, function () {
\r
14 this.details = new StringBuffer ();
\r
16 Clazz.makeConstructor (c$,
\r
18 this.construct (s, false);
\r
20 Clazz.makeConstructor (c$,
\r
21 function (s, nucleotides) {
\r
22 this.construct (s, nucleotides, null);
\r
24 Clazz.makeConstructor (c$,
\r
25 function (s, nucleotides, s_m) {
\r
26 var bs = new Array (s.length);
\r
28 while ((ii < s.length) && (s[ii] != null)) {
\r
29 bs[ii] = new jalview.datamodel.BinarySequence (s[ii], nucleotides);
\r
33 var bs2 = new Array (s.length);
\r
38 smtrx = jalview.schemes.ResidueProperties.getScoreMatrix (sm);
\r
39 }if (smtrx == null) {
\r
40 smtrx = jalview.schemes.ResidueProperties.getScoreMatrix (sm = (nucleotides ? "DNA" : "BLOSUM62"));
\r
41 }this.details.append ("PCA calculation using " + sm + " sequence similarity matrix\n========\n\n");
\r
42 while ((ii < s.length) && (s[ii] != null)) {
\r
43 bs2[ii] = new jalview.datamodel.BinarySequence (s[ii], nucleotides);
\r
44 if (smtrx != null) {
\r
46 bs2[ii].matrixEncode (smtrx);
\r
48 if (Clazz.exceptionOf (x, jalview.datamodel.BinarySequence.InvalidSequenceTypeException)) {
\r
49 this.details.append ("Unexpected mismatch of sequence type and score matrix. Calculation will not be valid!\n\n");
\r
57 while ((count < bs.length) && (bs[count] != null)) {
\r
60 var seqmat = Clazz.newDoubleArray (count, bs[0].getDBinary ().length, 0);
\r
61 var seqmat2 = Clazz.newDoubleArray (count, bs2[0].getDBinary ().length, 0);
\r
64 seqmat[i] = bs[i].getDBinary ();
\r
65 seqmat2[i] = bs2[i].getDBinary ();
\r
68 this.m = new jalview.math.Matrix (seqmat, count, bs[0].getDBinary ().length);
\r
69 this.m2 = new jalview.math.Matrix (seqmat2, count, bs2[0].getDBinary ().length);
\r
71 Clazz.defineMethod (c$, "getM",
\r
75 Clazz.defineMethod (c$, "getEigenvalue",
\r
77 return this.eigenvector.d[i];
\r
79 Clazz.defineMethod (c$, "getComponents",
\r
80 function (l, n, mm, factor) {
\r
81 var out = Clazz.newFloatArray (this.m.rows, 3, 0);
\r
82 for (var i = 0; i < this.m.rows; i++) {
\r
83 out[i][0] = this.component (i, l) * factor;
\r
84 out[i][1] = this.component (i, n) * factor;
\r
85 out[i][2] = this.component (i, mm) * factor;
\r
89 Clazz.defineMethod (c$, "component",
\r
91 var out = Clazz.newDoubleArray (this.m.rows, 0);
\r
92 for (var i = 0; i < this.m.rows; i++) {
\r
93 out[i] = this.component (i, n);
\r
97 Clazz.defineMethod (c$, "component",
\r
100 for (var i = 0; i < this.symm.cols; i++) {
\r
101 out += (this.symm.value[row][i] * this.eigenvector.value[i][n]);
\r
103 return out / this.eigenvector.d[n];
\r
105 Clazz.defineMethod (c$, "getDetails",
\r
107 return this.details.toString ();
\r
109 Clazz.overrideMethod (c$, "run",
\r
111 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
113 this.details.append ("PCA Calculation Mode is " + (this.jvCalcMode ? "Jalview variant" : "Original SeqSpace") + "\n");
\r
114 var mt = this.m.transpose ();
\r
115 this.details.append (" --- OrigT * Orig ---- \n");
\r
116 if (!this.jvCalcMode) {
\r
117 this.eigenvector = mt.preMultiply (this.m);
\r
119 this.eigenvector = mt.preMultiply (this.m2);
\r
120 }this.eigenvector.print (ps);
\r
121 this.symm = this.eigenvector.copy ();
\r
122 this.eigenvector.tred ();
\r
123 this.details.append (" ---Tridiag transform matrix ---\n");
\r
124 this.details.append (" --- D vector ---\n");
\r
125 this.eigenvector.printD (ps);
\r
127 this.details.append ("--- E vector ---\n");
\r
128 this.eigenvector.printE (ps);
\r
130 this.eigenvector.tqli ();
\r
132 if (Clazz.exceptionOf (q, Exception)) {
\r
133 q.printStackTrace ();
\r
134 this.details.append ("\n*** Unexpected exception when performing PCA ***\n" + q.getLocalizedMessage ());
\r
135 this.details.append ("*** Matrices below may not be fully diagonalised. ***\n");
\r
140 this.details.append (" --- New diagonalization matrix ---\n");
\r
141 this.eigenvector.print (ps);
\r
142 this.details.append (" --- Eigenvalues ---\n");
\r
143 this.eigenvector.printD (ps);
\r
146 Clazz.defineMethod (c$, "setJvCalcMode",
\r
147 function (calcMode) {
\r
148 this.jvCalcMode = calcMode;
\r
150 c$.$PCA$1$ = function () {
\r
152 c$ = Clazz.declareAnonymous (jalview.analysis, "PCA$1", java.io.PrintStream);
\r
153 Clazz.defineMethod (c$, "print",
\r
155 this.b$["jalview.analysis.PCA"].details.append (x);
\r
157 Clazz.defineMethod (c$, "println",
\r
159 this.b$["jalview.analysis.PCA"].details.append ("\n");
\r