X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fanalysis%2Fscoremodels%2FScoreMatrix.java;h=7f71d0fc7858dfdf5d9c9c64876727a482276a61;hb=993b6a26f415bf05ce6dce0b93e96eaf95733d4b;hp=eb94817f4d441f322bc7df25145a78a2a41eacfe;hpb=7c5c70f4bbe69a722dd6e8bd269d7d01e1089034;p=jalview.git
diff --git a/src/jalview/analysis/scoremodels/ScoreMatrix.java b/src/jalview/analysis/scoremodels/ScoreMatrix.java
index eb94817..7f71d0f 100644
--- a/src/jalview/analysis/scoremodels/ScoreMatrix.java
+++ b/src/jalview/analysis/scoremodels/ScoreMatrix.java
@@ -20,10 +20,25 @@
*/
package jalview.analysis.scoremodels;
+import jalview.api.analysis.PairwiseScoreModelI;
+import jalview.api.analysis.SimilarityScoreModelI;
+import jalview.datamodel.AlignmentView;
+import jalview.math.Matrix;
+import jalview.math.MatrixI;
+
import java.util.Arrays;
-public class ScoreMatrix implements PairwiseScoreModelI
+public class ScoreMatrix implements SimilarityScoreModelI,
+ PairwiseScoreModelI
{
+ /*
+ * Jalview 2.10.1 treated gaps as X (peptide) or N (nucleotide)
+ * for pairwise scoring; 2.10.2 uses gap score (last column) in
+ * score matrix (JAL-2397)
+ * Set this flag to true (via Groovy) for 2.10.1 behaviour
+ */
+ private static boolean scoreGapAsAny = false;
+
public static final short UNMAPPED = (short) -1;
private static final String BAD_ASCII_ERROR = "Unexpected character %s in getPairwiseScore";
@@ -158,16 +173,22 @@ public class ScoreMatrix implements PairwiseScoreModelI
}
/**
- * Returns the score matrix as used in getPairwiseScore. If using this matrix
- * directly, callers must also call getMatrixIndex
in
- * order to get the matrix index for each character (symbol).
+ * Returns a copy of the score matrix as used in getPairwiseScore. If using
+ * this matrix directly, callers must also call
+ * getMatrixIndex
in order to get the matrix index for each
+ * character (symbol).
*
* @return
* @see #getMatrixIndex(char)
*/
public float[][] getMatrix()
{
- return matrix;
+ float[][] v = new float[matrix.length][matrix.length];
+ for (int i = 0; i < matrix.length; i++)
+ {
+ v[i] = Arrays.copyOf(matrix[i], matrix[i].length);
+ }
+ return v;
}
/**
@@ -228,7 +249,12 @@ public class ScoreMatrix implements PairwiseScoreModelI
}
/**
- * Print the score matrix, optionally formatted as html, with the alphabet symbols as column headings and at the start of each row
+ * Print the score matrix, optionally formatted as html, with the alphabet
+ * symbols as column headings and at the start of each row.
+ *
+ * The non-html format should give an output which can be parsed as a score + * matrix file + * * @param html * @return */ @@ -244,6 +270,11 @@ public class ScoreMatrix implements PairwiseScoreModelI sb.append("
" : ""); } + else + { + sb.append("ScoreMatrix ").append(getName()).append("\n"); + sb.append(symbols).append("\n"); + } for (char sym : symbols) { if (html) @@ -292,4 +323,104 @@ public class ScoreMatrix implements PairwiseScoreModelI { return symbols.length; } + + /** + * 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 + * |
---|