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
Falseallows to compute the neighborhood enrichment betweencell1andcell2as the ratio between the number of links betweencell1andcell2and the total number of links ofcell1. This results in enrichment values that are not symmetric, i.e. the neighborhood enrichment betweencell1andcell2is not equal to the enrichment betweencell2andcell1.- Parameters:
adata (
AnnData) – Annotated data object.cluster_key (
str) – Key inanndata.AnnData.obswhere clustering is stored.connectivity_key (
Optional[str] (default:None)) – Key inanndata.AnnData.obspwhere 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)) – IfTrue, the neighborhood enrichment betweencell1andcell2is equal to the enrichment betweencell2andcell1.pvalues (
bool(default:False)) – IfTrue, 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 ifpvaluesisTrue.n_jobs (
int(default:1)) – Number of jobs to run in parallel ifpvaluesisTrue.batch_size (
int(default:10)) – Number of permutations to run in each batch ifpvaluesisTrue.copy (
bool(default:False)) – IfTrue, return the result, otherwise save it to theadataobject.observed_expected (
bool(default:False)) – IfTrue, return the observed and expected neighborhood proportions.
- Return type:
- Returns:
- If
copy = True, returns adictwith the following keys: 'enrichment'- the neighborhood enrichment.'pvalue'- the enrichment pvalues (ifpvaluesisTrue).'observed'- the observed neighborhood proportions (ifobserved_expected is True).'expected'- the expected neighborhood proportions (ifobserved_expected is True).
- Otherwise, modifies the
adatawith the following key: anndata.AnnData.uns['{cluster_key}_nhood_enrichment']- the above mentioned dict.anndata.AnnData.uns['{cluster_key}_nhood_enrichment']['params']- the parameters used.
- If