cellcharter.gr.nhood_enrichment

cellcharter.gr.nhood_enrichment#

cellcharter.gr.nhood_enrichment(adata, cluster_key, connectivity_key=None, log_fold_change=False, only_inter=True, symmetric=False, pvalues=False, n_perms=1000, n_jobs=1, batch_size=10, observed_expected=False, copy=False)#

A modified version of squidpy’s neighborhood enrichment.

This function computes the neighborhood enrichment between clusters in the spatial graph. It allows for the computation of the expected neighborhood enrichment using the analytical formula or by permutation. The analytical version is much faster, but the version based on permutation allows to estimate p-values for each enrichment value.

Setting the symmetric parameter to False allows to compute the neighborhood enrichment between cell1 and cell2 as the ratio between the number of links between cell1 and cell2 and the total number of links of cell1. This results in enrichment values that are not symmetric, i.e. the neighborhood enrichment between cell1 and cell2 is not equal to the enrichment between cell2 and cell1.

Parameters:
  • adata (AnnData) – Annotated data object.

  • cluster_key (str) – Key in anndata.AnnData.obs where clustering is stored.

  • connectivity_key (Optional[str] (default: None)) – Key in anndata.AnnData.obsp where spatial connectivities are stored. Default is: anndata.AnnData.obsp ['spatial_connectivities'].

  • only_inter (bool (default: True)) – Consider only links between cells that belong to the different clusters.

  • symmetric (bool (default: False)) – If True, the neighborhood enrichment between cell1 and cell2 is equal to the enrichment between cell2 and cell1.

  • pvalues (bool (default: False)) – If True, compute the p-values for each neighborhood enrichment value using permutation of the cluster labels.

  • n_perms (int (default: 1000)) – Number of permutations to use to compute the expected neighborhood enrichment if pvalues is True.

  • n_jobs (int (default: 1)) – Number of jobs to run in parallel if pvalues is True.

  • batch_size (int (default: 10)) – Number of permutations to run in each batch if pvalues is True.

  • copy (bool (default: False)) – If True, return the result, otherwise save it to the adata object.

  • observed_expected (bool (default: False)) – If True, return the observed and expected neighborhood proportions.

Return type:

dict | None

Returns:

If copy = True, returns a dict with the following keys:
  • 'enrichment' - the neighborhood enrichment.

  • 'pvalue' - the enrichment pvalues (if pvalues is True).

  • 'observed' - the observed neighborhood proportions (if observed_expected is True).

  • 'expected' - the expected neighborhood proportions (if observed_expected is True).

Otherwise, modifies the adata with the following key: