scrnatools.tools.log_density_ratio

scrnatools.tools.log_density_ratio(adata: AnnData, group_by: str, groups: Tuple[str, str], latent_rep: str = 'X_umap', key_added: str = 'log_density_ratio', est_settings=None) AnnData[source]

Calculates a differential density ratio of cells grouped by condition and control.

Parameters:
  • adata (AnnData) – The AnnData containing labeled cell data.

  • group_by (str) – The column in ‘adata.obs’ containing condition and control labels.

  • groups (Tuple[str, str]) – The labels in ‘adata.obs[group_by]’ that distinguish condition and control cells, i.e. [“WT”, “KO”].

  • latent_rep (str, optional) – The latent representation to calculate differential density across. Defaults to “X_umap”.

  • key_added (str, optional) – The column in ‘adata.obs’ that will the density ratios will be added to. Defaults to “log_density_ratio”.

  • est_settings (optional) – The estimator settings used for kernel density calculation. Defaults to None.

Raises:
  • ValueError – If ‘group_by’ is not a valid column name in ‘adata.obs’.

  • ValueError – If ‘groups’ are not valid labels in ‘adata.obs[group_by]’.

Returns:

The original adata modified to contain the differential density ratios in a new column in ‘adata.obs’.

Return type:

AnnData