From: gmungoc Date: Tue, 21 Feb 2017 11:56:39 +0000 (+0000) Subject: Merge branch 'develop' into features/JAL-2393customMatrices X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~97 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f46c404585087d8937c48504bfcff716440d5186;p=jalview.git Merge branch 'develop' into features/JAL-2393customMatrices Conflicts: src/jalview/analysis/PCA.java src/jalview/schemes/ResidueProperties.java src/jalview/schemes/ScoreMatrix.java --- f46c404585087d8937c48504bfcff716440d5186 diff --cc src/jalview/analysis/PCA.java index ae83400,9babaee..b6766c6 --- a/src/jalview/analysis/PCA.java +++ b/src/jalview/analysis/PCA.java @@@ -20,12 -20,9 +20,10 @@@ */ package jalview.analysis; +import jalview.analysis.scoremodels.PairwiseDistanceModel; +import jalview.analysis.scoremodels.ScoreMatrix; +import jalview.analysis.scoremodels.ScoreModels; - import jalview.datamodel.BinarySequence; - import jalview.datamodel.BinarySequence.InvalidSequenceTypeException; - import jalview.math.Matrix; + import jalview.math.MatrixI; -import jalview.schemes.ResidueProperties; -import jalview.schemes.ScoreMatrix; import java.io.PrintStream; @@@ -95,15 -80,14 +81,15 @@@ public class PCA implements Runnabl String sm = s_m; if (sm != null) { - smtrx = (ScoreMatrix) ((PairwiseDistanceModel) ScoreModels - scoreMatrix = ResidueProperties.getScoreMatrix(sm); ++ scoreMatrix = (ScoreMatrix) ((PairwiseDistanceModel) ScoreModels + .getInstance() + .forName(sm)).getScoreModel(); } - if (smtrx == null) + if (scoreMatrix == null) { // either we were given a non-existent score matrix or a scoremodel that // isn't based on a pairwise symbol score matrix - smtrx = ScoreModels.getInstance().getDefaultModel(!nucleotides); - scoreMatrix = ResidueProperties - .getScoreMatrix(sm = (nucleotides ? "DNA" : "BLOSUM62")); ++ scoreMatrix = ScoreModels.getInstance().getDefaultModel(!nucleotides); } details.append("PCA calculation using " + sm + " sequence similarity matrix\n========\n\n"); diff --cc src/jalview/analysis/scoremodels/ScoreMatrix.java index eb94817,0000000..22c81f1 mode 100644,000000..100644 --- a/src/jalview/analysis/scoremodels/ScoreMatrix.java +++ b/src/jalview/analysis/scoremodels/ScoreMatrix.java @@@ -1,295 -1,0 +1,341 @@@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.analysis.scoremodels; + ++import jalview.math.Matrix; ++import jalview.math.MatrixI; ++ +import java.util.Arrays; + +public class ScoreMatrix implements PairwiseScoreModelI +{ + public static final short UNMAPPED = (short) -1; + + private static final String BAD_ASCII_ERROR = "Unexpected character %s in getPairwiseScore"; + + private static final int MAX_ASCII = 127; + + /* + * the name of the model as shown in menus + */ + private String name; + + /* + * the characters that the model provides scores for + */ + private char[] symbols; + + /* + * the score matrix; both dimensions must equal the number of symbols + * matrix[i][j] is the substitution score for replacing symbols[i] with symbols[j] + */ + private float[][] matrix; + + /* + * quick lookup to convert from an ascii character value to the index + * of the corresponding symbol in the score matrix + */ + private short[] symbolIndex; + + /* + * true for Protein Score matrix, false for dna score matrix + */ + private boolean peptide; + + /** + * Constructor given a name, symbol alphabet, and matrix of scores for pairs + * of symbols. The matrix should be square and of the same size as the + * alphabet, for example 20x20 for a 20 symbol alphabet. + * + * @param name + * Unique, human readable name for the matrix + * @param alphabet + * the symbols to which scores apply + * @param matrix + * Pairwise scores indexed according to the symbol alphabet + */ + public ScoreMatrix(String name, char[] alphabet, float[][] matrix) + { + if (alphabet.length != matrix.length) + { + throw new IllegalArgumentException( + "score matrix size must match alphabet size"); + } + for (float[] row : matrix) + { + if (row.length != alphabet.length) + { + throw new IllegalArgumentException( + "score matrix size must be square"); + } + } + + this.matrix = matrix; + this.name = name; + this.symbols = alphabet; + + symbolIndex = buildSymbolIndex(alphabet); + + /* + * crude heuristic for now... + */ + peptide = alphabet.length >= 20; + } + + /** + * Returns an array A where A[i] is the position in the alphabet array of the + * character whose value is i. For example if the alphabet is { 'A', 'D', 'X' + * } then A['D'] = A[68] = 1. + *

+ * Unmapped characters (not in the alphabet) get an index of -1. + *

+ * Mappings are added automatically for lower case symbols (for non case + * sensitive scoring), unless they are explicitly present in the alphabet (are + * scored separately in the score matrix). + * + * @param alphabet + * @return + */ + static short[] buildSymbolIndex(char[] alphabet) + { + short[] index = new short[MAX_ASCII + 1]; + Arrays.fill(index, UNMAPPED); + short pos = 0; + for (char c : alphabet) + { + if (c <= MAX_ASCII) + { + index[c] = pos; + } + + /* + * also map lower-case character (unless separately mapped) + */ + if (c >= 'A' && c <= 'Z') + { + short lowerCase = (short) (c + ('a' - 'A')); + if (index[lowerCase] == UNMAPPED) + { + index[lowerCase] = pos; + } + } + pos++; + } + return index; + } + + @Override + public String getName() + { + return name; + } + + @Override + public boolean isDNA() + { + return !peptide; + } + + @Override + public boolean isProtein() + { + return peptide; + } + + /** + * 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). + * + * @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 getMatrix 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 >= symbolIndex.length) + { + System.err.println(String.format(BAD_ASCII_ERROR, c)); + return 0; + } + if (d >= symbolIndex.length) + { + System.err.println(String.format(BAD_ASCII_ERROR, d)); + return 0; + } + + int cIndex = symbolIndex[c]; + int dIndex = symbolIndex[d]; + if (cIndex != UNMAPPED && dIndex != UNMAPPED) + { + return matrix[cIndex][dIndex]; + } + return 0; + } + + /** + * pretty print the matrix + */ + @Override + public String toString() + { + return outputMatrix(false); + } + + /** + * Print the score matrix, optionally formatted as html, with the alphabet symbols as column headings and at the start of each row + * @param html + * @return + */ + public String outputMatrix(boolean html) + { + StringBuilder sb = new StringBuilder(512); + + /* + * heading row with alphabet + */ + if (html) + { + sb.append(""); + sb.append(html ? "" : ""); + } + for (char sym : symbols) + { + if (html) + { + sb.append(""); + } + else + { + sb.append("\t").append(sym); + } + } + sb.append(html ? "\n" : "\n"); + + /* + * table of scores + */ + for (char c1 : symbols) + { + if (html) + { + sb.append("" : ""); + for (char c2 : symbols) + { + sb.append(html ? "" : ""); + } + sb.append(html ? "\n" : "\n"); + } + if (html) + { + sb.append("
 ").append(sym).append(" 
"); + } + sb.append(c1).append(html ? "" : "\t") + .append(matrix[symbolIndex[c1]][symbolIndex[c2]]) + .append(html ? "
"); + } + return sb.toString(); + } + + /** + * Answers the number of symbols coded for (also equal to the number of rows + * and columns of the score matrix) + * + * @return + */ + public int getSize() + { + 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 ++ *

++ */ ++ public MatrixI computePairwiseScores(String[] seqs) ++ { ++ 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); ++ float score = getPairwiseScore(c1, c2); ++ total += score; ++ } ++ values[row][col] = total; ++ } ++ } ++ return new Matrix(values); ++ } +} diff --cc src/jalview/datamodel/BinarySequence.java index da41c44,62ee974..b7e15a6 --- a/src/jalview/datamodel/BinarySequence.java +++ b/src/jalview/datamodel/BinarySequence.java @@@ -128,20 -124,14 +124,14 @@@ public class BinarySequence extends Seq + " is not a valid matrix for " + (isNa ? "nucleotide" : "protein") + "sequences"); } - matrixEncode(matrix.isDNA() ? ResidueProperties.nucleotideIndex - : ResidueProperties.aaIndex, matrix.getMatrix()); + matrixEncode(smtrx.isDNA() ? ResidueProperties.nucleotideIndex + : ResidueProperties.aaIndex, smtrx.getMatrix()); } - private void matrixEncode(final int[] aaIndex, final int[][] matrix) + private void matrixEncode(final int[] aaIndex, final float[][] matrix) { - // Set all matrix to 0 - // dbinary = new double[getSequence().length * 21]; - int nores = initMatrixGetNoRes(); - // for (int i = 0; i < dbinary.length; i++) { - // dbinary[i] = 0.0; - // } for (int i = 0, iSize = getSequence().length; i < iSize; i++) { int aanum = nores - 1; diff --cc test/jalview/analysis/scoremodels/ScoreMatrixTest.java index 0a9dd25,0000000..97cb742 mode 100644,000000..100644 --- a/test/jalview/analysis/scoremodels/ScoreMatrixTest.java +++ b/test/jalview/analysis/scoremodels/ScoreMatrixTest.java @@@ -1,137 -1,0 +1,193 @@@ +package jalview.analysis.scoremodels; +import static org.testng.Assert.assertEquals; +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; + ++import jalview.math.MatrixI; ++ +import org.testng.annotations.Test; + +public class ScoreMatrixTest +{ + @Test(groups = "Functional") + public void testConstructor() + { + // note score matrix does not have to be symmetric (though it should be!) + float[][] scores = new float[3][]; + scores[0] = new float[] { 1f, 2f, 3f }; + scores[1] = new float[] { 4f, 5f, 6f }; + scores[2] = new float[] { 7f, 8f, 9f }; + ScoreMatrix sm = new ScoreMatrix("Test", "ABC".toCharArray(), scores); + assertEquals(sm.getSize(), 3); + assertArrayEquals(scores, sm.getMatrix()); + assertEquals(sm.getPairwiseScore('A', 'a'), 1f); + assertEquals(sm.getPairwiseScore('b', 'c'), 6f); + assertEquals(sm.getPairwiseScore('c', 'b'), 8f); + assertEquals(sm.getPairwiseScore('A', 'D'), 0f); + assertEquals(sm.getMatrixIndex('c'), 2); + assertEquals(sm.getMatrixIndex(' '), -1); + } + + @Test( + groups = "Functional", + expectedExceptions = { IllegalArgumentException.class }) + public void testConstructor_matrixTooSmall() + { + float[][] scores = new float[2][]; + scores[0] = new float[] { 1f, 2f }; + scores[1] = new float[] { 3f, 4f }; + new ScoreMatrix("Test", "ABC".toCharArray(), scores); + } + + @Test( + groups = "Functional", + expectedExceptions = { IllegalArgumentException.class }) + public void testConstructor_matrixTooBig() + { + float[][] scores = new float[2][]; + scores[0] = new float[] { 1f, 2f }; + scores[1] = new float[] { 3f, 4f }; + new ScoreMatrix("Test", "A".toCharArray(), scores); + } + + @Test( + groups = "Functional", + expectedExceptions = { IllegalArgumentException.class }) + public void testConstructor_matrixNotSquare() + { + float[][] scores = new float[2][]; + scores[0] = new float[] { 1f, 2f }; + scores[1] = new float[] { 3f }; + new ScoreMatrix("Test", "AB".toCharArray(), scores); + } + + @Test(groups = "Functional") + public void testBuildSymbolIndex() + { + short[] index = ScoreMatrix.buildSymbolIndex("AX-. yxYp".toCharArray()); + + assertEquals(index.length, 128); // ASCII character set size + + assertEquals(index['A'], 0); + assertEquals(index['a'], 0); // lower-case mapping added + assertEquals(index['X'], 1); + assertEquals(index['-'], 2); + assertEquals(index['.'], 3); + assertEquals(index[' '], 4); + assertEquals(index['y'], 5); // lower-case override + assertEquals(index['x'], 6); // lower-case override + assertEquals(index['Y'], 7); + assertEquals(index['p'], 8); + assertEquals(index['P'], -1); // lower-case doesn't map upper-case + + /* + * check all unmapped symbols have index for unmapped + */ + for (int c = 0; c < index.length; c++) + { + if (!"AaXx-. Yyp".contains(String.valueOf((char) c))) + { + assertEquals(index[c], -1); + } + } + } + + /** + * check that characters not in the basic ASCII set are simply ignored + */ + @Test(groups = "Functional") + public void testBuildSymbolIndex_nonAscii() + { + char[] weird = new char[] { 128, 245, 'P' }; + short[] index = ScoreMatrix.buildSymbolIndex(weird); + assertEquals(index.length, 128); + assertEquals(index['P'], 2); + assertEquals(index['p'], 2); + for (int c = 0; c < index.length; c++) + { + if (c != 'P' && c != 'p') + { + assertEquals(index[c], -1); + } + } + } + + @Test(groups = "Functional") + public void testGetMatrixIndex() + { + ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); + assertEquals(sm.getMatrixIndex('A'), 0); + assertEquals(sm.getMatrixIndex('R'), 1); + assertEquals(sm.getMatrixIndex('r'), 1); + assertEquals(sm.getMatrixIndex('N'), 2); + assertEquals(sm.getMatrixIndex('D'), 3); + assertEquals(sm.getMatrixIndex('X'), 22); + assertEquals(sm.getMatrixIndex('x'), 22); + assertEquals(sm.getMatrixIndex(' '), 23); + assertEquals(sm.getMatrixIndex('*'), 24); + assertEquals(sm.getMatrixIndex('.'), -1); + assertEquals(sm.getMatrixIndex('-'), -1); + assertEquals(sm.getMatrixIndex('?'), -1); + assertEquals(sm.getMatrixIndex((char) 128), -1); + } + + @Test(groups = "Functional") + public void testGetSize() + { + ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); + assertEquals(sm.getMatrix().length, sm.getSize()); + } ++ ++ @Test(groups = "Functional") ++ public void testComputePairwiseScores() ++ { ++ /* ++ * NB score matrix assumes space for gap - Jalview converts ++ * space to gap before computing PCA or Tree ++ */ ++ String[] seqs = new String[] { "FKL", "R D", "QIA", "GWC" }; ++ ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); ++ ++ MatrixI pairwise = sm.computePairwiseScores(seqs); ++ ++ /* ++ * should be NxN where N = number of sequences ++ */ ++ assertEquals(pairwise.height(), 4); ++ assertEquals(pairwise.width(), 4); ++ ++ /* ++ * should be symmetrical (because BLOSUM62 is) ++ */ ++ for (int i = 0; i < pairwise.height(); i++) ++ { ++ for (int j = i + 1; j < pairwise.width(); j++) ++ { ++ assertEquals(pairwise.getValue(i, j), pairwise.getValue(j, i), ++ String.format("Not symmetric at [%d, %d]", i, j)); ++ } ++ } ++ /* ++ * verify expected BLOSUM dot product scores ++ */ ++ // F.F + K.K + L.L = 6 + 5 + 4 = 15 ++ assertEquals(pairwise.getValue(0, 0), 15d); ++ // R.R + -.- + D.D = 5 + 1 + 6 = 12 ++ assertEquals(pairwise.getValue(1, 1), 12d); ++ // Q.Q + I.I + A.A = 5 + 4 + 4 = 13 ++ assertEquals(pairwise.getValue(2, 2), 13d); ++ // G.G + W.W + C.C = 6 + 11 + 9 = 26 ++ assertEquals(pairwise.getValue(3, 3), 26d); ++ // F.R + K.- + L.D = -3 + -4 + -4 = -11 ++ assertEquals(pairwise.getValue(0, 1), -11d); ++ // F.Q + K.I + L.A = -3 + -3 + -1 = -7 ++ assertEquals(pairwise.getValue(0, 2), -7d); ++ // F.G + K.W + L.C = -3 + -3 + -1 = -7 ++ assertEquals(pairwise.getValue(0, 3), -7d); ++ // R.Q + -.I + D.A = 1 + -4 + -2 = -5 ++ assertEquals(pairwise.getValue(1, 2), -5d); ++ // R.G + -.W + D.C = -2 + -4 + -3 = -9 ++ assertEquals(pairwise.getValue(1, 3), -9d); ++ // Q.G + I.W + A.C = -2 + -3 + 0 = -5 ++ assertEquals(pairwise.getValue(2, 3), -5d); ++ } +} diff --cc test/jalview/analysis/scoremodels/ScoreModelsTest.java index c5c8673,0000000..f63843d mode 100644,000000..100644 --- a/test/jalview/analysis/scoremodels/ScoreModelsTest.java +++ b/test/jalview/analysis/scoremodels/ScoreModelsTest.java @@@ -1,63 -1,0 +1,110 @@@ +package jalview.analysis.scoremodels; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import jalview.api.analysis.DistanceModelI; + +import java.util.Iterator; + +import org.testng.annotations.Test; + +public class ScoreModelsTest +{ + /** + * Verify that the singleton constructor successfully loads Jalview's built-in + * score models + */ + @Test + public void testConstructor() + { + Iterator models = ScoreModels.getInstance().getModels() + .iterator(); + assertTrue(models.hasNext()); + + /* + * models are served in order of addition + */ + DistanceModelI sm = models.next(); + assertTrue(sm instanceof PairwiseDistanceModel); + assertEquals(sm.getName(), "BLOSUM62"); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('I', 'R'), -3f); + + sm = models.next(); + assertTrue(sm instanceof PairwiseDistanceModel); + assertEquals(sm.getName(), "PAM250"); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('R', 'C'), -4f); + + sm = models.next(); + assertTrue(sm instanceof PairwiseDistanceModel); + assertEquals(sm.getName(), "Identity (SeqSpace)"); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('R', 'C'), 0f); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('R', 'r'), 1f); + + sm = models.next(); + assertTrue(sm instanceof PairwiseDistanceModel); + assertEquals(sm.getName(), "DNA"); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('c', 'x'), 1f); + + sm = models.next(); + assertFalse(sm instanceof PairwiseDistanceModel); + assertEquals(sm.getName(), "Sequence Feature Similarity"); + + sm = models.next(); + assertFalse(sm instanceof PairwiseDistanceModel); + assertEquals(sm.getName(), "PID"); + } ++ ++ /** ++ * 'Test' that prints out score matrices in tab-delimited format. This test is ++ * intentionally not assigned to any group so would not be run as part of a ++ * suite. It makes no assertions and is just provided as a utility method for ++ * printing out matrices. Relocated here from ScoreMatrixPrinter. ++ */ ++ @Test ++ public void printAllMatrices_tabDelimited() ++ { ++ printAllMatrices(false); ++ } ++ ++ /** ++ * 'Test' that prints out score matrices in html format. This test is ++ * intentionally not assigned to any group so would not be run as part of a ++ * suite. It makes no assertions and is just provided as a utility method for ++ * printing out matrices. Relocated here from ScoreMatrixPrinter. ++ */ ++ @Test ++ public void printAllMatrices_asHtml() ++ { ++ printAllMatrices(true); ++ } ++ ++ /** ++ * Print all registered ScoreMatrix as plain or html tables ++ * ++ * @param asHtml ++ */ ++ protected void printAllMatrices(boolean asHtml) ++ { ++ for (DistanceModelI dm : ScoreModels.getInstance().getModels()) ++ { ++ if (dm instanceof PairwiseDistanceModel) ++ { ++ PairwiseScoreModelI psm = ((PairwiseDistanceModel) dm) ++ .getScoreModel(); ++ if (psm instanceof ScoreMatrix) ++ { ++ ScoreMatrix sm = (ScoreMatrix) psm; ++ System.out.println("ScoreMatrix " + sm.getName()); ++ System.out.println(sm.outputMatrix(asHtml)); ++ } ++ } ++ } ++ } +} diff --cc test/jalview/schemes/ScoreMatrixPrinter.java index aed4086,80241fb..0000000 deleted file mode 100644,100644 --- a/test/jalview/schemes/ScoreMatrixPrinter.java +++ /dev/null @@@ -1,64 -1,64 +1,0 @@@ --/* -- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) -- * Copyright (C) $$Year-Rel$$ The Jalview Authors -- * -- * This file is part of Jalview. -- * -- * Jalview is free software: you can redistribute it and/or -- * modify it under the terms of the GNU General Public License -- * as published by the Free Software Foundation, either version 3 -- * of the License, or (at your option) any later version. -- * -- * Jalview is distributed in the hope that it will be useful, but -- * WITHOUT ANY WARRANTY; without even the implied warranty -- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR -- * PURPOSE. See the GNU General Public License for more details. -- * -- * You should have received a copy of the GNU General Public License -- * along with Jalview. If not, see . -- * The Jalview Authors are detailed in the 'AUTHORS' file. -- */ --package jalview.schemes; -- - import jalview.analysis.scoremodels.ScoreMatrix; - import jalview.analysis.scoremodels.ScoreModels; - import jalview.api.analysis.DistanceModelI; - import jalview.gui.JvOptionPane; - - import org.testng.annotations.BeforeClass; - import org.testng.annotations.Test; - - public class ScoreMatrixPrinter - { - - @BeforeClass(alwaysRun = true) - public void setUpJvOptionPane() - { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); - } - - @Test(groups = { "Functional" }) - public void printAllMatrices() - { - for (DistanceModelI sm : ScoreModels.getInstance().getModels()) - { - System.out.println("Matrix " + sm.getName()); - System.out.println(sm.toString()); - } - } - - @Test(groups = { "Functional" }) - public void printHTMLMatrices() - { - for (DistanceModelI sm : ScoreModels.getInstance().getModels()) - { - if (sm instanceof ScoreMatrix) - { - System.out.println("Matrix " + sm.getName()); - System.out.println(((ScoreMatrix) sm).outputMatrix(true)); - } - } - } - - } -import jalview.api.analysis.ScoreModelI; -import jalview.gui.JvOptionPane; - -import java.util.Map; - -import org.testng.annotations.BeforeClass; - -public class ScoreMatrixPrinter -{ - - @BeforeClass(alwaysRun = true) - public void setUpJvOptionPane() - { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); - } - - public void printAllMatrices() - { - for (Map.Entry sm : ResidueProperties.scoreMatrices - .entrySet()) - { - System.out.println("Matrix " + sm.getKey()); - System.out.println(sm.getValue().toString()); - } - } - - public void printHTMLMatrices() - { - for (Map.Entry _sm : ResidueProperties.scoreMatrices - .entrySet()) - { - if (_sm.getValue() instanceof ScoreMatrix) - { - ScoreMatrix sm = (ScoreMatrix) _sm.getValue(); - System.out.println("Matrix " + _sm.getKey()); - System.out.println(sm.outputMatrix(true)); - } - } - } - -}