Clusterizer¶
damicore_clusterizer partitions the tree graph with FastGreedy community detection.
Functions¶
- damicore_clusterizer.cluster_tree(tree_path: str | Path, output_dir: str | Path, *, config: ClusterConfig | None = None) ClusterResult¶
Cluster every node in an unrooted tree and project communities to leaves.
Takes
tree.jsonas the tree stage writes it and runs FastGreedy over the whole tree graph, internal nodes included, then keeps only the leaves of each community. A community made entirely of internal nodes therefore disappears, which is whycluster_countcan be lower thancommunity_count. Cluster numbers are assigned by sorting the groups by their object ids, so the numbering depends on the tree rather than on FastGreedy’s internal ordering. Writesmembership.csvandclusters.jsonintooutput_dir; both must be absent, since neither is overwritten.output_diris created before that check, so a call rejected for the conflict still leaves the directory behind.- Raises:
ClusterizerError –
config.num_clustersexceeds the leaf count (configuration_error); the tree artifact is missing, unparsable, not a valid unrooted binary tree, or carries a branch length of zero or too small for a finite reciprocal weight (tree_format_error); the resulting communities do not cover every leaf (clusterization_error); the outputs already exist (output_directory_conflict_error).