spac.spatial_analysis.neighborhood_profile(adata, phenotypes, distances, regions=None, spatial_key='spatial', normalize=None, associated_table_name='neighborhood_profile')[source]

Calculate the neighborhood profile for every cell in all slides in an analysis and update the input AnnData object in place.

Parameters:
  • adata (AnnData) – The AnnData object containing the spatial coordinates and phenotypes.

  • phenotypes (str) – The name of the column in adata.obs that contains the phenotypes.

  • distances (list) – The list of increasing distances for the neighborhood profile.

  • spatial_key (str, optional) – The key in adata.obs that contains the spatial coordinates. Default is ‘spatial’.

  • normalize (str or None, optional) – If ‘total_cells’, normalize the neighborhood profile based on the total number of cells in each bin. If ‘bin_area’, normalize the neighborhood profile based on the area of every bin. Default is None.

  • associated_table_name (str, optional) – The name of the column in adata.obsm that will contain the neighborhood profile. Default is ‘neighborhood_profile’.

  • regions (str or None, optional) – The name of the column in adata.obs that contains the regions. If None, all cells in adata will be used. Default is None.

Returns:

The function modifies the input AnnData object in place, adding a new column containing the neighborhood profile to adata.obsm.

Return type:

None

Notes

The input AnnData object ‘adata’ is modified in place. The function adds a new column containing the neighborhood profile to adata.obsm, named by the parameter ‘associated_table_name’. The associated_table_name is a 3D array of shape (n_cells, n_phenotypes, n_bins) where n_cells is the number of cells in the all slides, n_phenotypes is the number of unique phenotypes, and n_bins is the number of bins in the distances list.

A dictionary is added to adata.uns[associated_table_name] with the two keys “bins” and “labels”. “labels” will store all the values in the phenotype annotation.