monkeybread.calc.neighborhood_profile
- monkeybread.calc.neighborhood_profile(adata, groupby, basis='spatial', subset_output_features=None, subset_cells_by_group=None, radius=None, n_neighbors=None, normalize_counts=True)
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 inobs
to use for neighborhood profile calculations.basis (
Optional
[str
] (default:'spatial'
)) – Coordinates inadata.obsm[X_{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_features
is provided andnormalize_counts = True
, the normalization step will be performed before removing groups, so proportions will not sum to 1.
- 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.