grassp.tl.leiden_mito_sweep

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_resolution the function iteratively increases or decreases the resolution (binary-search style) until mitochondrial proteins—identified via protein_ground_truth_column—remain grouped in a single Leiden cluster with at least min_mito_fraction of all mitochondrial proteins.

The result is the highest resolution tried that kept more than min_mito_fraction together. Its clusters are written to data.obs[key_added] ("leiden" unless key_added is passed through leiden_kwargs), its resolution to data.uns[key_added]['params']['resolution'] and the observed fraction to data.uns[key_added]['mito_majority_fraction'].

Parameters:
data AnnData

anndata.AnnData object after scanpy.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_fraction threshold.

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).

Return type:

None

Returns:

Updates data.obs[key_added] and data.uns[key_added] in place.