1#!/usr/bin/env python 2# Time-stamp: <2019-08-09 14:19:31 taoliu> 3 4import unittest 5 6from MACS2.IO.FixWidthTrack import * 7 8class Test_FWTrack(unittest.TestCase): 9 10 def setUp(self): 11 12 self.input_regions = [(b"chrY",0,0 ), 13 (b"chrY",90,0 ), 14 (b"chrY",150,0 ), 15 (b"chrY",70,0 ), 16 (b"chrY",80,0 ), 17 (b"chrY",85,0 ), 18 (b"chrY",85,0 ), 19 (b"chrY",85,0 ), 20 (b"chrY",85,0 ), 21 (b"chrY",90,1 ), 22 (b"chrY",150,1 ), 23 (b"chrY",70,1 ), 24 (b"chrY",80,1 ), 25 (b"chrY",80,1 ), 26 (b"chrY",80,1 ), 27 (b"chrY",85,1 ), 28 (b"chrY",90,1 ), 29 ] 30 self.fw = 50 31 32 def test_add_loc(self): 33 # make sure the shuffled sequence does not lose any elements 34 fw = FWTrack(fw=self.fw) 35 for ( c, p, s ) in self.input_regions: 36 fw.add_loc(c, p, s) 37 fw.finalize() 38 # roughly check the numbers... 39 self.assertEqual( fw.total, 17 ) 40 self.assertEqual( fw.length, 17*self.fw ) 41 42 def test_filter_dup(self): 43 # make sure the shuffled sequence does not lose any elements 44 fw = FWTrack(fw=self.fw) 45 for ( c, p, s ) in self.input_regions: 46 fw.add_loc(c, p, s) 47 fw.finalize() 48 # roughly check the numbers... 49 self.assertEqual( fw.total, 17 ) 50 self.assertEqual( fw.length, 17*self.fw ) 51 52 # filter out more than 3 tags 53 fw.filter_dup( 3 ) 54 # one chrY:85:0 should be removed 55 self.assertEqual( fw.total, 16 ) 56 57 # filter out more than 2 tags 58 fw.filter_dup( 2 ) 59 # then, one chrY:85:0 and one chrY:80:- should be removed 60 self.assertEqual( fw.total, 14 ) 61 62 # filter out more than 1 tag 63 fw.filter_dup( 1 ) 64 # then, one chrY:85:0 and one chrY:80:1, one chrY:90:1 should be removed 65 self.assertEqual( fw.total, 11 ) 66 67 68 def test_sample_num(self): 69 # make sure the shuffled sequence does not lose any elements 70 fw = FWTrack(fw=self.fw) 71 for ( c, p, s ) in self.input_regions: 72 fw.add_loc(c, p, s) 73 fw.finalize() 74 # roughly check the numbers... 75 self.assertEqual( fw.total, 17 ) 76 self.assertEqual( fw.length, 17*self.fw ) 77 78 fw.sample_num( 10 ) 79 self.assertEqual( fw.total, 9 ) 80 81 def test_sample_percent(self): 82 # make sure the shuffled sequence does not lose any elements 83 fw = FWTrack(fw=self.fw) 84 for ( c, p, s ) in self.input_regions: 85 fw.add_loc(c, p, s) 86 fw.finalize() 87 # roughly check the numbers... 88 self.assertEqual( fw.total, 17 ) 89 self.assertEqual( fw.length, 17*self.fw ) 90 91 fw.sample_percent( 0.5 ) 92 self.assertEqual( fw.total, 8 ) 93 94