scdynomics.utils.pp.align

Formatting the data for scDynOmics

author: jy

Functions

align_genes_to_reference(input_adata, ref_adata)

Align genes in adata with ref using sparse-aware operations.

align_peaks_to_reference(query_adata, ref_adata)

Align peaks in adata with ref using the peak-gene map.

get_peak_promoter_map(peaks[, map_dict, ...])

Map the peaks to the genes' promoters.

make_peak_interval_tree(ref_dict_path)

Constructs an interval tree for each chromosome based on the promoter peaks.

parse_peak_id(peak_id)

Parses the peak to extract the chromosome, start, and end positions.

remove_mt_genes(adata)

Remove mitochondrial genes from adata.

stratify_genes_to_reference(input_adata, ...)

Simply stratify genes in adata to match the reference,

scdynomics.utils.pp.align.align_genes_to_reference(input_adata: anndata.AnnData, ref_adata: anndata.AnnData, handle_duplicated: str = 'sum') anndata.AnnData

Align genes in adata with ref using sparse-aware operations.

scdynomics.utils.pp.align.align_peaks_to_reference(query_adata: anndata.AnnData, ref_adata: anndata.AnnData, ref_dict_path: str = None, map_dict: dict = None, save_path: str = None) anndata.AnnData

Align peaks in adata with ref using the peak-gene map.

Curate the raw ATAC-seq data to include only promoter peaks. Uses highly-optimized sparse matrix multiplication.

Instead of iterating over cells and adding vectors, we compute the entire aggregation instantly using a dot product. Query shape: (n_cells, n_peaks) @ M shape: (n_peaks, n_genes) -> (n_cells, n_genes) TBTested

scdynomics.utils.pp.align.get_peak_promoter_map(peaks, map_dict: dict = None, promoter_trees: dict = None, ref_dict_path: str = None) dict

Map the peaks to the genes’ promoters.

scdynomics.utils.pp.align.make_peak_interval_tree(ref_dict_path: str) dict

Constructs an interval tree for each chromosome based on the promoter peaks.

Parameters:

ref_dict_path – Path to the reference dictionary containing promoter information

Returns:

A dictionary mapping chromosome names to their corresponding interval trees

scdynomics.utils.pp.align.parse_peak_id(peak_id: str) tuple

Parses the peak to extract the chromosome, start, and end positions. Moved outside the class to prevent @lru_cache from holding ‘self’ in memory.

Parameters:

peak_id – A string in the format “chr:start-end”

Returns:

A tuple of (chromosome, start, end)

scdynomics.utils.pp.align.remove_mt_genes(adata: anndata.AnnData)

Remove mitochondrial genes from adata. The mitochondrial genes are identified by the ‘mt’ column in adata.var as in reference adata.

scdynomics.utils.pp.align.stratify_genes_to_reference(input_adata: anndata.AnnData, ref_adata: anndata.AnnData) anndata.AnnData
Simply stratify genes in adata to match the reference,

without handling duplicated genes or missing genes.