Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix scoreTrackII so that it can pass unittests.

  • Loading branch information...
commit 4cdea38b4a4ff25e05d33ff8c4ea855011760815 1 parent 1600ccd
@taoliu authored
View
1,537 MACS2/IO/cScoreTrack.c
771 additions, 766 deletions not shown
View
9 MACS2/IO/cScoreTrack.pyx
@@ -1,5 +1,5 @@
# cython: profile=True
-# Time-stamp: <2012-06-01 15:42:46 Tao Liu>
+# Time-stamp: <2012-06-01 16:01:05 Tao Liu>
"""Module for Feature IO classes.
@@ -1372,6 +1372,7 @@ cdef class scoreTrackII:
cdef:
dict pqtable
long i,l,j
+ double k
str chrom
np.ndarray p, c, v
@@ -1384,10 +1385,8 @@ cdef class scoreTrackII:
# convert pvalue2qvalue to a simple dict
s_p2q = Float64HashTable()
- #g = pvalue2qvalue.get
- for i in pqtable.keys():
- #for i in range(pvalue2qvalue.shape[0]):
- s_p2q.set_item(i,pqtable[i][0])
+ for k in pqtable.keys():
+ s_p2q.set_item(k,pqtable[k][0])
g = s_p2q.get_item
View
180 test/test_cScoreTrack.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Time-stamp: <2012-05-29 19:02:48 Tao Liu>
+# Time-stamp: <2012-06-01 16:10:30 Tao Liu>
import os
import sys
@@ -21,33 +21,33 @@ def setUp(self):
self.treat_edm = 10
self.ctrl_edm = 5
# for scoring
- self.p_result = [63.27, 0.38, 0.07, 0, 7.09]
+ self.p_result = [63.27, 0.38, 0.07, 0.00, 7.09]
self.q_result = [60.95, 0, 0, 0 ,5.81]
- self.l_result = [57.20, 0, -0.39, -3.79, 4.36]
- self.f_result = [0.96, 0, -0.11, -0.54, 0.54] # note, pseudo count 1 would be introduced.
+ self.l_result = [57.21, 0.00, -0.40, -3.79, 4.37]
+ self.f_result = [0.96, 0.00, -0.12, -0.54, 0.54] # note, pseudo count 1 would be introduced.
self.d_result = [90.00, 0, -5.00, -15.00, 15.00]
self.m_result = [10.00, 1.00, 1.50, 0.50, 2.00]
# for norm
- self.norm_T = [[ 10, 10000, 2000, 0],
- [ 60, 1000, 2000, 0],
- [110, 1500, 4000, 0],
- [160, 500, 4000, 0],
- [210, 2000, 1000, 0]]
- self.norm_C = [[ 10, 5000, 1000, 0],
- [ 60, 500, 1000, 0],
- [110, 750, 2000, 0],
- [160, 250, 2000, 0],
- [210, 1000, 500, 0]]
- self.norm_M = [[ 10, 1000, 200, 0],
- [ 60, 100, 200, 0],
- [110, 150, 400, 0],
- [160, 50, 400, 0],
- [210, 200, 100, 0]]
- self.norm_N = [[ 10, 10000, 1000, 0], # note precision lost
- [ 60, 1000, 1000, 0],
- [110, 1500, 2000, 0],
- [160, 500, 2000, 0],
- [210, 2000, 500, 0]]
+ self.norm_T = np.array([[ 10, 100, 20, 0],
+ [ 60, 10, 20, 0],
+ [110, 15, 40, 0],
+ [160, 5, 40, 0],
+ [210, 20, 10, 0]]).transpose()
+ self.norm_C = np.array([[ 10, 50, 10, 0],
+ [ 60, 5, 10, 0],
+ [110, 7.5, 20, 0],
+ [160, 2.5, 20, 0],
+ [210, 10, 5, 0]]).transpose()
+ self.norm_M = np.array([[ 10, 10, 2, 0],
+ [ 60, 1, 2, 0],
+ [110, 1.5, 4, 0],
+ [160, 0.5, 4, 0],
+ [210, 2, 1, 0]]).transpose()
+ self.norm_N = np.array([[ 10, 100, 10, 0], # note precision lost
+ [ 60, 10, 10, 0],
+ [110, 15, 20, 0],
+ [160, 5, 20, 0],
+ [210, 20, 5, 0]]).transpose()
# for write_bedGraph
self.bdg1 = """chrY 0 10 100.00
@@ -89,87 +89,87 @@ def test_compute_scores(self):
s1.change_score_method( ord('p') )
r = s1.get_data_by_chr("chrY")
- self.assertListEqual( list(r[3]), self.p_result )
+ self.assertListEqual( map(lambda x:round(x,2),list(r[3])), self.p_result )
s1.change_score_method( ord('q') )
r = s1.get_data_by_chr("chrY")
- self.assertListEqual( list(r[3]), self.q_result )
+ self.assertListEqual( map(lambda x:round(x,2),list(r[3])), self.q_result )
s1.change_score_method( ord('l') )
r = s1.get_data_by_chr("chrY")
- self.assertListEqual( list(r[3]), self.l_result )
+ self.assertListEqual( map(lambda x:round(x,2),list(r[3])), self.l_result )
s1.change_score_method( ord('f') )
r = s1.get_data_by_chr("chrY")
- self.assertListEqual( list(r[3]), self.f_result )
+ self.assertListEqual( map(lambda x:round(x,2),list(r[3])), self.f_result )
s1.change_score_method( ord('d') )
r = s1.get_data_by_chr("chrY")
- self.assertListEqual( list(r[3]), self.d_result )
+ self.assertListEqual( map(lambda x:round(x,2),list(r[3])), self.d_result )
s1.change_score_method( ord('m') )
r = s1.get_data_by_chr("chrY")
- self.assertListEqual( list(r[3]), self.m_result )
-
- # def test_normalize(self):
- # s1 = scoreTrackII( self.treat_edm, self.ctrl_edm )
- # s1.add_chromosome( "chrY", 5 )
- # for a in self.test_regions1:
- # s1.add( a[0],a[1],a[2],a[3] )
-
- # s1.change_normalization_method( ord('T') )
- # r = s1.get_data_by_chr("chrY")
- # assert_array_equal( r, self.norm_T )
-
- # s1.change_normalization_method( ord('C') )
- # r = s1.get_data_by_chr("chrY")
- # assert_array_equal( r, self.norm_C )
-
- # s1.change_normalization_method( ord('M') )
- # r = s1.get_data_by_chr("chrY")
- # assert_array_equal( r, self.norm_M )
-
- # s1.change_normalization_method( ord('N') )
- # r = s1.get_data_by_chr("chrY")
- # assert_array_equal( r, self.norm_N )
-
- # def test_writebedgraph ( self ):
- # s1 = scoreTrackII( self.treat_edm, self.ctrl_edm )
- # s1.add_chromosome( "chrY", 5 )
- # for a in self.test_regions1:
- # s1.add( a[0],a[1],a[2],a[3] )
-
- # s1.change_score_method( ord('p') )
-
- # strio = StringIO.StringIO()
- # s1.write_bedGraph( strio, "NAME", "DESC", 1 )
- # self.assertEqual( strio.getvalue(), self.bdg1 )
- # strio = StringIO.StringIO()
- # s1.write_bedGraph( strio, "NAME", "DESC", 2 )
- # self.assertEqual( strio.getvalue(), self.bdg2 )
- # strio = StringIO.StringIO()
- # s1.write_bedGraph( strio, "NAME", "DESC", 3 )
- # self.assertEqual( strio.getvalue(), self.bdg3 )
-
- # def test_callpeak ( self ):
- # s1 = scoreTrackII( self.treat_edm, self.ctrl_edm )
- # s1.add_chromosome( "chrY", 5 )
- # for a in self.test_regions1:
- # s1.add( a[0],a[1],a[2],a[3] )
-
- # s1.change_score_method( ord('p') )
- # p = s1.call_peaks( cutoff = 10, min_length=10, max_gap=10 )
- # strio = StringIO.StringIO()
- # p.write_to_bed( strio, trackline = False )
- # self.assertEqual( strio.getvalue(), self.peak1 )
-
- # strio = StringIO.StringIO()
- # p.write_to_summit_bed( strio, trackline = False )
- # self.assertEqual( strio.getvalue(), self.summit1 )
-
- # strio = StringIO.StringIO()
- # p.write_to_xls( strio )
- # self.assertEqual( strio.getvalue(), self.xls1 )
+ self.assertListEqual( map(lambda x:round(x,2),list(r[3])), self.m_result )
+
+ def test_normalize(self):
+ s1 = scoreTrackII( self.treat_edm, self.ctrl_edm )
+ s1.add_chromosome( "chrY", 5 )
+ for a in self.test_regions1:
+ s1.add( a[0],a[1],a[2],a[3] )
+
+ s1.change_normalization_method( ord('T') )
+ r = s1.get_data_by_chr("chrY")
+ assert_array_equal( r, self.norm_T )
+
+ s1.change_normalization_method( ord('C') )
+ r = s1.get_data_by_chr("chrY")
+ assert_array_equal( r, self.norm_C )
+
+ s1.change_normalization_method( ord('M') )
+ r = s1.get_data_by_chr("chrY")
+ assert_array_equal( r, self.norm_M )
+
+ s1.change_normalization_method( ord('N') )
+ r = s1.get_data_by_chr("chrY")
+ assert_array_equal( r, self.norm_N )
+
+ def test_writebedgraph ( self ):
+ s1 = scoreTrackII( self.treat_edm, self.ctrl_edm )
+ s1.add_chromosome( "chrY", 5 )
+ for a in self.test_regions1:
+ s1.add( a[0],a[1],a[2],a[3] )
+
+ s1.change_score_method( ord('p') )
+
+ strio = StringIO.StringIO()
+ s1.write_bedGraph( strio, "NAME", "DESC", 1 )
+ self.assertEqual( strio.getvalue(), self.bdg1 )
+ strio = StringIO.StringIO()
+ s1.write_bedGraph( strio, "NAME", "DESC", 2 )
+ self.assertEqual( strio.getvalue(), self.bdg2 )
+ strio = StringIO.StringIO()
+ s1.write_bedGraph( strio, "NAME", "DESC", 3 )
+ self.assertEqual( strio.getvalue(), self.bdg3 )
+
+ def test_callpeak ( self ):
+ s1 = scoreTrackII( self.treat_edm, self.ctrl_edm )
+ s1.add_chromosome( "chrY", 5 )
+ for a in self.test_regions1:
+ s1.add( a[0],a[1],a[2],a[3] )
+
+ s1.change_score_method( ord('p') )
+ p = s1.call_peaks( cutoff = 0.10, min_length=10, max_gap=10 )
+ strio = StringIO.StringIO()
+ p.write_to_bed( strio, trackline = False )
+ self.assertEqual( strio.getvalue(), self.peak1 )
+
+ strio = StringIO.StringIO()
+ p.write_to_summit_bed( strio, trackline = False )
+ self.assertEqual( strio.getvalue(), self.summit1 )
+
+ strio = StringIO.StringIO()
+ p.write_to_xls( strio )
+ self.assertEqual( strio.getvalue(), self.xls1 )
if __name__ == '__main__':
Please sign in to comment.
Something went wrong with that request. Please try again.