2 # Time-stamp: <2024-10-15 16:07:27 Tao Liu>
5 from MACS3
.Signal
.PairedEndTrack
import PETrackI
, PETrackII
9 class Test_PETrackI(unittest
.TestCase
):
11 self
.input_regions
= [(b
"chrY", 0, 100),
29 self
.t
= sum([x
[2]-x
[1] for x
in self
.input_regions
])
31 def test_add_loc(self
):
33 for (c
, l
, r
) in self
.input_regions
:
36 # roughly check the numbers...
37 self
.assertEqual(pe
.total
, 17)
38 self
.assertEqual(pe
.length
, self
.t
)
40 def test_filter_dup(self
):
42 for (c
, l
, r
) in self
.input_regions
:
45 # roughly check the numbers...
46 self
.assertEqual(pe
.total
, 17)
47 self
.assertEqual(pe
.length
, self
.t
)
49 # filter out more than 3 tags
51 self
.assertEqual(pe
.total
, 17)
53 # filter out more than 2 tags
55 self
.assertEqual(pe
.total
, 16)
57 # filter out more than 1 tag
59 self
.assertEqual(pe
.total
, 12)
61 def test_sample_num(self
):
63 for (c
, l
, r
) in self
.input_regions
:
67 self
.assertEqual(pe
.total
, 10)
69 def test_sample_percent(self
):
71 for (c
, l
, r
) in self
.input_regions
:
74 pe
.sample_percent(0.5)
75 self
.assertEqual(pe
.total
, 8)
78 class Test_PETrackII(unittest
.TestCase
):
80 self
.input_regions
= [(b
"chrY", 0, 100, b
"0w#AAACGAAAGACTCGGA", 2),
81 (b
"chrY", 70, 170, b
"0w#AAACGAAAGACTCGGA", 1),
82 (b
"chrY", 80, 190, b
"0w#AAACGAAAGACTCGGA", 1),
83 (b
"chrY", 85, 180, b
"0w#AAACGAAAGACTCGGA", 3),
84 (b
"chrY", 100, 190, b
"0w#AAACGAAAGACTCGGA", 1),
85 (b
"chrY", 0, 100, b
"0w#AAACGAACAAGTAACA", 1),
86 (b
"chrY", 70, 170, b
"0w#AAACGAACAAGTAACA", 2),
87 (b
"chrY", 80, 190, b
"0w#AAACGAACAAGTAACA", 1),
88 (b
"chrY", 85, 180, b
"0w#AAACGAACAAGTAACA", 1),
89 (b
"chrY", 100, 190, b
"0w#AAACGAACAAGTAACA", 3),
90 (b
"chrY", 10, 110, b
"0w#AAACGAACAAGTAAGA", 1),
91 (b
"chrY", 50, 160, b
"0w#AAACGAACAAGTAAGA", 2),
92 (b
"chrY", 100, 170, b
"0w#AAACGAACAAGTAAGA", 3)
94 self
.pileup_p
= np
.array([10, 50, 70, 80, 85, 100, 110, 160, 170, 180, 190], dtype
="i4")
95 self
.pileup_v
= np
.array([3.0, 4.0, 6.0, 9.0, 11.0, 15.0, 19.0, 18.0, 16.0, 10.0, 6.0], dtype
="f4")
96 self
.peak_str
= "chrom:chrY start:80 end:180 name:peak_1 score:19 summit:105\n"
97 self
.subset_barcodes
= {b
'0w#AAACGAACAAGTAACA', b
"0w#AAACGAACAAGTAAGA"}
98 self
.subset_pileup_p
= np
.array([10, 50, 70, 80, 85, 100, 110, 160, 170, 180, 190], dtype
="i4")
99 self
.subset_pileup_v
= np
.array([1.0, 2.0, 4.0, 6.0, 7.0, 8.0, 13.0, 12.0, 10.0, 5.0, 4.0], dtype
="f4")
100 self
.subset_peak_str
= "chrom:chrY start:100 end:170 name:peak_1 score:13 summit:105\n"
102 self
.t
= sum([(x
[2]-x
[1]) * x
[4] for x
in self
.input_regions
])
104 def test_add_frag(self
):
106 for (c
, l
, r
, b
, C
) in self
.input_regions
:
107 pe
.add_loc(c
, l
, r
, b
, C
)
109 # roughly check the numbers...
110 self
.assertEqual(pe
.total
, 22)
111 self
.assertEqual(pe
.length
, self
.t
)
114 pe_subset
= pe
.subset(self
.subset_barcodes
)
115 # roughly check the numbers...
116 self
.assertEqual(pe_subset
.total
, 14)
117 self
.assertEqual(pe_subset
.length
, 1305)
119 def test_pileup(self
):
121 for (c
, l
, r
, b
, C
) in self
.input_regions
:
122 pe
.add_loc(c
, l
, r
, b
, C
)
124 bdg
= pe
.pileup_bdg()
125 d
= bdg
.get_data_by_chr(b
'chrY') # (p, v) of ndarray
126 np
.testing
.assert_array_equal(d
[0], self
.pileup_p
)
127 np
.testing
.assert_array_equal(d
[1], self
.pileup_v
)
129 pe_subset
= pe
.subset(self
.subset_barcodes
)
130 bdg
= pe_subset
.pileup_bdg()
131 d
= bdg
.get_data_by_chr(b
'chrY') # (p, v) of ndarray
132 np
.testing
.assert_array_equal(d
[0], self
.subset_pileup_p
)
133 np
.testing
.assert_array_equal(d
[1], self
.subset_pileup_v
)
135 def test_pileup2(self
):
137 for (c
, l
, r
, b
, C
) in self
.input_regions
:
138 pe
.add_loc(c
, l
, r
, b
, C
)
140 bdg
= pe
.pileup_bdg2()
141 d
= bdg
.get_data_by_chr(b
'chrY') # (p, v) of ndarray
142 np
.testing
.assert_array_equal(d
['p'], self
.pileup_p
)
143 np
.testing
.assert_array_equal(d
['v'], self
.pileup_v
)
145 pe_subset
= pe
.subset(self
.subset_barcodes
)
146 bdg
= pe_subset
.pileup_bdg2()
147 d
= bdg
.get_data_by_chr(b
'chrY') # (p, v) of ndarray
148 np
.testing
.assert_array_equal(d
['p'], self
.subset_pileup_p
)
149 np
.testing
.assert_array_equal(d
['v'], self
.subset_pileup_v
)
151 def test_callpeak(self
):
153 for (c
, l
, r
, b
, C
) in self
.input_regions
:
154 pe
.add_loc(c
, l
, r
, b
, C
)
156 bdg
= pe
.pileup_bdg() # bedGraphTrackI object
157 peaks
= bdg
.call_peaks(cutoff
=10, min_length
=20, max_gap
=10)
158 self
.assertEqual(str(peaks
), self
.peak_str
)
160 pe_subset
= pe
.subset(self
.subset_barcodes
)
161 bdg
= pe_subset
.pileup_bdg()
162 peaks
= bdg
.call_peaks(cutoff
=10, min_length
=20, max_gap
=10)
163 self
.assertEqual(str(peaks
), self
.subset_peak_str
)
165 def test_callpeak2(self
):
167 for (c
, l
, r
, b
, C
) in self
.input_regions
:
168 pe
.add_loc(c
, l
, r
, b
, C
)
170 bdg
= pe
.pileup_bdg2() # bedGraphTrackII object
171 peaks
= bdg
.call_peaks(cutoff
=10, min_length
=20, max_gap
=10)
172 self
.assertEqual(str(peaks
), self
.peak_str
)
174 pe_subset
= pe
.subset(self
.subset_barcodes
)
175 bdg
= pe_subset
.pileup_bdg2()
176 peaks
= bdg
.call_peaks(cutoff
=10, min_length
=20, max_gap
=10)
177 self
.assertEqual(str(peaks
), self
.subset_peak_str
)