def test_sampling_example_graph2(): sif_file = join(dirname(__file__), 'korkut_stmts.sif') g = pg.load_signed_sif(sif_file) source = 'BLK' target = 'EIF4EBP1' enum_cf_paths = set( pg.enumerate_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=True)) sampled_cf_paths = set( pg.sample_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, num_samples=10000, cycle_free=True)) count_cf_paths = pg.count_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=True) # The sampled paths should be a subset of the enumerated paths assert sampled_cf_paths.intersection(enum_cf_paths) == sampled_cf_paths
def test_enumerate_example_graph2(): sif_file = join(dirname(__file__), 'korkut_stmts.sif') g = pg.load_signed_sif(sif_file) source = 'BLK' target = 'EIF4EBP1' enum_paths = pg.enumerate_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=False) assert len(enum_paths) == len(set(enum_paths)) enum_paths = set(enum_paths) count_paths = pg.count_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=False) enum_cf_paths = pg.enumerate_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=True) assert len(enum_cf_paths) == len(set(enum_cf_paths)) enum_cf_paths = set(enum_cf_paths) count_cf_paths = pg.count_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=True) # Check that the counts match the enumeratio assert len(enum_paths) == count_paths assert len(enum_cf_paths) == count_cf_paths # All of the cycle-free paths should be contained in the set of paths # with cycles assert enum_paths.intersection(enum_cf_paths) == enum_cf_paths # Check that all paths in the set difference contain cycles for path in enum_paths.difference(enum_cf_paths): assert len(set(path)) < len(path)
def test_uniform_sampling_example_graph1(): sif_file = join(dirname(__file__), 'korkut_im.sif') g = pg.load_signed_sif(sif_file) source = 'BLK_phosphoY389_phosphorylation_PTK2_Y397' target = 'EIF4EBP1_T37_p_obs' target_polarity = 0 length = 8 cfpg = pg.CFPG.from_graph(g, source, target, length, signed=True, target_polarity=0) os.environ['TEST_FLAG'] = 'TRUE' np.random.seed(1) # Count paths # Now, re-weight for uniformity and re-sample num_samples = cfpg.count_paths() * 1000 cfpg.set_uniform_path_distribution() sampled_paths_uni = cfpg.sample_paths(num_samples=num_samples) ctr_uni = Counter(sampled_paths_uni) for path, count in ctr_uni.items(): assert count > 900 and count < 1100
def test_example_graph1(): sif_file = join(dirname(__file__), 'korkut_im.sif') g = pg.load_signed_sif(sif_file) source = 'BLK_phosphoY389_phosphorylation_PTK2_Y397' target = 'EIF4EBP1_T37_p_obs' target_polarity = 0 enum_paths = pg.enumerate_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=False) assert len(enum_paths) == len(set(enum_paths)) enum_paths = set(enum_paths) sampled_paths = set( pg.sample_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, num_samples=10000, cycle_free=False)) count_paths = pg.count_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=False) assert len(sampled_paths) == len(enum_paths) assert len(sampled_paths) == count_paths assert sampled_paths == enum_paths enum_cf_paths = pg.enumerate_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=True) assert len(enum_cf_paths) == len(set(enum_cf_paths)) enum_cf_paths = set(enum_cf_paths) sampled_cf_paths = set( pg.sample_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, num_samples=10000, cycle_free=True)) count_cf_paths = pg.count_paths(g, source, target, signed=True, target_polarity=0, max_depth=8, cycle_free=True) assert len(sampled_cf_paths) == len(enum_cf_paths) assert len(sampled_cf_paths) == count_cf_paths assert sampled_cf_paths == enum_cf_paths # 101 cycle free paths assert count_cf_paths == 101 # All of the cycle-free paths should be contained in the set of paths # with cycles assert sampled_paths.intersection(sampled_cf_paths) == sampled_cf_paths # Check that all paths in the set difference contain cycles for path in sampled_paths.difference(sampled_cf_paths): assert len(set(path)) < len(path)