scviva.tools.vision.apply_micro_clustering#
- scviva.tools.vision.apply_micro_clustering(adata, cells_per_partition=10, filter_input=True, filter_threshold=None, filter_num_mad=2.0, latent_space_key=None, K=None, uns_key='micro_clusters', random_state=0)[source]#
Partition cells into micro-clusters (supercells) via Louvain + K-means.
Mirrors R VISION’s
applyMicroClustering.If latent_space_key is provided and present in
adata.obsm, those coordinates are used directly. Otherwise a lightweight internal PCA (max 10 components) is computed on log-transformed, filtered expression.- Parameters:
- adata
AnnData Annotated data matrix.
- cells_per_partition
int Target number of cells per micro-cluster, by default 10.
- filter_input
bool Apply threshold + fano gene filters before internal PCA, by default
True. Ignored when latent_space_key is provided.- filter_threshold
int|None Minimum expressing-cell count for the threshold filter. Defaults to
round(0.05 * n_cells)(matching R VISION’sapplyMicroClusteringdefault of 5% of cells) whenNone.- filter_num_mad
float MAD multiplier for the fano filter, by default 2.0.
- latent_space_key
str|None Key in
adata.obsmfor pre-computed latent-space coordinates. WhenNone(default), coordinates are computed internally.- K
int|None Number of KNN neighbors for the Louvain graph. Defaults to
min(round(sqrt(n_cells)), 30), matching R VISION (no lower floor – R’s own formula has none either).- uns_key
str Key under which the pool mapping is stored in
adata.uns, by default"micro_clusters".- random_state
int Seed for the internal PCA, Louvain clustering, and K-means readjustment steps, by default 0. Passing the same value across runs makes the whole micro-clustering pipeline reproducible.
- adata
- Return type:
- Returns:
dict mapping str → list[str]
pools["microcluster_<i>"]is the list ofobs_namesbelonging to that micro-cluster.