2 # Time-stamp: <2019-09-20 15:06:44 taoliu>
4 """Module Description: Test functions for pileup functions.
6 This code is free software; you can redistribute it and/or modify it
7 under the terms of the BSD License (see the file LICENSE included with
13 from math
import log10
14 from MACS2
.Pileup
import *
15 from MACS2
.IO
.FixWidthTrack
import FWTrack
17 # ------------------------------------
19 # ------------------------------------
21 class Test_pileup(unittest
.TestCase
):
22 """Unittest for pileup_bdg() in Pileup.pyx.
28 self
.plus_pos
= ( 0, 1, 3, 4, 5 )
29 self
.minus_pos
= ( 5, 6, 8, 9, 10 )
31 self
.scale_factor
= 0.5
32 self
.expect
= [ ( 0, 1, 1.0 ),
40 self
.expect2
= [(0, 1, 13.0),
48 self
.d_s
= [ 5, 10, 100 ]
49 self
.scale_factor_s
= [ 0.5, 1, 2 ]
51 def test_pileup(self
):
53 self
.fwtrack2
= FWTrack()
54 for i
in self
.plus_pos
:
55 self
.fwtrack2
.add_loc(self
.chrom
, i
, 0)
56 for i
in self
.minus_pos
:
57 self
.fwtrack2
.add_loc(self
.chrom
, i
, 1)
58 self
.fwtrack2
.finalize()
60 self
.pileup
= unified_pileup_bdg(self
.fwtrack2
, self
.d
, self
.scale_factor
, halfextension
=False)
62 chrs
= self
.pileup
.get_chr_names()
64 (p
,v
) = self
.pileup
.get_data_by_chr(chrom
)
65 pnext
= iter(p
).__next
__
66 vnext
= iter(v
).__next
__
68 for i
in range(len(p
)):
71 self
.result
.append( (pre
,pos
,value
) )
74 self
.assertEqual(self
.result
, self
.expect
)
76 def test_pileup_w_multiple_d_bdg ( self
):
78 self
.fwtrack2
= FWTrack(fw
=5)
79 for i
in self
.plus_pos
:
80 self
.fwtrack2
.add_loc(self
.chrom
, i
, 0)
81 for i
in self
.minus_pos
:
82 self
.fwtrack2
.add_loc(self
.chrom
, i
, 1)
83 self
.fwtrack2
.finalize()
85 self
.pileup
= unified_pileup_bdg(self
.fwtrack2
, self
.d_s
, self
.scale_factor_s
, baseline_value
=13, halfextension
=False)
87 chrs
= self
.pileup
.get_chr_names()
89 (p
,v
) = self
.pileup
.get_data_by_chr(chrom
)
90 pnext
= iter(p
).__next
__
91 vnext
= iter(v
).__next
__
93 for i
in range(len(p
)):
96 self
.result
.append( (pre
,pos
,value
) )
99 self
.assertEqual(self
.result
, self
.expect2
)