def test_named_indices(self): parent_regions = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr10'], 'start': [100, 200], 'end': [160, 220]}, index=['foo', 'bar'])) # Edges edge_regions = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr10'], 'start': [100, 215], 'end': [110, 220]}, index=['foo', 'bar'])) correct_ans = {'foo': np.array([0, 1]), 'bar': np.array([3])} self.assert_numpy_dicts_equal(correct_ans, edge_regions.as_bins_of(parent_regions, resolution=5)) # Middle mid_regions = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr10'], 'start': [140, 208], 'end': [145, 212]}, index=['foo', 'bar'])) correct_ans = {'foo': np.array([8]), 'bar': np.array([1, 2])} self.assert_numpy_dicts_equal(correct_ans, mid_regions.as_bins_of(parent_regions, resolution=5)) # Middle, without one index mid_regions2 = Regions(pd.DataFrame({'chromosome': ['chr10'], 'start': [208], 'end': [212]}, index=['bar'])) correct_ans = {'bar': np.array([1, 2])} self.assert_numpy_dicts_equal(correct_ans, mid_regions2.as_bins_of(parent_regions, resolution=5)) length_one_regions = Regions(pd.DataFrame({'chromosome': ['chr1'], 'start': [140], 'end': [141]}, index=['foo'])) correct_ans = {'foo': np.array([8])} self.assert_numpy_dicts_equal(correct_ans, length_one_regions.as_bins_of(parent_regions, resolution=5)) regions_not_in_parent = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr2'], 'start': [140, 200], 'end': [141, 300]}, index=['foo', 'baz'])) correct_ans = {'foo': np.array([8])} self.assert_numpy_dicts_equal(correct_ans, regions_not_in_parent.as_bins_of(parent_regions, resolution=5))
def test_bins_calculated_correctly(self): parent_regions = Regions( pd.DataFrame({ 'chromosome': ['chr1', 'chr10'], 'start': [100, 200], 'end': [160, 220] })) # Edges edge_regions = Regions( pd.DataFrame({ 'chromosome': ['chr1', 'chr10'], 'start': [100, 215], 'end': [110, 220] })) correct_ans = {0: np.array([0, 1]), 1: np.array([3])} self.assert_numpy_dicts_equal( correct_ans, edge_regions.as_bins_of(parent_regions, resolution=5)) # Middle mid_regions = Regions( pd.DataFrame({ 'chromosome': ['chr1', 'chr10'], 'start': [140, 208], 'end': [145, 212] })) correct_ans = {0: np.array([8]), 1: np.array([1, 2])} self.assert_numpy_dicts_equal( correct_ans, mid_regions.as_bins_of(parent_regions, resolution=5)) # Middle, without one index mid_regions2 = Regions( pd.DataFrame( { 'chromosome': ['chr10'], 'start': [208], 'end': [212] }, index=[1])) correct_ans = {1: np.array([1, 2])} self.assert_numpy_dicts_equal( correct_ans, mid_regions2.as_bins_of(parent_regions, resolution=5)) length_one_regions = Regions( pd.DataFrame({ 'chromosome': ['chr1'], 'start': [140], 'end': [141] })) correct_ans = {0: np.array([8])} self.assert_numpy_dicts_equal( correct_ans, length_one_regions.as_bins_of(parent_regions, resolution=5))
def test_bins_calculated_correctly(self): parent_regions = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr10'], 'start': [100, 200], 'end': [160, 220]})) # Edges edge_regions = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr10'], 'start': [100, 215], 'end': [110, 220]})) correct_ans = {0: np.array([0, 1]), 1: np.array([3])} self.assert_numpy_dicts_equal(correct_ans, edge_regions.as_bins_of(parent_regions, resolution=5)) # Middle mid_regions = Regions(pd.DataFrame({'chromosome': ['chr1', 'chr10'], 'start': [140, 208], 'end': [145, 212]})) correct_ans = {0: np.array([8]), 1: np.array([1, 2])} self.assert_numpy_dicts_equal(correct_ans, mid_regions.as_bins_of(parent_regions, resolution=5)) # Middle, without one index mid_regions2 = Regions(pd.DataFrame({'chromosome': ['chr10'], 'start': [208], 'end': [212]}, index=[1])) correct_ans = {1: np.array([1, 2])} self.assert_numpy_dicts_equal(correct_ans, mid_regions2.as_bins_of(parent_regions, resolution=5)) length_one_regions = Regions(pd.DataFrame({'chromosome' : ['chr1'], 'start': [140], 'end': [141]})) correct_ans = {0: np.array([8])} self.assert_numpy_dicts_equal(correct_ans, length_one_regions.as_bins_of(parent_regions, resolution=5))
def test_named_indices(self): parent_regions = Regions( pd.DataFrame( { 'chromosome': ['chr1', 'chr10'], 'start': [100, 200], 'end': [160, 220] }, index=['foo', 'bar'])) # Edges edge_regions = Regions( pd.DataFrame( { 'chromosome': ['chr1', 'chr10'], 'start': [100, 215], 'end': [110, 220] }, index=['foo', 'bar'])) correct_ans = {'foo': np.array([0, 1]), 'bar': np.array([3])} self.assert_numpy_dicts_equal( correct_ans, edge_regions.as_bins_of(parent_regions, resolution=5)) # Middle mid_regions = Regions( pd.DataFrame( { 'chromosome': ['chr1', 'chr10'], 'start': [140, 208], 'end': [145, 212] }, index=['foo', 'bar'])) correct_ans = {'foo': np.array([8]), 'bar': np.array([1, 2])} self.assert_numpy_dicts_equal( correct_ans, mid_regions.as_bins_of(parent_regions, resolution=5)) # Middle, without one index mid_regions2 = Regions( pd.DataFrame( { 'chromosome': ['chr10'], 'start': [208], 'end': [212] }, index=['bar'])) correct_ans = {'bar': np.array([1, 2])} self.assert_numpy_dicts_equal( correct_ans, mid_regions2.as_bins_of(parent_regions, resolution=5)) length_one_regions = Regions( pd.DataFrame({ 'chromosome': ['chr1'], 'start': [140], 'end': [141] }, index=['foo'])) correct_ans = {'foo': np.array([8])} self.assert_numpy_dicts_equal( correct_ans, length_one_regions.as_bins_of(parent_regions, resolution=5)) regions_not_in_parent = Regions( pd.DataFrame( { 'chromosome': ['chr1', 'chr2'], 'start': [140, 200], 'end': [141, 300] }, index=['foo', 'baz'])) correct_ans = {'foo': np.array([8])} self.assert_numpy_dicts_equal( correct_ans, regions_not_in_parent.as_bins_of(parent_regions, resolution=5))