예제 #1
0
def main(argv):
    kmers = files.read_lines(argv[0])

    edges = graphs.debruijn_graph(kmers)
    adj = graphs.adjacency_table(edges)

    print '\n'.join('%s -> %s' % (head, ','.join(sorted(adj[head])))
                    for head in sorted(adj))
예제 #2
0
def main(argv):
    n, m, edges = files.read_graph(argv[0])
    adjacency = graphs.adjacency_table(edges, directed=False)
    D = []

    for i in xrange(1, n + 1):
        D.append(sum(len(adjacency[node]) for node in adjacency[i]))

    print ' '.join(str(d) for d in D)
예제 #3
0
def main(argv):
    lines = files.read_lines(argv[0])
    k = int(lines[0])
    text = lines[1]

    kmers = genetics.list_kmers(text, k)
    edges = graphs.debruijn_graph(kmers)
    adj = graphs.adjacency_table(edges)

    print '\n'.join('%s -> %s' % (head, ','.join(sorted(adj[head])))
                    for head in sorted(adj))
예제 #4
0
def assemble_genome_from_reads(reads):
    length = len(reads[0])

    for i in xrange(length - 1, 1, -1):
        kmers = kmer_candidates(reads, i, rc=True)
        edges = graphs.debruijn_graph(kmers)
        adj = graphs.adjacency_table(edges)

        if len(graphs.connected_components_iterative(adj)) == 2:
            path = graphs.eulerian_cycle(edges[0][1], edges)
            return reconstruct_circular_string_from_path(path)

    return None
예제 #5
0
def two_break_distance(P, Q):
    edges = set()

    for genome in [P, Q]:
        for edge in colored_edges_from_genome(genome):
            edges.add(edge)

    # nodes      = graphs.nodes_from_edges(edges)
    # components = graphs.connected_components(nodes, edges, False)

    adjacency = graphs.adjacency_table(edges, False)
    components = graphs.connected_components_iterative(adjacency)

    return sum(len(g) for g in P) - len(components)