snapatac2.metrics.tsse#

snapatac2.metrics.tsse(adata, gene_anno, *, exclude_chroms=['chrM', 'M'], inplace=True, n_jobs=8)[source]#

Compute transcription start site enrichment for each cell.

Run this metric after import_fragments has attached fragment metadata to the AnnData object. With inplace=True, the function writes cell-level scores to adata.obs["tsse"] and library-level summaries to adata.uns.

Anti-Patterns#

  • Do NOT call this function on an AnnData object that lacks imported fragments.

  • Do NOT pass a genome object without an annotation file; gene_anno must resolve to a GTF/GFF annotation.

param adata:

AnnData object, or a list of AnnData objects, with imported fragments. When a list is provided, compute TSSe for each object in parallel.

type adata:

AnnData | list[AnnData]

param gene_anno:

Genome object with an annotation path, or a GTF/GFF annotation file path used to define transcription start sites.

type gene_anno:

Genome | Path

param exclude_chroms:

Chromosome names to exclude when computing the TSS profile. Use None to include all chromosomes.

type exclude_chroms:

list[str] | str | None

param inplace:

If True, store results in adata.obs and adata.uns. If False, return the result dictionary instead.

type inplace:

bool

param n_jobs:

Number of jobs to run when adata is a list. If n_jobs=-1, use all available CPUs.

type n_jobs:

int

returns:

If inplace=True, returns None after storing tsse in adata.obs and library_tsse, frac_overlap_TSS, and TSS_profile in adata.uns. If inplace=False, returns the same values in a dictionary, or a list of dictionaries when adata is a list.

rtype:

ndarray | list[ndarray] | None

Examples

>>> import snapatac2 as snap
>>> data = snap.pp.import_fragments(snap.datasets.pbmc500(downsample=True), chrom_sizes=snap.genome.hg38, sorted_by_barcode=False)
>>> snap.metrics.tsse(data, snap.genome.hg38)
>>> print(data.obs['tsse'].head())
AAACTGCAGACTCGGA-1    32.129514
AAAGATGCACCTATTT-1    22.052786
AAAGATGCAGATACAA-1    27.109808
AAAGGGCTCGCTCTAC-1    24.990329
AAATGAGAGTCCCGCA-1    33.264463
Name: tsse, dtype: float64