1 """Unit Test for nussinov"""
2 import unittest
3 from nussinov import NussinovMatrix, Nussinov
4
5 sample = 'GGGAAAUCC'
6
7 class TestDataStructure(unittest.TestCase):
8 def testStack(self):
9 mystack = [1,2,3,4,5]
10 mystack.pop()
11 mystack.append('push')
12 self.assertEqual(mystack, [1,2,3,4,'push'])
13
14 class TestNussinovMatrix(unittest.TestCase):
15 def testInitialNussinovMatrix(self):
16 matrix = NussinovMatrix(sample)
17 initialMatrix = [[ 0,'n','n','n','n','n','n','n','n'],
18 [ 0, 0,'n','n','n','n','n','n','n'],
19 ['n', 0, 0,'n','n','n','n','n','n'],
20 ['n','n', 0, 0,'n','n','n','n','n'],
21 ['n','n','n', 0, 0,'n','n','n','n'],
22 ['n','n','n','n', 0, 0,'n','n','n'],
23 ['n','n','n','n','n', 0, 0,'n','n'],
24 ['n','n','n','n','n','n', 0, 0,'n'],
25 ['n','n','n','n','n','n','n', 0, 0]]
26 self.assertEqual(matrix.getInitialMatrix(), initialMatrix)
27
28 def testScorePair(self):
29 matrix = NussinovMatrix(sample)
30 self.assertEqual(matrix.score(1, 9), 1)
31
32 def testScoreNonPair(self):
33 matrix = NussinovMatrix(sample)
34 self.assertEqual(matrix.score(1, 2), 0)
35
36 def testFinalNussinovMatrix(self):
37 finalMatrix = [[ 0, 0, 0, 0, 0, 0, 1, 2, 3],
38 [ 0, 0, 0, 0, 0, 0, 1, 2, 3],
39 ['n', 0, 0, 0, 0, 0, 1, 2, 2],
40 ['n','n', 0, 0, 0, 0, 1, 1, 1],
41 ['n','n','n', 0, 0, 0, 1, 1, 1],
42 ['n','n','n','n', 0, 0, 1, 1, 1],
43 ['n','n','n','n','n', 0, 0, 0, 0],
44 ['n','n','n','n','n','n', 0, 0, 0],
45 ['n','n','n','n','n','n','n', 0, 0]]
46 matrix = NussinovMatrix(sample)
47 self.assertEqual(matrix.getFinalMatrix(), finalMatrix)
48
49 class TestNussinovTraceback(unittest.TestCase):
50 def testStackRecursion(self):
51 matrix = [[ 0, 0, 0, 0, 0, 0, 1, 2, 3],
52 [ 0, 0, 0, 0, 0, 0, 1, 2, 3],
53 ['n', 0, 0, 0, 0, 0, 1, 2, 2],
54 ['n','n', 0, 0, 0, 0, 1, 1, 1],
55 ['n','n','n', 0, 0, 0, 1, 1, 1],
56 ['n','n','n','n', 0, 0, 1, 1, 1],
57 ['n','n','n','n','n', 0, 0, 0, 0],
58 ['n','n','n','n','n','n', 0, 0, 0],
59 ['n','n','n','n','n','n','n', 0, 0]]
60 mystack = Nussinov(sample)
61 basepair = [(2,9),(3,8),(4,7)]
62 self.assertEqual(mystack.getBasePair(), basepair)
63
64 if __name__=='__main__':
65 unittest.main(argv=('','-v'))