JAL-2403 ScoreModelI now DistanceModelI, ScoreMatrix delegate of
[jalview.git] / src / jalview / analysis / scoremodels / ScoreMatrix.java
index baa18e9..51d8276 100644 (file)
@@ -22,7 +22,7 @@ package jalview.analysis.scoremodels;
 
 import java.util.Arrays;
 
-public class ScoreMatrix extends PairwiseSeqScoreModel
+public class ScoreMatrix implements PairwiseScoreModelI
 {
   public static final short UNMAPPED = (short) -1;
 
@@ -141,25 +141,53 @@ public class ScoreMatrix extends PairwiseSeqScoreModel
     return peptide;
   }
 
-  @Override
+  /**
+   * Returns the score matrix as used in getPairwiseScore. If using this matrix
+   * directly, callers <em>must</em> also call <code>getMatrixIndex</code> in
+   * order to get the matrix index for each character (symbol).
+   * 
+   * @return
+   * @see #getMatrixIndex(char)
+   */
   public float[][] getMatrix()
   {
     return matrix;
   }
 
   /**
+   * Answers the matrix index for a given character, or -1 if unmapped in the
+   * matrix. Use this method only if using <code>getMatrix</code> in order to
+   * compute scores directly (without symbol lookup) for efficiency.
+   * 
+   * @param c
+   * @return
+   * @see #getMatrix()
+   */
+  public int getMatrixIndex(char c)
+  {
+    if (c < symbolIndex.length)
+    {
+      return symbolIndex[c];
+    }
+    else
+    {
+      return UNMAPPED;
+    }
+  }
+
+  /**
    * Returns the pairwise score for substituting c with d, or zero if c or d is
    * an unscored or unexpected character
    */
   @Override
   public float getPairwiseScore(char c, char d)
   {
-    if (c > MAX_ASCII)
+    if (c >= symbolIndex.length)
     {
       System.err.println(String.format(BAD_ASCII_ERROR, c));
       return 0;
     }
-    if (d > MAX_ASCII)
+    if (d >= symbolIndex.length)
     {
       System.err.println(String.format(BAD_ASCII_ERROR, d));
       return 0;