JAL-2839 refactored out getNextVisibleSequenceRegion
[jalview.git] / src / jalview / analysis / PCA.java
index 11c73c1..42a168d 100755 (executable)
  */
 package jalview.analysis;
 
-import jalview.analysis.scoremodels.PIDModel;
-import jalview.api.analysis.DistanceScoreModelI;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
-import jalview.api.analysis.SimilarityScoreModelI;
 import jalview.datamodel.AlignmentView;
 import jalview.math.MatrixI;
 
@@ -43,10 +40,10 @@ public class PCA implements Runnable
 
   StringBuilder details = new StringBuilder(1024);
 
-  private AlignmentView seqs;
+  final private AlignmentView seqs;
 
   private ScoreModelI scoreModel;
-  
+
   private SimilarityParamsI similarityParams;
 
   public PCA(AlignmentView s, ScoreModelI sm, SimilarityParamsI options)
@@ -54,7 +51,7 @@ public class PCA implements Runnable
     this.seqs = s;
     this.similarityParams = options;
     this.scoreModel = sm;
-    
+
     details.append("PCA calculation using " + sm.getName()
             + " sequence similarity matrix\n========\n\n");
   }
@@ -172,7 +169,7 @@ public class PCA implements Runnable
     // long now = System.currentTimeMillis();
     try
     {
-      eigenvector = computeSimilarity(seqs);
+      eigenvector = scoreModel.findSimilarities(seqs, similarityParams);
 
       details.append(" --- OrigT * Orig ---- \n");
       eigenvector.print(ps, "%8.2f");
@@ -196,7 +193,8 @@ public class PCA implements Runnable
       q.printStackTrace();
       details.append("\n*** Unexpected exception when performing PCA ***\n"
               + q.getLocalizedMessage());
-      details.append("*** Matrices below may not be fully diagonalised. ***\n");
+      details.append(
+              "*** Matrices below may not be fully diagonalised. ***\n");
     }
 
     details.append(" --- New diagonalization matrix ---\n");
@@ -215,50 +213,6 @@ public class PCA implements Runnable
   }
 
   /**
-   * Computes a pairwise similarity matrix for the given sequence regions using
-   * the configured score model. If the score model is a similarity model, then
-   * it computes the result directly. If it is a distance model, then use it to
-   * compute pairwise distances, and convert these to similarity scores.
-   * 
-   * @param av
-   * @return
-   */
-  MatrixI computeSimilarity(AlignmentView av)
-  {
-    MatrixI result = null;
-    if (scoreModel instanceof SimilarityScoreModelI)
-    {
-      result = ((SimilarityScoreModelI) scoreModel).findSimilarities(av,
-              similarityParams);
-      if (scoreModel instanceof PIDModel)
-      {
-        /*
-         * scale % identities to width of alignment for backwards
-         * compatibility with Jalview 2.10.1 SeqSpace PCA calculation 
-         */
-        result.multiply(av.getWidth() / 100d);
-      }
-    }
-    else if (scoreModel instanceof DistanceScoreModelI)
-    {
-      /*
-       * find distances and convert to similarity scores
-       * reverseRange(false) preserves but reverses the min-max range
-       */
-      result = ((DistanceScoreModelI) scoreModel).findDistances(av,
-              similarityParams);
-      result.reverseRange(false);
-    }
-    else
-    {
-      System.err
-              .println("Unexpected type of score model, cannot calculate similarity");
-    }
-
-    return result;
-  }
-
-  /**
    * Answers the N dimensions of the NxN PCA matrix. This is the number of
    * sequences involved in the pairwise score calculation.
    *