sccoda.util.cell_composition_data.read_anndata_one_sample

sccoda.util.cell_composition_data.read_anndata_one_sample(adata, cell_type_identifier, covariate_key=None)

Converts a single scRNA-seq data set from scanpy (anndata format) to a row of a cell count matrix.

It is assumed that a column of adata.obs (e.g. Louvain clustering results) contains the cell type assignment. Additionally, covariates (control/disease group, …) can be specified as a subdict in adata.uns

Usage:

cell_counts, covs = from_scanpy(adata, cell_type_identifier="Louvain", covariate_key="covariates")

Parameters
adata : AnnDataAnnData

single-cell data object from scanpy

cell_type_identifier : strstr

column name in adata.obs that specifies the cell types

covariate_key : str, NoneOptional[str] (default: None)

key for adata.uns, where the covariate values are stored

Return type

Tuple[ndarray, dict]Tuple[ndarray, dict]

Returns

  • A numpy array for the cell counts and a dict for the covariates

  • cell_counts – cell count vector

  • covs – covariate dictionary