snapatac2.pp.make_peak_matrix#

snapatac2.pp.make_peak_matrix(adata, *, use_rep=None, inplace=False, file=None, backend='hdf5', peak_file=None, chunk_size=500, use_x=False, min_frag_size=None, max_frag_size=None, count_frag_as_reads=True)[source]#

Generate cell by peak count matrix.

This function will generate a cell by peak count matrix and store it in a new .h5ad file.

import_data must be ran first in order to use this function.

Parameters:
  • adata (AnnData | AnnDataSet) – The (annotated) data matrix of shape n_obs x n_vars. Rows correspond to cells and columns to regions.

  • use_rep (Union[str, list[str], None]) – This is used to read peak information from .uns[use_rep]. The peaks can also be provided by a list of strings: [“chr1:1-100”, “chr2:2-200”].

  • inplace (bool) – Whether to add the tile matrix to the AnnData object or return a new AnnData object.

  • file (Optional[Path]) – File name of the output h5ad file used to store the result. If provided, result will be saved to a backed AnnData, otherwise an in-memory AnnData is used. This has no effect when inplace=True.

  • backend (Literal['hdf5']) – The backend to use for storing the result. If None, the default backend will be used.

  • peak_file (Optional[Path]) – Bed file containing the peaks. If provided, peak information will be read from this file.

  • chunk_size (int) – Chunk size

  • use_x (bool) – If True, use the matrix stored in .X as raw counts. Otherwise the .obsm['insertion'] is used.

  • min_frag_size (Optional[int]) – Minimum fragment size to include.

  • max_frag_size (Optional[int]) – Maximum fragment size to include.

  • count_frag_as_reads (bool) – Whether to count fragments as reads. If True, each fragment is converted to two points representing both ends of the fragment.

Returns:

An annotated data matrix of shape n_obs x n_vars. Rows correspond to cells and columns to peaks. If file=None, an in-memory AnnData will be returned, otherwise a backed AnnData is returned.

Return type:

AnnData | ad.AnnData | None

Examples

>>> import snapatac2 as snap
>>> data = snap.pp.import_data(snap.datasets.pbmc500(downsample=True), chrom_sizes=snap.genome.hg38, sorted_by_barcode=False)
>>> peak_mat = snap.pp.make_peak_matrix(data, peak_file=snap.datasets.cre_HEA())
>>> print(peak_mat)
AnnData object with n_obs × n_vars = 585 × 1154611
    obs: 'n_fragment', 'frac_dup', 'frac_mito'