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 obs to 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, if subset_output_features is provided and normalize_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 than clip_min to clip_min

  • clip_max (default: 5) – Clip values that are greater than clip_max to clip_max

  • mask (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 the non_niche_value argument

  • n_neighbors (default: 100) – Parameter to scanpy.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 clustering

  • resolution (default: 0.25) – Parameter to scanpy.tl.leiden() that determines the granularity of the clustering of the neighborhood profiles

  • min_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 the non_niche_value argument

  • key_added (default: 'niche') – Column name added adata.obs that stores each cell’s assigned niche

  • non_niche_value (default: 'other') – Cells that have been filtered out using the mask argument or that fall within a cluster smaller than min_niche_size will be assigned a niche with this name

Returns:

: An AnnData object storing the neighborhood profiles as computed by monkeybread.calc.neighborhood_profile()