def est_jc69_from_matrix(self):
     """compute JC69 from diversity matrix"""
     s1 = seq_to_indices('ACGTACGTAC', self.dna_char_indices)
     s2 = seq_to_indices('GTGTACGTAC', self.dna_char_indices)
     matrix = numpy.zeros((4,4), float)
     _fill_diversity_matrix(matrix, s1, s2)
     total, p, dist, var = _jc69_from_matrix(matrix)
     self.assertEquals(total, 10.0)
     self.assertEquals(p, 0.2)
 def test_jc69_from_matrix(self):
     """compute JC69 from diversity matrix"""
     s1 = seq_to_indices('ACGTACGTAC', self.dna_char_indices)
     s2 = seq_to_indices('GTGTACGTAC', self.dna_char_indices)
     matrix = numpy.zeros((4, 4), float)
     _fill_diversity_matrix(matrix, s1, s2)
     total, p, dist, var = _jc69_from_matrix(matrix)
     self.assertEquals(total, 10.0)
     self.assertEquals(p, 0.2)
 def est_python_vs_cython_fill_matrix(self):
     """python & cython fill_diversity_matrix give same answer"""
     s1 = seq_to_indices('RACGTACGTACN', self.dna_char_indices)
     s2 = seq_to_indices('AGTGTACGTACA', self.dna_char_indices)
     matrix1 = numpy.zeros((4,4), float)
     _fill_diversity_matrix(matrix1, s1, s2)
     matrix2 = numpy.zeros((4,4), float)
     pyx_fill_diversity_matrix(matrix2, s1, s2)
     self.assertFloatEqual(matrix1, matrix2)
 def test_python_vs_cython_fill_matrix(self):
     """python & cython fill_diversity_matrix give same answer"""
     s1 = seq_to_indices('RACGTACGTACN', self.dna_char_indices)
     s2 = seq_to_indices('AGTGTACGTACA', self.dna_char_indices)
     matrix1 = numpy.zeros((4, 4), float)
     _fill_diversity_matrix(matrix1, s1, s2)
     matrix2 = numpy.zeros((4, 4), float)
     pyx_fill_diversity_matrix(matrix2, s1, s2)
     self.assertFloatEqual(matrix1, matrix2)
 def est_fill_diversity_matrix_some(self):
     """make correct diversity matrix when not all chars valid"""
     s1 = seq_to_indices('RACGTACGTACN', self.dna_char_indices)
     s2 = seq_to_indices('AGTGTACGTACA', self.dna_char_indices)
     matrix = numpy.zeros((4,4), float)
     # small diffs
     matrix.fill(0)
     _fill_diversity_matrix(matrix, s1, s2)
     self.assertEquals(matrix,
         numpy.array([[2,0,0,0],
                      [1,2,0,0],
                      [0,0,2,1],
                      [0,0,0,2]], float))
 def test_fill_diversity_matrix_some(self):
     """make correct diversity matrix when not all chars valid"""
     s1 = seq_to_indices('RACGTACGTACN', self.dna_char_indices)
     s2 = seq_to_indices('AGTGTACGTACA', self.dna_char_indices)
     matrix = numpy.zeros((4, 4), float)
     # small diffs
     matrix.fill(0)
     _fill_diversity_matrix(matrix, s1, s2)
     self.assertEquals(
         matrix,
         numpy.array(
             [[2, 0, 0, 0], [1, 2, 0, 0], [0, 0, 2, 1], [0, 0, 0, 2]],
             float))
 def est_fill_diversity_matrix_all(self):
     """make correct diversity matrix when all chars valid"""
     s1 = seq_to_indices('ACGTACGTAC', self.dna_char_indices)
     s2 = seq_to_indices('GTGTACGTAC', self.dna_char_indices)
     matrix = numpy.zeros((4,4), float)
     # self-self should just be an identity matrix
     _fill_diversity_matrix(matrix, s1, s1)
     self.assertEquals(matrix.sum(), len(s1))
     self.assertEquals(matrix,
         numpy.array([[2,0,0,0],
                      [0,3,0,0],
                      [0,0,3,0],
                      [0,0,0,2]], float))
     
     # small diffs
     matrix.fill(0)
     _fill_diversity_matrix(matrix, s1, s2)
     self.assertEquals(matrix,
         numpy.array([[2,0,0,0],
                      [1,2,0,0],
                      [0,0,2,1],
                      [0,0,0,2]], float))
    def test_fill_diversity_matrix_all(self):
        """make correct diversity matrix when all chars valid"""
        s1 = seq_to_indices('ACGTACGTAC', self.dna_char_indices)
        s2 = seq_to_indices('GTGTACGTAC', self.dna_char_indices)
        matrix = numpy.zeros((4, 4), float)
        # self-self should just be an identity matrix
        _fill_diversity_matrix(matrix, s1, s1)
        self.assertEquals(matrix.sum(), len(s1))
        self.assertEquals(
            matrix,
            numpy.array(
                [[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 3, 0], [0, 0, 0, 2]],
                float))

        # small diffs
        matrix.fill(0)
        _fill_diversity_matrix(matrix, s1, s2)
        self.assertEquals(
            matrix,
            numpy.array(
                [[2, 0, 0, 0], [1, 2, 0, 0], [0, 0, 2, 1], [0, 0, 0, 2]],
                float))