monkeybread.calc.cellular_niches
- monkeybread.calc.cellular_niches(adata, cell_type_key, radius, normalize_counts=True, standard_scale=True, clip_min=-5, clip_max=5, mask=None, n_neighbors=100, resolution=0.25, min_niche_size=0, key_added='niche', non_niche_value='other')
Compute cellular niches. Each cell is assigned to a “niche” that represents a set of colocalizing cells with a distinct cell type composition. To generate niches, for each cell, a neighborhood profile is calculated via
monkeybread.calc.neighborhood_profile(). These neighborhood profiles are then clustered. The cluster ID of each cell is its assigned niche.- Parameters:
adata – Annotated data matrix.
cell_type_key – A categorical column in
obsto use that stores the cell type of each cell to be used in generating the neighborhood profiles.radius – Radius in coordinate space to include nearby cells for neighborhood profile calculation.
normalize_counts (default:
True) – Normalize neighborhood counts to proportions instead of raw counts. Note, ifsubset_output_featuresis provided andnormalize_counts = True, the normalization step will be performed before removing groups, so proportions will not sum to 1.standard_scale (default:
True) – Compute z-score of neighborhood values by subtracting the mean and dividing by the standard deviation.clip_min (default:
-5) – Clip values that are less thanclip_mintoclip_minclip_max (default:
5) – Clip values that are greater thanclip_maxtoclip_maxmask (default:
None) – A Boolean-valued vector used to denote all cells for which a niche will be assigned. All cells that are filtered out will be assigned to a niche with the name provided by thenon_niche_valueargumentn_neighbors (default:
100) – Parameter toscanpy.pp.neighbors()that determines the number of neighbors used to generate the k-nearest neighbors graph of the neighborhood profiles that will then undergo graph clusteringresolution (default:
0.25) – Parameter toscanpy.tl.leiden()that determines the granularity of the clustering of the neighborhood profilesmin_niche_size (default:
0) – Consider only clusters larger than this value to denote cellular niches. Cells within any cluster that are smaller than this value will be assigned to a niche with the name provided by thenon_niche_valueargumentkey_added (default:
'niche') – Column name addedadata.obsthat stores each cell’s assigned nichenon_niche_value (default:
'other') – Cells that have been filtered out using themaskargument or that fall within a cluster smaller thanmin_niche_sizewill be assigned a niche with this name
- Returns:
: An AnnData object storing the neighborhood profiles as computed by
monkeybread.calc.neighborhood_profile()