cellcharter.gr.diff_nhood_enrichment

cellcharter.gr.diff_nhood_enrichment#

cellcharter.gr.diff_nhood_enrichment(adata, cluster_key, condition_key, condition_groups=None, connectivity_key=None, pvalues=False, library_key='library_id', n_perms=1000, n_jobs=None, copy=False, **nhood_kwargs)#

Differential neighborhood enrichment between conditions.

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

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

  • condition_key (str) – Key in anndata.AnnData.obs where the sample condition is stored.

  • condition_groups (Optional[tuple[str, str]] (default: None)) – The condition groups to compare. If None, all conditions in condition_key will be used.

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

  • pvalues (bool (default: False)) – If True, compute the p-values for each differential neighborhood enrichment through permutation of the condition key for each Z-dimension.

  • library_key (str | None (default: 'library_id')) – If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs. Used only if pvalues is True to permute the condition labels.

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

  • n_jobs (Optional[int] (default: None)) – Number of jobs to run in parallel if pvalues is True. -1 means using all processors.

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

  • nhood_kwargs

    Keyword arguments for gr.nhood_enrichment(). The following arguments are not allowed:
    • n_perms

    • pvalues

    • n_jobs

Return type:

dict | None

Returns:

If copy = True, returns a dict of all pairwise differential neighborhood enrichments between conditions stored as {condition1}_{condition2}. The differential neighborhood enrichment is a dict with the following keys:

  • 'enrichment' - the differential neighborhood enrichment.

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