def make_cluster_column(ATelement,Elementclusters): cluster = [] for i in ATelement.T.index: included=False for j in Elementclusters.keys(): if i in Elementclusters[j]: cluster.append(j) included=True if not included: cluster.append(None) return cluster
def clusters_at(tree, sampled, cutpoint): """ returns a list of lists of clusters occuring after cutpoint """ branches = branches_sampled(tree, sampled) branches = list(branches) branches.sort(key=lambda x: x.i_time) clusters = [] for branch in branches: if branch.i_time > cutpoint: children = all_children_of(tree, branch) if branch in sampled: children.append(branch) cluster = [] for child in children: if child in sampled: cluster.append(child) sampled.remove(child) clusters.append(cluster) return clusters
def brown_clusters(tree, sampled, s_time): """ returns a list of lists of clusters in tree according to the standard in Brown et al. """ cbound = s_time - 12 clusterlist = [] clustered = [] bpoints = branches_sampled(tree, sampled) for bp in sorted(bpoints, key=lambda x: x.i_time): if bp.i_time >= cbound: cluster = [] childs = all_children_of(tree, bp) print childs for cbp in childs: if cbp in sampled and cbp not in clustered: cluster.append(cbp) clustered.append(cbp) clusterlist.append(cluster) print len(clustered), clustered return clusterlist
def get_cluster(id, labels): cluster = [] for i in range(len(labels)): if labels[i] == id: cluster.append(i) return cluster