root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/bx/intervals/cluster_tests.py

リビジョン 3, 3.8 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1import sys, os
2import unittest
3try:
4    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
5except:
6    sys.path.insert(0, os.path.dirname(os.path.abspath(".")))
7
8# from bx.intervals.cluster import ClusterTree
9from cluster import ClusterTree
10
11class TestCluster(unittest.TestCase):
12    def setUp(self):
13        self.tree = ClusterTree(0, 0)
14   
15    def insertpairs(self, pairs):
16        for i, (s, e) in enumerate(pairs):
17            self.tree.insert(s, e, i)
18   
19    def test_merge_case(self):
20        pairs = [(3, 4), (6, 7), (9, 10), (1, 2), (3, 8)]
21        self.insertpairs(pairs)
22       
23        self.assertEqual( [(1, 2, [3]), (3, 8, [0, 1, 4]), (9, 10, [2])], self.tree.getregions() )
24   
25    def test_trivial(self):
26        pairs = [ (1, 4), (4, 5) ]
27        self.insertpairs(pairs)
28       
29        self.assertEqual( [(1, 5, [0, 1])], self.tree.getregions() )
30       
31    def test_easymerge(self):
32        pairs = [ (1, 2), (4, 5), (2, 4) ]
33        self.insertpairs(pairs)
34
35        self.assertEqual( [(1, 5, [0, 1, 2])], self.tree.getregions() )
36       
37    def test_hardmerge(self):
38        pairs = [ (1, 2), (8, 9), (3, 4), (5, 6), (7, 8), (1, 10) ]
39        self.insertpairs(pairs)
40
41        self.assertEqual( [(1, 10, [0, 1, 2, 3, 4, 5])], self.tree.getregions() )
42   
43    def test_duplicates(self):
44        pairs = [ (1, 1), (1, 2), (3, 4), (3, 4), (1, 4) ]
45        self.insertpairs(pairs)
46
47        self.assertEqual( [(1, 4, [0, 1, 2, 3, 4])], self.tree.getregions() )
48       
49    def test_startbeforeend(self):
50        self.assertRaises(ValueError, self.tree.insert, 4, 2, 0)
51       
52    def test_large_sorted(self):
53        upto = 100000
54        pairs = [ (2*i + 1, 2*i + 2) for i in range(upto) ]
55        self.insertpairs(pairs)
56        self.tree.insert( 0, upto*3, upto )
57        self.assertEqual( [ (0, upto*3, [x for x in range(upto+1)]) ], self.tree.getregions() )
58       
59    def test_minregions(self):
60        self.tree = ClusterTree(0, 2)
61        pairs = [(3, 4), (6, 7), (9, 10), (1, 2), (3, 8)]
62        self.insertpairs(pairs)
63       
64        self.assertEqual( [(3, 8, [0, 1, 4])], self.tree.getregions() )
65       
66    def test_distance(self):
67        self.tree = ClusterTree(1, 0)
68        pairs = [(3, 4), (6, 7), (9, 10), (1, 2), (3, 8)]
69        self.insertpairs(pairs)
70       
71        self.assertEqual( [(1, 10, [0, 1, 2, 3, 4])], self.tree.getregions() )
72       
73    def test_merge_left_right(self):
74        pairs = [(6, 7, 1), (1, 2, 3), (9, 10, 2), (3, 4, 0), (3, 8, 4)]
75        for s, e, i in pairs:
76            self.tree.insert(s, e, i)
77
78        self.assertEqual( [(1, 2, [3]), (3, 8, [0, 1, 4]), (9, 10, [2])], self.tree.getregions() )
79   
80    def test_larger(self):
81        pairs = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11, 12), (13, 14), (15, 16), (17, 18), (19, 20),
82                (1, 3), (4, 10), (10, 15), (15, 20), (21, 22)]
83        self.insertpairs(pairs)
84       
85        self.assertEqual( [(1, 20, [x for x in range(14)]), (21, 22, [14])], self.tree.getregions() )
86   
87    def test_another(self):
88        pairs = [(3, 4, 1), (13, 14, 6), (21, 22, 14), (5, 6, 2), (4, 10, 11), (1, 2, 0), (11, 12, 5), (1, 3, 10), (7, 8, 3), (15, 16, 7), (15, 20, 13), (19, 20, 9), (10, 15, 12), (17, 18, 8), (9, 10, 4)]
89        # pairs = [(3, 4, 1), (13, 14, 6), (21, 22, 14), (5, 6, 2), (4, 10, 11), (1, 2, 0), (11, 12, 5), (1, 3, 10), (7, 8, 3), (15, 16, 7), (15, 20, 13), (19, 20, 9), (10, 15, 12), (9, 10, 4)]
90        for s, e, i in pairs:
91            self.tree.insert(s, e, i)
92       
93        self.assertEqual( [(1, 20, [x for x in range(14)]), (21, 22, [14])], self.tree.getregions() )
94       
95    def test_none(self):
96        pairs = []
97        self.insertpairs(pairs)
98
99        self.assertEqual( [], self.tree.getregions() )
100       
101
102if __name__ == '__main__':
103    unittest.main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。