*/
private boolean peptide;
+ private boolean symmetric;
+
/**
* 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
}
/**
- * 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).
+ * Returns a copy of 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;
+ 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;
}
/**
}
return false;
}
+
+ public boolean isSymmetric()
+ {
+ return symmetric;
+ }
+
+ /**
+ * Returns the alphabet the matrix scores for, as a string of characters
+ *
+ * @return
+ */
+ public String getSymbols()
+ {
+ return new String(symbols);
+ }
}
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
import static org.testng.Assert.assertTrue;
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.util.Arrays;
import org.testng.annotations.Test;
}
@Test(groups = "Functional")
+ public void testGetMatrix()
+ {
+ ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
+ float[][] m = sm.getMatrix();
+ assertEquals(m.length, sm.getSize());
+ assertEquals(m[2][4], -3f);
+ // verify a defensive copy is returned
+ float[][] m2 = sm.getMatrix();
+ assertNotSame(m, m2);
+ assertTrue(Arrays.deepEquals(m, m2));
+ }
+
+ @Test(groups = "Functional")
public void testGetMatrixIndex()
{
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
assertNotNull(sm2);
assertTrue(sm2.equals(sm));
}
+
+ @Test(groups = "Functional")
+ public void testEauals()
+ {
+ ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
+ ScoreMatrix sm2 = new ScoreMatrix(sm.getName(), sm.getSymbols()
+ .toCharArray(), sm.getMatrix());
+ assertTrue(sm.equals(sm2));
+ assertEquals(sm.hashCode(), sm2.hashCode());
+ }
}