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 betweencell1
andcell2
as the ratio between the number of links betweencell1
andcell2
and the total number of links ofcell1
. This results in enrichment values that are not symmetric, i.e. the neighborhood enrichment betweencell1
andcell2
is not equal to the enrichment betweencell2
andcell1
.- Parameters:
adata (
AnnData
) – Annotated data object.cluster_key (
str
) – Key inanndata.AnnData.obs
where clustering is stored.connectivity_key (
Optional
[str
] (default:None
)) – Key inanndata.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
)) – IfTrue
, the neighborhood enrichment betweencell1
andcell2
is equal to the enrichment betweencell2
andcell1
.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 ifpvalues
isTrue
.n_jobs (
int
(default:1
)) – Number of jobs to run in parallel ifpvalues
isTrue
.batch_size (
int
(default:10
)) – Number of permutations to run in each batch ifpvalues
isTrue
.copy (
bool
(default:False
)) – IfTrue
, return the result, otherwise save it to theadata
object.observed_expected (
bool
(default:False
)) – IfTrue
, return the observed and expected neighborhood proportions.
- Return type:
- Returns:
- If
copy = True
, returns adict
with the following keys: 'enrichment'
- the neighborhood enrichment.'pvalue'
- the enrichment pvalues (ifpvalues
isTrue
).'observed'
- the observed neighborhood proportions (ifobserved_expected is True
).'expected'
- the expected neighborhood proportions (ifobserved_expected is True
).
- Otherwise, modifies the
adata
with 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