scdynomics.utils.pp

For preprocessing the data

author: jy

Functions

pipeline(adata[, ref_adata, ref_adata_path, ...])

A comprehensive pipeline for pre-processing the AnnData object.

scdynomics.utils.pp.pipeline(adata: anndata.AnnData, ref_adata: anndata.AnnData = None, ref_adata_path: str = None, layers: list = [None], matching_strategy: str = 'stratify', handle_duplicated: str = 'sum', remove_mt: bool = True, filtering: bool = True, min_genes: int = 200, min_cells: int = None, percent_top: int = 20, remove_outliers: bool = True, log1p: bool = True, remove_mono: bool = False, normalizing: bool = True, target_sum: float = 1000000.0, exclude_highly_expressed: bool = False, max_fraction: float = 0.05, methods: list = ['cpm'], n_top_genes: int = None, hvg_flavor: str = 'seurat_v3', savepath: str = None, **kwargs) anndata.AnnData

A comprehensive pipeline for pre-processing the AnnData object.

This function chains together gene alignment, mitochondrial gene removal, quality control (QC) filtering, normalization, and highly variable gene (HVG) selection.

Parameters:
adata: ad.AnnData

The input annotated data matrix to be pre-processed.

ref_adata: ad.AnnData (default: None)

A reference AnnData object used to align or stratify genes.

ref_adata_path: str (default: None)

File path to load the reference AnnData from an .h5ad file if ref_adata is not directly provided.

layers: list (default: [None])

List of layer names to apply QC and normalization to. None applies to adata.X.

matching_strategy: str (default: 'stratify')

The strategy to match genes with the reference. Valid options are 'align' or 'stratify'.

handle_duplicated: str (default: 'sum')

Method to handle duplicated genes during alignment.

remove_mt: bool (default: True)

If True, removes mitochondrial genes from the dataset.

filtering: bool (default: True)

If True, applies quality control metrics to filter cells and genes.

min_genes: int (default: 200)

Minimum number of genes expressed required for a cell to pass QC.

min_cells: int (default: None)

Minimum number of cells a gene must be expressed in to be kept.

percent_top: int (default: 20)

Proportions of counts in top-expressed genes used to calculate a QC metric.

remove_outliers: bool (default: True)

If True, removes outlier cells based on QC metrics calculations.

log1p: bool (default: True)

If True, computes log1p transformed metrics and applies log1p after normalization.

remove_mono: bool (default: False)

If True, removes mono-omics cells when filtering multimodal data.

normalizing: bool (default: True)

If True, normalizes the data layers.

target_sum: float (default: 1e6)

Target sum for total count normalization (e.g., 1e6 for CPM).

exclude_highly_expressed: bool (default: False)

If True, excludes highly expressed genes from the size factor computation.

max_fraction: float (default: 0.05)

Maximum fraction of counts for a gene to not be considered highly expressed.

methods: list (default: ['cpm'])

List of normalization methods matching the length of layers. Supported methods include 'cpm', 'tpm', and 'cpm_promoter'.

n_top_genes: int (default: None)

Number of highly variable genes to select. If None, HVG selection is skipped.

hvg_flavor: str (default: 'seurat_v3')

The flavor used for selecting highly variable genes.

savepath: str (default: None)

If provided, saves the final processed AnnData to this path with zstd compression.

kwargs:

Additional keyword arguments passed to sc.pp.highly_variable_genes.

Returns: ad.AnnData

The fully pre-processed AnnData object.

Modules

align

Formatting the data for scDynOmics

normalize

Normalization modules for scDynOmics

qc

For filtering low quality cells