Exemplo n.º 1
0
    def test_emits_one_single_color_unitig(self):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0)
        b.add_edge('AAA', 'AAT', color=0)
        b.make_consistent('AAA')
        graph = b.build()

        # when
        paths = list(Interactor(graph).all_simple_paths())

        # then
        assert ['AAAT'] == [str(p.seq) for p in paths]
Exemplo n.º 2
0
    def test_two_colors_to_one_color_is_node_end(self, start_node, orientation):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        b.with_node_coverage('AAA', 1, 1)
        b.with_node_coverage('AAT', 1, 0)
        b.add_edge_with_color('AAA', 'AAT', 0)

        # when
        graph = b.build()

        # then
        search = UnitigSearch.from_node_and_graph(start_node, graph)
        assert search.is_unitig_end(start_node, orientation)
Exemplo n.º 3
0
    def test_follows_two_colors_with_no_color_specified(self):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        b.add_edge('AAA', 'AAT', color=0)
        b.add_edge('AAT', 'ATA', color=1)
        b.make_consistent('AAA')
        graph = b.build()

        # when
        paths = list(Interactor(graph).all_simple_paths())

        # then
        assert {'AAATA'} == set([str(p.seq) for p in paths])
Exemplo n.º 4
0
    def test_with_link_for_y_graph_emits_one_path(self):
        # given
        b = CortexGraphBuilder()
        b.with_kmer_size(3)
        b.add_path('AAA', 'AAC')
        b.add_path('AAA', 'AAT')
        b.make_consistent('AAA')
        cdb = b.build()

        links = LinksBuilder() \
            .with_link_for_kmer('F 1 1 C', 'AAA') \
            .build()

        # when
        paths = list(Interactor(cdb).all_simple_paths(links=links))

        # then
        assert ['AAAC'] == [str(p.seq) for p in paths]
Exemplo n.º 5
0
    def test_in_y_graph_finds_two_paths(self):
        # given
        b = CortexGraphBuilder()
        b.add_path('CAA', 'AAA')
        b.add_path('TAA', 'AAA')
        b.make_consistent('AAA')
        cdb = b.build()

        # when
        paths = list(Interactor(cdb).all_simple_paths())

        # then
        assert {'CAAA', 'TAAA'} == set([str(p.seq) for p in paths])
Exemplo n.º 6
0
    def test_two_connected_nodes_are_a_unitig(self, num_colors):
        # given
        colors = list(range(num_colors))
        coverage = [1] + [0 for _ in range(1, num_colors)]

        b = CortexGraphBuilder()
        b.with_colors(*colors)
        b.with_node_coverage('AAA', *coverage)
        b.with_node_coverage('AAT', *coverage)
        b.add_edge_with_color('AAA', 'AAT', 0)

        # when
        graph = b.build()

        # then
        search = UnitigSearch.from_node_and_graph('AAA', graph)
        assert not search.is_unitig_end('AAA', EdgeTraversalOrientation.original)
        assert search.is_unitig_end('AAA', EdgeTraversalOrientation.reverse)

        search = UnitigSearch.from_node_and_graph('AAT', graph)
        assert search.is_unitig_end('AAT', EdgeTraversalOrientation.original)
        assert not search.is_unitig_end('AAT', EdgeTraversalOrientation.reverse)
Exemplo n.º 7
0
    def test_returns_two_nodes_in_order_regardless_of_starting_node(self, start_node):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0)
        b.add_path('AAA', 'AAT', 'ATA')

        # when
        graph = b.build()

        # then
        search = UnitigSearch.from_node_and_graph(start_node, graph)
        assert ['AAT', 'ATA'] == list(
            search.next_unitig_node_iter(EdgeTraversalOrientation.original,
                                         start_node='AAA'))
        assert ['AAT', 'AAA'] == list(search.next_unitig_node_iter(EdgeTraversalOrientation.reverse,
                                                                   start_node='ATA'))
Exemplo n.º 8
0
    def test_multi_color_y_graph_always_has_three_unitigs(self, data, num_colors, orientation):
        # given
        colors = list(range(num_colors))
        edge_colors = [data.draw(s.sampled_from(colors)) for _ in range(3)]

        b = CortexGraphBuilder()
        b.with_colors(*colors)
        for edge_color in edge_colors:
            b.add_edge_with_color_and_coverage('AAA', 'AAT', edge_color, color_coverage=1)
        b.add_edge_with_color_and_coverage('AAT', 'ATA', edge_colors[1], color_coverage=1)
        b.add_edge_with_color_and_coverage('AAT', 'ATC', edge_colors[2], color_coverage=1)

        # when
        graph = b.build()

        # then
        for node in ['ATA', 'ATC']:
            search = UnitigSearch.from_node_and_graph(node, graph)
            search.is_unitig_end(node, orientation)
        search = UnitigSearch.from_node_and_graph('AAA', graph)
        assert not search.is_unitig_end('AAA', EdgeTraversalOrientation.original)
        assert search.is_unitig_end('AAA', EdgeTraversalOrientation.reverse)
        assert search.is_unitig_end('AAT', EdgeTraversalOrientation.original)
        assert not search.is_unitig_end('AAT', EdgeTraversalOrientation.reverse)
Exemplo n.º 9
0
    def test_prunes_three_tips_of_length_1_reverse_kmer(self, seed_and_expected_kmer):
        # given
        seed, expected_kmer = seed_and_expected_kmer
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        kmers = ['AAC', 'ACT', 'AAG', 'CAG']
        for kmer in kmers:
            b.add_node(kmer)
        b.add_edge(kmers[0], kmers[1], 0)
        b.add_edge(kmers[0], kmers[1], 1)
        b.add_edge(kmers[1], kmers[2], 0)
        b.add_edge(kmers[1], kmers[3], 1)
        graph = b.build()

        # when
        graph = interactor.Interactor(graph).prune_tips_less_than(2).graph

        # then
        assert 1 == len(graph)
        assert {expected_kmer} == set(graph.nodes)
Exemplo n.º 10
0
    def test_prunes_one_tip_of_length_1_in_y(self):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        kmers = ['AAA', 'AAC', 'ACC', 'CCC', 'ACG', 'CGC']
        for kmer in kmers:
            b.add_node(kmer)
        b.add_edge('AAA', 'AAC', 0)
        b.add_edge('AAA', 'AAC', 1)
        b.add_edge('AAC', 'ACC', 0)
        b.add_edge('ACC', 'CCC', 0)
        b.add_edge('AAC', 'ACG', 1)
        b.add_edge('ACG', 'CGC', 1)
        graph = b.build()

        # when
        graph = interactor.Interactor(graph) \
            .prune_tips_less_than(2) \
            .graph

        # then
        assert set(kmers[1:]) == set(graph.nodes)
        assert 5 == len(graph)
Exemplo n.º 11
0
    def test_prunes_three_tips_of_length_1(self):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        kmers = ['AAA', 'AAC', 'ACC', 'ACG']
        for kmer in kmers:
            b.add_node(kmer)
        b.add_edge(kmers[0], kmers[1], 0)
        b.add_edge(kmers[0], kmers[1], 1)
        b.add_edge(kmers[1], kmers[2], 0)
        b.add_edge(kmers[1], kmers[3], 1)
        graph = b.build()

        # when
        graph = interactor.Interactor(graph) \
            .prune_tips_less_than(2) \
            .graph

        # then
        assert 1 == len(graph)
        assert {'AAC'} == set(graph.nodes)
Exemplo n.º 12
0
    def test_two_colors_to_two_nodes_in_first_color_is_node_end(self):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        b.with_node_coverage('AAA', 1, 1)
        b.with_node_coverage('AAT', 1, 0)
        b.with_node_coverage('AAC', 1, 0)
        b.add_edge_with_color('AAA', 'AAT', 0)
        b.add_edge_with_color('AAA', 'AAC', 0)

        # when
        graph = b.build()

        # then
        for orientation in EdgeTraversalOrientation:
            for node in ['AAA', 'AAT', 'AAC']:
                search = UnitigSearch.from_node_and_graph(node, graph)
                assert search.is_unitig_end(node, orientation)
Exemplo n.º 13
0
    def test_middle_unconnected_node_for_one_color_in_two_color_graph_results_in_three_unitigs(
        self, start_node, orientation
    ):
        # given
        b = CortexGraphBuilder()
        b.with_colors(0, 1)
        b.with_node_coverage('AAA', 1, 1)
        b.with_node_coverage('AAT', 1, 1)
        b.with_node_coverage('ATA', 1, 1)
        b.add_edge_with_color('AAA', 'AAT', 0)
        b.add_edge_with_color('AAT', 'ATA', 0)

        # when
        graph = b.build()
        search = UnitigSearch.from_node_and_graph(start_node, graph)
        assert search.is_unitig_end(start_node, orientation)
Exemplo n.º 14
0
    def test_bubble_and_y_with_two_links_returns_three_transcripts(self):
        # given
        links = LinksBuilder() \
            .with_link_for_kmer('F 2 1 CT', 'AAA') \
            .with_link_for_kmer('F 1 1 G', 'AAA') \
            .build()

        b = CortexGraphBuilder()
        b.with_kmer_size(3)
        b.add_path('AAA', 'AAC', 'ACC', 'CCC', 'CCA')
        b.add_path('AAA', 'AAG', 'AGC', 'GCC', 'CCC', 'CCT')
        b.make_consistent('AAA')
        cdb = b.build()

        # when
        paths = list(Interactor(cdb).all_simple_paths(links=links))

        # then
        assert ['AAACCCT', 'AAAGCCCA',
                'AAAGCCCT'] == sorted([str(p.seq) for p in paths])