grassp.tl.leiden_mito_sweep#
- leiden_mito_sweep(data, starting_resolution=0.5, resolution_increments=0.5, min_mito_fraction=0.9, increment_threshold=0.005, protein_ground_truth_column='protein_ground_truth', max_iter=50, **leiden_kwargs)[source]#
Automated sweep to pick a Leiden resolution that keeps mitochondria intact.
Starting from
starting_resolutionthe function iteratively increases or decreases the resolution (binary-search style) until mitochondrial proteins—identified viaprotein_ground_truth_column—remain grouped in a single Leiden cluster with at leastmin_mito_fractionof all mitochondrial proteins.The result is the highest resolution tried that kept more than
min_mito_fractiontogether. Its clusters are written todata.obs[key_added]("leiden"unlesskey_addedis passed throughleiden_kwargs), its resolution todata.uns[key_added]['params']['resolution']and the observed fraction todata.uns[key_added]['mito_majority_fraction'].- Parameters:
- data
AnnData anndata.AnnDataobject afterscanpy.pp.neighbors()with proteins as observations.- starting_resolution
float(default:0.5) Initial Leiden resolution from which to begin the sweep.
- resolution_increments
float(default:0.5) Step size added (or subtracted) each iteration; halved whenever the sweep crosses the
min_mito_fractionthreshold.- min_mito_fraction
float(default:0.9) Required proportion of mitochondrial proteins that must share a cluster (default
0.9).- increment_threshold
float(default:0.005) When the increment falls below this value the search terminates.
- protein_ground_truth_column
str(default:'protein_ground_truth') Observation column holding the curated ground-truth localisation with the category
"mitochondria".- max_iter
int(default:50) Maximum number of Leiden runs. If the search has not converged by then (e.g. the mitochondria stay together at every resolution tried), a warning is raised and the best resolution so far is kept.
- **leiden_kwargs
Extra parameters forwarded to
scanpy.tl.leiden()(e.g.random_state,key_added).
- data
- Return type:
- Returns:
Updates
data.obs[key_added]anddata.uns[key_added]in place.