6
|
1 import unittest
|
|
2 from commons.core.coord.SlidingWindow import SlidingWindow
|
|
3 from commons.core.coord.SlidingWindow import SlidingWindowToCountMatchingBases
|
|
4 from commons.core.coord.Set import Set
|
|
5
|
|
6 class Test_SlidingWindow( unittest.TestCase ):
|
|
7
|
|
8 def test_slideWindowOnce( self ):
|
|
9 expStart = 91
|
|
10 expEnd = 190
|
|
11 self.sw = SlidingWindow(100, 10)
|
|
12 self.sw.slideWindowOnce()
|
|
13 obsStart = self.sw._start
|
|
14 obsEnd = self.sw._end
|
|
15
|
|
16 self.assertEqual(expStart, obsStart)
|
|
17 self.assertEqual(expEnd, obsEnd)
|
|
18
|
|
19 def test_slideWindowOnceFourTime( self ):
|
|
20 expStart = 201
|
|
21 expEnd = 300
|
|
22 self.sw = SlidingWindow(100, 50)
|
|
23 i = 0
|
|
24 for i in range(4):
|
|
25 self.sw.slideWindowOnce()
|
|
26 i += 1
|
|
27 obsStart = self.sw._start
|
|
28 obsEnd = self.sw._end
|
|
29
|
|
30 self.assertEqual(expStart, obsStart)
|
|
31 self.assertEqual(expEnd, obsEnd)
|
|
32
|
|
33
|
|
34 class Test_SlidingWindowToCountMatchingBases(unittest.TestCase):
|
|
35
|
|
36 def test_getSetLengthOnWindow_featureIncluded( self ):
|
|
37 self.sw = SlidingWindowToCountMatchingBases(100, 1)
|
|
38 iSet = Set( 1, "TE3", "chr1", 21, 30 )
|
|
39 exp = 10
|
|
40 obs = self.sw.getSetLengthOnWindow( iSet)
|
|
41 self.assertEqual( exp, obs )
|
|
42
|
|
43 def test_getSetLengthOnWindow_windowIncluded( self ):
|
|
44 self.sw = SlidingWindowToCountMatchingBases(100, 10)
|
|
45 self.sw.slideWindowOnce()
|
|
46 iSet = Set( 1, "TE3", "chr1", 21, 530 )
|
|
47 exp = 100
|
|
48 obs = self.sw.getSetLengthOnWindow( iSet)
|
|
49 self.assertEqual( exp, obs )
|
|
50
|
|
51 def test_getSetLengthOnWindow_featureOverlapLeft( self ):
|
|
52 self.sw = SlidingWindowToCountMatchingBases(100, 10)
|
|
53 self.sw.slideWindowOnce()
|
|
54 iSet = Set( 1, "TE3", "chr1", 21, 130 )
|
|
55 exp = 40
|
|
56 obs = self.sw.getSetLengthOnWindow( iSet)
|
|
57 self.assertEqual( exp, obs )
|
|
58
|
|
59 def test_getSetLengthOnWindow_featureOverlapRight( self ):
|
|
60 self.sw = SlidingWindowToCountMatchingBases(100, 10)
|
|
61 self.sw.slideWindowOnce()
|
|
62 iSet = Set( 1, "TE3", "chr1", 121, 230 )
|
|
63 exp = 70
|
|
64 obs = self.sw.getSetLengthOnWindow( iSet)
|
|
65 self.assertEqual( exp, obs )
|
|
66
|
|
67 def test_getCoordSetOnWindow_featureIncluded( self ):
|
|
68 self.sw = SlidingWindowToCountMatchingBases(100, 1)
|
|
69 iSet = Set( 1, "TE3", "chr1", 21, 30 )
|
|
70 expStart = 21
|
|
71 expEnd = 30
|
|
72 obsStart,obsEnd = self.sw.getCoordSetOnWindow( iSet)
|
|
73 self.assertEqual( expStart, obsStart )
|
|
74 self.assertEqual( expEnd, obsEnd )
|
|
75
|
|
76 def test_getCoordSetOnWindow_windowIncluded( self ):
|
|
77 self.sw = SlidingWindowToCountMatchingBases(100, 10)
|
|
78 self.sw.slideWindowOnce()
|
|
79 iSet = Set( 1, "TE3", "chr1", 21, 530 )
|
|
80 expStart = 91
|
|
81 expEnd = 190
|
|
82 obsStart,obsEnd = self.sw.getCoordSetOnWindow( iSet)
|
|
83 self.assertEqual( expStart, obsStart )
|
|
84 self.assertEqual( expEnd, obsEnd )
|
|
85
|
|
86 def test_getCoordSetOnWindow_featureOverlapLeft( self ):
|
|
87 self.sw = SlidingWindowToCountMatchingBases(100, 10)
|
|
88 self.sw.slideWindowOnce()
|
|
89 iSet = Set( 1, "TE3", "chr1", 21, 130 )
|
|
90 expStart = 91
|
|
91 expEnd = 130
|
|
92 obsStart,obsEnd = self.sw.getCoordSetOnWindow( iSet)
|
|
93 self.assertEqual( expStart, obsStart )
|
|
94 self.assertEqual( expEnd, obsEnd )
|
|
95
|
|
96 def test_getCoordSetOnWindow_featureOverlapRight( self ):
|
|
97 self.sw = SlidingWindowToCountMatchingBases(100, 10)
|
|
98 self.sw.slideWindowOnce()
|
|
99 iSet = Set( 1, "TE3", "chr1", 121, 230 )
|
|
100 expStart = 121
|
|
101 expEnd = 190
|
|
102 obsStart,obsEnd = self.sw.getCoordSetOnWindow( iSet)
|
|
103 self.assertEqual( expStart, obsStart )
|
|
104 self.assertEqual( expEnd, obsEnd )
|
|
105
|
|
106 test_suite = unittest.TestSuite()
|
|
107 test_suite.addTest( unittest.makeSuite( Test_SlidingWindow ) )
|
|
108 if __name__ == "__main__":
|
|
109 unittest.TextTestRunner(verbosity=2).run( test_suite ) |