def allele_clusters ( dists , t = 0.025 ) : clusters = fcluster ( linkage ( dists ) , 0.025 , criterion = 'distance' ) cluster_idx = defaultdict ( list ) for idx , cl in enumerate ( clusters ) : cluster_idx [ cl ] . append ( idx ) return cluster_idx
hierarchical clustering python precomputed distance matrix
Flat clusters from distance matrix
def allele_clusters(dists, t=0.025):
    """Flat clusters from distance matrix

    Args:
        dists (numpy.array): pdist distance matrix
        t (float): fcluster (tree cutting) distance threshold

    Returns:
        dict of lists: cluster number to list of indices of distances in cluster
    """
    clusters = fcluster(linkage(dists), 0.025, criterion='distance')
    cluster_idx = defaultdict(list)
    for idx, cl in enumerate(clusters):
        cluster_idx[cl].append(idx)
    return cluster_idx