def to_graph(alnfname, weight_func):
    """Create a NetworkX graph from a sequence alignment.

    Nodes are string sequence IDs; edge weights are the output of weight_func
    between each pair, by default the absolute identity (# identical chars).
    """
    import networkx
    G = networkx.Graph()
    aln = AlignIO.read(alnfname, 'fasta')
    for i, arec in enumerate(aln):
        for brec in aln[i+1:]:
            ident = weight_func(str(arec.seq), str(brec.seq))
            G.add_edge(arec.id, brec.id, weight=ident)
    return G
def to_graph ( alnfname , weight_func ) : import networkx G = networkx . Graph ( ) aln = AlignIO . read ( alnfname , 'fasta' ) for i , arec in enumerate ( aln ) : for brec in aln [ i + 1 : ] : ident = weight_func ( str ( arec . seq ) , str ( brec . seq ) ) G . add_edge ( arec . id , brec . id , weight = ident ) return G
Create a NetworkX graph from a sequence alignment.

    Nodes are string sequence IDs; edge weights are the output of weight_func
    between each pair, by default the absolute identity (# identical chars).