def test_add_pos_and_negbinary_areas(self): touched_nodes = set() graph = obg.Graph({1: obg.Block(100)}, {}) pos_starts = np.array([0] + [i * 10 for i in range(9)]) pos_ends = np.array([100] + [(i + 2) * 10 for i in range(9)]) neg_starts = np.array([0] + [i * 10 + 5 for i in range(9)]) neg_ends = np.array([100] + [(i + 1) * 10 + 5 for i in range(9)]) bin_areas = [] for start, end in zip(pos_starts, pos_ends): binary_connected_areas = BinaryContinousAreas(graph) binary_connected_areas.add(1, start, end) binary_connected_areas.sanitize() bin_areas.append(binary_connected_areas) for start, end in zip(neg_starts, neg_ends): binary_connected_areas = BinaryContinousAreas(graph) binary_connected_areas.add(-1, start, end) binary_connected_areas.sanitize() bin_areas.append(binary_connected_areas) valued_areas = ValuedAreas(graph) for bin_area in bin_areas: valued_areas.add_binary_areas(bin_area, touched_nodes=touched_nodes) true_starts = np.sort(np.concatenate([pos_starts, 100 - neg_ends])) true_ends = np.sort(np.concatenate([pos_ends, 100 - neg_starts])) self.assertTrue( np.all(np.sort(valued_areas.get_starts_array(1)) == true_starts)) self.assertTrue( np.all(np.sort(valued_areas.get_ends_array(1)) == true_ends))
def graph(): return obg.Graph({i + 1: obg.Block(10) for i in range(4)}, { 1: [2, 3], 2: [4], 3: [4] })
def hierarchical_graph(): nodes = {i: obg.Block(i - 90) for i in range(100, 106)} edges = { 100: [101, 102], 101: [105], 102: [103, 104], 103: [105], 104: [105] } return obg.Graph(nodes, edges)
def snp_graph(): nodes = {i: obg.Block((i % 2) + 1) for i in range(100, 106)} edges = { 100: [101, 102], 101: [105], 102: [103, 104], 103: [105], 104: [105] } return obg.Graph(nodes, edges)
def graph(): nodes = {i: obg.Block(10) for i in range(10, 18)} edges = { 10: [11], 11: [12, 13], 12: [14], 13: [14], 14: [15, 16, 17], 15: [16], 16: [17] } return obg.Graph(nodes, edges)
def test_add_binary_areas(self): touched_nodes = set() graph = obg.Graph({1: obg.Block(100)}, {}) starts = np.array([0] + [i * 10 for i in range(9)]) ends = np.array([100] + [(i + 2) * 10 for i in range(9)]) bin_areas = [] for start, end in zip(starts, ends): binary_connected_areas = BinaryContinousAreas(graph) binary_connected_areas.add(1, start, end) binary_connected_areas.sanitize() bin_areas.append(binary_connected_areas) valued_areas = ValuedAreas(graph) for bin_area in bin_areas: valued_areas.add_binary_areas(bin_area, touched_nodes=touched_nodes) self.assertTrue( np.all(valued_areas.get_starts_array(1) == np.sort(starts))) self.assertTrue( np.all(valued_areas.get_ends_array(1) == np.sort(ends)))
def test_get_p_value_track(self): graph = one_block_graph sample_intervals = [ Interval(1, 10, [1], graph), Interval(5, 7, [1], graph) ] control_intervals = [Interval(0, 10, [1], graph)] sample = Pileup(graph) sample.add_intervals(sample_intervals) control = Pileup(graph) control.add_intervals(control_intervals) self._test_get_p_value_track(graph, sample, control) # case 2 graph = offsetbasedgraph.Graph({1: Block(10), 2: Block(10)}, {1: [2]}) sample_intervals = [ Interval(1, 10, [1], graph), Interval(5, 7, [1], graph), Interval(4, 6, [1], graph), Interval(0, 10, [2], graph), Interval(1, 3, [2], graph) ] control_intervals = [ Interval(0, 10, [1], graph), Interval(0, 10, [2], graph), Interval(5, 5, [1, 2], graph) ] sample = Pileup(graph) sample.add_intervals(sample_intervals) control = Pileup(graph) control.add_intervals(control_intervals) self._test_get_p_value_track(graph, sample, control)
def graph(): nodes = [9, 10, 11, 12, 13, 14] nodes = {i: obg.Block(10) for i in nodes} edges = {9: [10], 10: [11, 12], 11: [13], 12: [13], 13: [14]} return obg.Graph(nodes, edges)
def graph(): nodes = {i: obg.Block(5) for i in range(1, 5)} edges = {1: [2, 3], 2: [4], 3: [4]} return obg.Graph(nodes, edges)