def test_single_kmer(self): # given b = get_cortex_builder() b.with_kmer('AAA 1 ......G.') b.with_kmer('AAG 1 a.......') cdb = b.build() seed = 'AAA' # when / then assert [('AAA', 'AAG')] == list(cdb.out_edges(seed)) assert [] == list(cdb.in_edges(seed))
def test_nodes_returns_two_nodes(self): # given b = get_cortex_builder() b.with_kmer('AAA 1 .....C..') b.with_kmer('AAC 1 a.......') # when cortex_graph = b.build() # then assert {'AAA', 'AAC'} == set(cortex_graph.nodes())
def test_revcomps_a_kmer(): # given b = get_cortex_builder() b.with_kmer('AAA 1 ........') cdb = b.build() # when expect = KmerGraphExpectation( Interactor(cdb).make_graph_nodes_consistent({'TTT'}).graph) # then expect.has_node('TTT') expect.has_n_nodes(1)
def test_with_2_nodes_has_len_2(self): # given b = get_cortex_builder() b.with_kmer('AAA 1 .....C..') b.with_kmer('AAC 1 a.......') # when cdb = b.build() ucdb = make_multi_graph(cdb) # then assert 2 == len(cdb) assert 2 == len(ucdb)
def test_remove_nodes(self, removal_nodes): # given b = get_cortex_builder() b.with_kmer('AAA 1 .....C..') b.with_kmer('AAC 1 a....C..') b.with_kmer('ACC 1 a.......') nodes = {'AAC', 'AAA', 'ACC'} cdb = b.build() # when cdb.remove_nodes_from(removal_nodes) # then assert (nodes - set(removal_nodes)) == set(cdb.nodes())
def test_in_y_graph_finds_two_paths_of_revcomp(self): # given b = get_cortex_builder() b.with_kmer('CGC 1 .......T') b.with_kmer('AGC 1 a....CG.') b.with_kmer('AAG 1 .....C..') b.with_kmer('GCC 1 a.......') cdb = b.build() cdb = Interactor(cdb).make_graph_nodes_consistent(['AAG']).graph # when paths = list(Interactor(cdb).all_simple_paths()) # then assert ['AAGCC', 'AAGCG'] == sorted([str(p.seq) for p in paths])
def test_single_kmer_revcomp_seed(self, seed): # given b = get_cortex_builder() b.with_kmer('AAA 1 ......G.') b.with_kmer('AAG 1 a.......') cdb = b.build() # when graph = Interactor(cdb).make_graph_nodes_consistent([seed]).graph # then if seed == 'AAA': assert [] == list(graph.in_edges(seed)) assert [('AAA', 'AAG')] == list(graph.out_edges(seed)) else: assert [('CTT', 'TTT')] == list(graph.in_edges(seed)) assert [] == list(graph.out_edges(seed))
def test_neighbors_of_three_colors_returns_colors_0_and_2(self): # given b = get_cortex_builder() b.with_kmer('AAA 1 1 1 .....C.. ........ .....C..') b.with_kmer('AAC 1 1 1 a....... ........ a.......') # when cdb = b.build() # then assert {0, 2} == set(cdb.succ['AAA']['AAC']) assert set() == set(cdb.pred['AAA']['AAC']) assert {0, 2} == set(cdb['AAA']['AAC']) assert set() == set(cdb.succ['AAC']['AAA']) assert {0, 2} == set(cdb.pred['AAC']['AAA']) assert set() == set(cdb['AAC']['AAA'])
def test_revcomps_path(): # given b = get_cortex_builder() b.with_kmer('CGC 1 .......T') b.with_kmer('AGC 1 ......G.') cdb = b.build() for seed, expected_nodes in [('CGC', ['CGC', 'GCT']), ('GCT', ['CGC', 'GCT']), ('AGC', ['AGC', 'GCG']), ('GCG', ['AGC', 'GCG'])]: # when expect = KmerGraphExpectation( Interactor(cdb).make_graph_nodes_consistent([seed]).graph) # then expect.has_nodes(*expected_nodes) expect.has_n_nodes(2)
def test_remove_node(self, remove_first): # given b = get_cortex_builder() b.with_kmer('AAA 1 .....C..') b.with_kmer('AAC 1 a.......') cdb = b.build() # when if remove_first: cdb.remove_node('AAC') # then assert {'AAA'} == set(cdb.nodes()) else: cdb.remove_node('AAA') # then assert {'AAC'} == set(cdb.nodes())
def test_keys_y_graph(): # given b = get_cortex_builder() b.with_kmer('CGC 1 .......T') b.with_kmer('AGC 1 a....CG.') b.with_kmer('AAG 1 .....C..') b.with_kmer('GCC 1 a.......') expected_nodes1 = ['CGC', 'GCT', 'CTT', 'GGC'] expected_nodes2 = ['AAG', 'AGC', 'GCG', 'GCC'] for expected_nodes in [expected_nodes1, expected_nodes2]: for seed in expected_nodes: cdb = b.build() # when expect = KmerGraphExpectation( Interactor(cdb).make_graph_nodes_consistent([seed]).graph) # then expect.has_nodes(*expected_nodes)
def test_revcomps_many_kmers(data, num_kmers, kmer_size): # given kmers = {} for _ in range(num_kmers): kmer_string = data.draw(kmer_strings(min_size=kmer_size, max_size=kmer_size)) kmers[lexlo(kmer_string)] = kmer_string b = get_cortex_builder() for kmer in kmers.keys(): b.with_kmer('{} 1 ........'.format(kmer)) cdb = b.build() # when expect = KmerGraphExpectation( Interactor(cdb).make_graph_nodes_consistent(set(kmers.values())).graph) # then for kmer_string in kmers.values(): expect.has_node(kmer_string) expect.has_n_nodes(len(kmers))
def test_gets_correct_neighbors_of_kmer(self): # given b = get_cortex_builder() b.with_kmer('AAC 1 .......T') b.with_kmer('ACT 1 a.....G.') b.with_kmer('CAG 1 .......T') cdb = b.build() seed = 'AAC' # when graph = Interactor(cdb).make_graph_nodes_consistent([seed]).graph # then assert ['CTG'] == list(graph['ACT']) assert ['CTG'] == list(graph.succ['ACT']) assert ['AAC'] == list(graph.pred['ACT']) assert [('ACT', 'CTG')] == list(graph.out_edges('ACT')) assert [('AAC', 'ACT')] == list(graph.in_edges('ACT')) assert [] == list(graph['CTG']) assert [] == list(graph.succ['CTG']) assert ['ACT'] == list(graph.pred['CTG']) assert [] == list(graph.out_edges('CTG')) assert [('ACT', 'CTG')] == list(graph.in_edges('CTG'))