ins[v] += 1
    print('ins', ins)
    print('outs', outs)

    contig_starts = [v for v, out in outs.items() if not (out in (0, 1) and ins[v] == 1)]
    print('contig_starts', contig_starts)

    contigs = []
    for start in contig_starts:
        while graph[start]:  # multiple edges
            path = [start]
            u = graph[start].pop()
            while ins[u] == outs[u] == 1:
                path.append(u)
                u = graph[u].pop()
            contigs.append(''.join(v[0] for v in path) + u)

    return contigs


if __name__ == '__main__':
    #dataset, test_contigs = big_example()
    dataset = read_dataset()

    dataset = [l.lower() for l in dataset]
    adjlist = debruijn_graph(dataset)
    contigs = sorted(assemble_contigs(adjlist))
    #print(len(contigs))
    #test_contigs = sorted(test_contigs)
    #print(len(test_contigs))
    write_result('\n'.join(sorted(contigs)))
Esempio n. 2
0
    print('outs', outs)

    contig_starts = [
        v for v, out in outs.items() if not (out in (0, 1) and ins[v] == 1)
    ]
    print('contig_starts', contig_starts)

    contigs = []
    for start in contig_starts:
        while graph[start]:  # multiple edges
            path = [start]
            u = graph[start].pop()
            while ins[u] == outs[u] == 1:
                path.append(u)
                u = graph[u].pop()
            contigs.append(''.join(v[0] for v in path) + u)

    return contigs


if __name__ == '__main__':
    #dataset, test_contigs = big_example()
    dataset = read_dataset()

    dataset = [l.lower() for l in dataset]
    adjlist = debruijn_graph(dataset)
    contigs = sorted(assemble_contigs(adjlist))
    #print(len(contigs))
    #test_contigs = sorted(test_contigs)
    #print(len(test_contigs))
    write_result('\n'.join(sorted(contigs)))
from itertools import product
from common import small_example, big_example, read_dataset, write_result
from eulerian_cycle import eulerian_path, eulerian_cycle
from debruijn import debruijn_graph


if __name__ == '__main__':
    kmers = (''.join(kmer) for kmer in product('01', repeat=17))
    adjlist = debruijn_graph(kmers)
    cycle = eulerian_cycle(adjlist)

    output = ''.join(kmer[0] for kmer in cycle[:-1])
    write_result(output)
from itertools import product
from common import small_example, big_example, read_dataset, write_result
from eulerian_cycle import eulerian_path, eulerian_cycle
from debruijn import debruijn_graph

if __name__ == '__main__':
    kmers = (''.join(kmer) for kmer in product('01', repeat=17))
    adjlist = debruijn_graph(kmers)
    cycle = eulerian_cycle(adjlist)

    output = ''.join(kmer[0] for kmer in cycle[:-1])
    write_result(output)