vampire.anno.tl.haplotype_leiden#
- vampire.anno.tl.haplotype_leiden(adata, resolution=1.0, *, random_state=0, sort_by='sample_size', store_key='haplotype')[source]#
Cluster samples into haplotypes using Leiden on the fused graph.
Reads the fused connectivities built by
haplotype_neighbor(), runs the Leiden algorithm, builds a consensus sequence for each detected cluster, and stores haplotype labels inadata.obs.- Parameters:
adata (
AnnData) – Annotated data with fused connectivities.resolution (
float) – Leiden resolution parameter. Higher values yield more clusters.random_state (
int) – Random seed for Leiden.sort_by (
str) – How to order the resulting haplotype labels."sample_size"(default) sorts by the number of samples in each cluster (largest → H1)."copy_number"sorts by the average non-gap motif count per cluster (largest → H1).store_key (
str) – Key prefix. Must match the value used inhaplotype_neighbor().
- Return type:
AnnData- Returns:
adata – Updated in-place with:
obs[f"{store_key}"]— haplotype labels (category)uns[f"{store_key}_consensus"]— consensus per haplotype
Examples
——–
>>> import vampire as vp
>>> vp.anno.pl.set_default_plotstyle()
>>> adata = vp.datasets.wdr7_hprc()
>>> vp.anno.tl.sample_msa(adata)
>>> vp.anno.tl.haplotype_neighbor(adata, metrics=[“structural”, “composition”])
>>> vp.anno.tl.haplotype_leiden(
>>> adata,
>>> resolution = 1.0
>>> )