monkeybread.calc.neighborhood_profile
- monkeybread.calc.neighborhood_profile(adata, groupby, basis='X_spatial', subset_output_features=None, subset_cells_by_group=None, radius=None, n_neighbors=None, normalize_counts=True, standard_scale=True, clip_min=None, clip_max=None)
Calculates a neighborhood profile for each cell.
The resulting AnnData object will have the same index corresponding to rows/cells, but a new index corresponding to columns, one column for each category in
adata.obs[groupby]. Instead of a gene expression profile, each column corresponds to the proportion of cells in the surrounding radius that belong to the respective category.- Parameters:
adata (
AnnData) – Annotated data matrix.groupby (
str) – A categorical column inobsto use for neighborhood profile calculations.basis (
Optional[str] (default:'X_spatial')) – Coordinates inadata.obsm[{basis}]to use. Defaults tospatial.subset_output_features (
Optional[Sequence[str]] (default:None)) – A list of groups fromadata.obs[groupby]to include in the resultingadata.var_names. Will not affect the calculations themselves, only which results are provided.subset_cells_by_group (
Optional[Sequence[str]] (default:None)) – A list of groups inadata.obs[groupby]to restrict the resulting AnnData object to. Only cells in those groups will be included in the resultingadata.obs_names.radius (
Optional[float] (default:None)) – Radius in coordinate space to include nearby cells for neighborhood profile calculation.n_neighbors (
Optional[int] (default:None)) – Number of neighbors to consider for the neighborhood profile calculations.normalize_counts (
Optional[bool] (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 (
Optional[bool] (default:True)) – Compute z-score of neighborhood values by subtracting the mean and dividing by the standard deviation.clip_min (
Optional[float] (default:None)) – Clip values that are less thanclip_mintoclip_minclip_max (
Optional[float] (default:None)) – Clip values that are greater thanclip_maxtoclip_max
- Return type:
- Returns:
: A new AnnData object where columns now correspond to neighborhood profile proportions. All .obs columns will be carried over from the provided AnnData object, and they will share an index.