예제 #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]
예제 #2
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])
예제 #3
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)
예제 #4
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)
예제 #5
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)