import networkx
from typing import Counter


def make_debruijn_graph(kmers):
    """Constructs a de Bruijn graph from a list of kmers.

    Parameters
    ----------
        kmers: list of str

    Returns
    -------
        dbg: networkx.DiGraph
            In this graph, multi-edges are collapsed into a single edge.
            Coverage information (i.e. how many times a given edge was present
            in the input k-mer data) is stored in the 'cov' attribute of the
            edge.
    """
    g = networkx.DiGraph()
    edge_counter = Counter()
    for kmer in kmers:
        prefix = kmer[:-1]
        suffix = kmer[1:]
        edge_counter[(prefix, suffix)] += 1
    for edge in edge_counter:
        g.add_edge(edge[0], edge[1], cov=edge_counter[edge])
    return g