File: test_FixWidthTrack.py

package info (click to toggle)
macs 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 378,732 kB
  • sloc: ansic: 5,879; python: 4,342; sh: 451; makefile: 86
file content (93 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# Time-stamp: <2020-11-24 17:51:17 Tao Liu>

import unittest

from MACS3.Signal.FixWidthTrack import *

class Test_FWTrack(unittest.TestCase):

    def setUp(self):

        self.input_regions = [(b"chrY",0,0 ),
                              (b"chrY",90,0 ),
                              (b"chrY",150,0 ),
                              (b"chrY",70,0 ),
                              (b"chrY",80,0 ),
                              (b"chrY",85,0 ),
                              (b"chrY",85,0 ),
                              (b"chrY",85,0 ),
                              (b"chrY",85,0 ),
                              (b"chrY",90,1 ),
                              (b"chrY",150,1 ),
                              (b"chrY",70,1 ),
                              (b"chrY",80,1 ),
                              (b"chrY",80,1 ),
                              (b"chrY",80,1 ),
                              (b"chrY",85,1 ),
                              (b"chrY",90,1 ),
                              ]
        self.fw = 50

    def test_add_loc(self):
        # make sure the shuffled sequence does not lose any elements
        fw = FWTrack(fw=self.fw)
        for ( c, p, s ) in self.input_regions:
            fw.add_loc(c, p, s)
        fw.finalize()
        # roughly check the numbers...
        self.assertEqual( fw.total, 17 )
        self.assertEqual( fw.length, 17*self.fw )

    def test_filter_dup(self):
        # make sure the shuffled sequence does not lose any elements
        fw = FWTrack(fw=self.fw)
        for ( c, p, s ) in self.input_regions:
            fw.add_loc(c, p, s)
        fw.finalize()
        # roughly check the numbers...
        self.assertEqual( fw.total, 17 )
        self.assertEqual( fw.length, 17*self.fw )

        # filter out more than 3 tags
        fw.filter_dup( 3 )
        # one chrY:85:0 should be removed
        self.assertEqual( fw.total, 16 )

        # filter out more than 2 tags
        fw.filter_dup( 2 )
        # then, one chrY:85:0 and one chrY:80:- should be removed
        self.assertEqual( fw.total, 14 )

        # filter out more than 1 tag
        fw.filter_dup( 1 )
        # then, one chrY:85:0 and one chrY:80:1, one chrY:90:1 should be removed
        self.assertEqual( fw.total, 11 )


    def test_sample_num(self):
        # make sure the shuffled sequence does not lose any elements
        fw = FWTrack(fw=self.fw)
        for ( c, p, s ) in self.input_regions:
            fw.add_loc(c, p, s)
        fw.finalize()
        # roughly check the numbers...
        self.assertEqual( fw.total, 17 )
        self.assertEqual( fw.length, 17*self.fw )

        fw.sample_num( 10 )
        self.assertEqual( fw.total, 9 )

    def test_sample_percent(self):
        # make sure the shuffled sequence does not lose any elements
        fw = FWTrack(fw=self.fw)
        for ( c, p, s ) in self.input_regions:
            fw.add_loc(c, p, s)
        fw.finalize()
        # roughly check the numbers...
        self.assertEqual( fw.total, 17 )
        self.assertEqual( fw.length, 17*self.fw )

        fw.sample_percent( 0.5 )
        self.assertEqual( fw.total, 8 )