JAL-2484 minor house-keeping
[jalview.git] / src / jalview / analysis / PCA.java
index 1a4060c..9babaee 100755 (executable)
@@ -20,7 +20,6 @@
  */
 package jalview.analysis;
 
-import jalview.math.Matrix;
 import jalview.math.MatrixI;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.ScoreMatrix;
@@ -77,17 +76,6 @@ public class PCA implements Runnable
   {
     this.seqs = s;
 
-    // BinarySequence[] bs = new BinarySequence[s.length];
-    // int ii = 0;
-    //
-    // while ((ii < s.length) && (s[ii] != null))
-    // {
-    // bs[ii] = new BinarySequence(s[ii], nucleotides);
-    // bs[ii].encode();
-    // ii++;
-    // }
-    //
-    // BinarySequence[] bs2 = new BinarySequence[s.length];
     scoreMatrix = null;
     String sm = s_m;
     if (sm != null)
@@ -103,47 +91,6 @@ public class PCA implements Runnable
     }
     details.append("PCA calculation using " + sm
             + " sequence similarity matrix\n========\n\n");
-    // ii = 0;
-    // while ((ii < s.length) && (s[ii] != null))
-    // {
-    // bs2[ii] = new BinarySequence(s[ii], nucleotides);
-    // if (scoreMatrix != null)
-    // {
-    // try
-    // {
-    // bs2[ii].matrixEncode(scoreMatrix);
-    // } catch (InvalidSequenceTypeException x)
-    // {
-    // details.append("Unexpected mismatch of sequence type and score matrix. Calculation will not be valid!\n\n");
-    // }
-    // }
-    // ii++;
-    // }
-    //
-    // int count = 0;
-    // while ((count < bs.length) && (bs[count] != null))
-    // {
-    // count++;
-    // }
-    //
-    // double[][] seqmat = new double[count][];
-    // double[][] seqmat2 = new double[count][];
-    //
-    // int i = 0;
-    // while (i < count)
-    // {
-    // seqmat[i] = bs[i].getDBinary();
-    // seqmat2[i] = bs2[i].getDBinary();
-    // i++;
-    // }
-    //
-    // /*
-    // * using a SparseMatrix to hold the encoded sequences matrix
-    // * greatly speeds up matrix multiplication as these are mostly zero
-    // */
-    // m = new SparseMatrix(seqmat);
-    // m2 = new Matrix(seqmat2);
-
   }
 
   /**
@@ -263,9 +210,7 @@ public class PCA implements Runnable
               + (jvCalcMode ? "Jalview variant" : "Original SeqSpace")
               + "\n");
 
-      // MatrixI mt = m.transpose();
-      // eigenvector = mt.preMultiply(jvCalcMode ? m2 : m);
-      eigenvector = computePairwiseScores();
+      eigenvector = scoreMatrix.computePairwiseScores(seqs);
 
       details.append(" --- OrigT * Orig ---- \n");
       eigenvector.print(ps, "%8.2f");
@@ -307,48 +252,6 @@ public class PCA implements Runnable
     // + (System.currentTimeMillis() - now) + "ms"));
   }
 
-  /**
-   * Computes an NxN matrix where N is the number of sequences, and entry [i, j]
-   * is sequence[i] pairwise multiplied with sequence[j], as a sum of scores
-   * computed using the current score matrix. For example
-   * <ul>
-   * <li>Sequences:</li>
-   * <li>FKL</li>
-   * <li>RSD</li>
-   * <li>QIA</li>
-   * <li>GWC</li>
-   * <li>Score matrix is BLOSUM62</li>
-   * <li>product [0, 0] = F.F + K.K + L.L = 6 + 5 + 4 = 15</li>
-   * <li>product [2, 1] = R.R + S.S + D.D = 5 + 4 + 6 = 15</li>
-   * <li>product [2, 2] = Q.Q + I.I + A.A = 5 + 4 + 4 = 13</li>
-   * <li>product [3, 3] = G.G + W.W + C.C = 6 + 11 + 9 = 26</li>
-   * <li>product[0, 1] = F.R + K.S + L.D = -3 + 0 + -3 = -7
-   * <li>and so on</li>
-   * </ul>
-   */
-  MatrixI computePairwiseScores()
-  {
-    double[][] values = new double[seqs.length][];
-    for (int row = 0; row < seqs.length; row++)
-    {
-      values[row] = new double[seqs.length];
-      for (int col = 0; col < seqs.length; col++)
-      {
-        int total = 0;
-        int width = Math.min(seqs[row].length(), seqs[col].length());
-        for (int i = 0; i < width; i++)
-        {
-          char c1 = seqs[row].charAt(i);
-          char c2 = seqs[col].charAt(i);
-          int score = scoreMatrix.getPairwiseScore(c1, c2);
-          total += score;
-        }
-        values[row][col] = total;
-      }
-    }
-    return new Matrix(values);
-  }
-
   public void setJvCalcMode(boolean calcMode)
   {
     this.jvCalcMode = calcMode;