Example #1
0
    def test_read_blosum(self):
        f = data.data_stream("blosum80")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[0, 10], -3)
        f.close()

        f = data.data_stream("blosum62")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[4, 5], -4)
        f.close()
Example #2
0
    def test_read_pam(self):
        f = data.data_stream("pam250")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[0, 0], 2.0)
        f.close()

        f = data.data_stream("pam120")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[4, 5], -7)
        f.close()
Example #3
0
    def test_read_alphabets(self):

        # incompatable alphabets
        f = StringIO(test_matrix3)
        self.assertRaises(ValueError, SubMatrix.read, f)

        f = StringIO(test_matrix3)
        SubMatrix.read(f, alphabet=Alphabet('ARNDCQEGHILKMFPSTWYV'))

        f2 = StringIO(test_matrix1)
        self.assertRaises(ValueError, SubMatrix.read, f2,
                          unambiguous_protein_alphabet)
Example #4
0
 def test_get(self):
     ab = Alphabet('ABCD')
     ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                      [13, 14, 15, 16]])
     s = SubMatrix(ab, ar)
     s1 = 'DCCBBBAAA'
     s2 = 'BA'
     v = s.index((s1, s2))
     # print v
     for m, i in enumerate(s1):
         for n, j in enumerate(s2):
             assert s[i, j] == v[m, n]
Example #5
0
    def test_get_subMatrix(self):
        ab = Alphabet('ABCD')
        ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                         [13, 14, 15, 16]])
        mat = SubMatrix(ab, ar)

        mat2 = mat.reindex('ABC')
        assert np.all(
            mat2.array == np.asarray([[1, 2, 3], [5, 6, 7], [9, 10, 11]]))

        mat2 = mat.reindex('BA')
        assert np.all(mat2.array == np.asarray([[6, 5], [2, 1]]))

        mat2 = mat.reindex(Alphabet('BA'))
        assert np.all(mat2.array == np.asarray([[6, 5], [2, 1]]))
Example #6
0
    def test_repr(self):
        ab = Alphabet('ABCD')
        ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                         [13, 14, 15, 16]])
        s = SubMatrix(ab, ar)

        repr(s)
Example #7
0
    def test_read_blast(self):
        # New style blast matrices have letters at beginning of lines and a '*'
        f = data_stream("blosum35.blast.new")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[4, 5], -3)
        f.close()

        # Matrices formatted for old blast have a '*' (stop)
        # column and no letters at the beggining of lines
        f = data_stream("blosum35.blast")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[0, 10], -2)
        self.assertEqual(mat.array.shape, (23, 23))
        f.close()

        # For comparison, we'll also parse a matrix without '*'
        f = data_stream("pam250.mat")
        mat = SubMatrix.read(f)
        self.assertEqual(mat[4, 5], -5)
        f.close()
Example #8
0
    def test_fail_get(self):
        ab = Alphabet('ABCD')
        ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                         [13, 14, 15, 16]])
        s = SubMatrix(ab, ar)

        self.assertRaises(IndexError, s.__getitem__, ('E', 'A'))
        self.assertRaises(IndexError, s.__getitem__, ('5', '6'))

        # FIXME
        self.assertRaises(IndexError, s.index, ('E', 'A'))
Example #9
0
    def test_create(self):
        ab = 'ABCD'
        ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                         [13, 14, 15, 16]])
        s = SubMatrix(ab, ar)

        assert s[0, 0] == 1
        assert s['A', 'A'] == 1
        assert s['B', 'C'] == 7
        s['B', 'C'] = -1
        assert s['B', 'C'] == -1
Example #10
0
    def test_fail_get(self):
        ab = Alphabet("ABCD")
        ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                         [13, 14, 15, 16]])
        s = SubMatrix(ab, ar)

        self.assertRaises(IndexError, s.__getitem__, ("E", "A"))
        self.assertRaises(IndexError, s.__getitem__, ("5", "6"))

        # FIXME
        self.assertRaises(IndexError, s.index, ("E", "A"))
Example #11
0
    def test_create(self):
        ab = "ABCD"
        ar = np.asarray([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                         [13, 14, 15, 16]])
        s = SubMatrix(ab, ar)

        assert s[0, 0] == 1
        assert s["A", "A"] == 1
        assert s["B", "C"] == 7
        s["B", "C"] = -1
        assert s["B", "C"] == -1
Example #12
0
 def test_read(self):
     f = StringIO(test_matrix1)
     mat = SubMatrix.read(f)
     assert mat['a', 'a'] == 4
Example #13
0
 def test_read(self):
     f = StringIO(test_matrix1)
     mat = SubMatrix.read(f)
     assert mat["a", "a"] == 4