snapatac2.ex.export_coverage#
- snapatac2.ex.export_coverage(adata, groupby, selections=None, bin_size=10, blacklist=None, normalization='RPKM', include_for_norm=None, exclude_for_norm=None, min_frag_length=None, max_frag_length=2000, counting_strategy='fragment', smooth_base=None, out_dir='./', prefix='', suffix='.bw', output_format=None, compression=None, compression_level=None, tempdir=None, n_jobs=8)[source]#
Export grouped genome-wide coverage tracks.
Use this function after importing fragments to write one bedGraph or bigWig coverage track per cell group. Coverage is counted in fixed-width genomic bins, optionally filtered by fragment length, smoothed, and normalized. Disable normalization with
normalization=None.Anti-Patterns#
Do NOT pass an AnnData object without fragment metadata created by
import_fragments.Do NOT use
include_for_normandexclude_for_normas peak-calling filters; they only define which fragments contribute to normalization.Do NOT rely on suffix inference for custom extensions; pass
output_formatandcompressionexplicitly.
- param adata:
Annotated data object with
n_obscells and fragment metadata.- type adata:
AnnData|AnnDataSet- param groupby:
Group assignment for each cell. If a string, values are read from
adata.obs[groupby]. If a list, it must contain one group label per cell in observation order.- type groupby:
- param selections:
Group names to export. If None, export every group found in
groupby.- type selections:
- param bin_size:
Width, in bases, of each coverage bin.
- type bin_size:
- param blacklist:
BED file of regions to exclude from coverage output.
- type blacklist:
- param normalization:
Coverage normalization method. Use None to export raw counts. RPKM divides each bin by mapped reads in millions and bin length in kilobases; CPM divides by mapped reads in millions; BPM divides by the sum of all binned reads in millions.
- type normalization:
- param include_for_norm:
Genomic intervals or BED file of intervals to include when computing the normalization denominator. If None, include all non-excluded fragments.
- type include_for_norm:
- param exclude_for_norm:
Genomic intervals or BED file of intervals to exclude when computing the normalization denominator. If a fragment overlaps both included and excluded intervals, it is excluded.
- type exclude_for_norm:
- param min_frag_length:
Minimum fragment length to count. If None, do not apply a minimum.
- type min_frag_length:
- param max_frag_length:
Maximum fragment length to count. If None, do not apply a maximum.
- type max_frag_length:
- param counting_strategy:
Counting mode. Use “fragment” to count overlapping fragments or “insertion” to count transposition insertion sites.
- type counting_strategy:
Literal['fragment','insertion']- param smooth_base:
Width, in bases, of the smoothing window. If None, do not smooth.
- type smooth_base:
- param out_dir:
Directory where output files are written.
- type out_dir:
- param prefix:
Text prepended to each output filename.
- type prefix:
- param suffix:
Text appended to each output filename. Used to infer output format and compression when the corresponding arguments are None.
- type suffix:
- param output_format:
Coverage-track format. If None, infer it from
suffix.- type output_format:
- param compression:
Compression codec for compressed bedGraph output. If None, infer it from
suffix.- type compression:
- param compression_level:
Compression level. Use 1-9 for gzip or 1-22 for zstandard. If None, use the backend default: 6 for gzip or 3 for zstandard.
- type compression_level:
- param tempdir:
Directory for temporary files created during export. If None, use the system temporary directory.
- type tempdir:
- param n_jobs:
Number of worker threads. If
n_jobs <= 0, use all available threads.- type n_jobs:
- returns:
Mapping from group name to output filename.
- rtype:
See also
Examples
>>> import snapatac2 as snap >>> data = snap.read(snap.datasets.pbmc5k(type="annotated_h5ad"), backed='r') >>> snap.ex.export_coverage( ... data, ... groupby='cell_type', ... selections=['Naive B'], ... suffix='.bedgraph.zst', ... ) {'Naive B': './Naive B.bedgraph.zst'}