snapatac2.read_10x_mtx#
- snapatac2.read_10x_mtx(path, file=None, prefix=None)[source]#
Read a 10x Genomics MTX directory into an AnnData object.
Use this function to load a directory containing a matrix file, feature file, and barcode file in the 10x MTX layout. Pass
fileto create a backed AnnData object on disk instead of returning a fully in-memory object.Anti-Patterns#
Do NOT pass the path to
matrix.mtxdirectly; pass the directory that contains the matrix, feature, and barcode files.Do NOT include multiple matching matrix, feature, or barcode files with the same prefix in the directory; exactly one of each file type must match.
- param path:
Directory containing the 10x MTX files. The directory must contain one matching file from each group:
Matrix: “matrix.mtx” or “matrix.mtx.gz”.
Features: “genes.tsv”, “genes.tsv.gz”, “features.tsv”, or “features.tsv.gz”.
Barcodes: “barcodes.tsv” or “barcodes.tsv.gz”.
- type path:
- param file:
Output h5ad filename for a backed AnnData object. If None, return an in-memory AnnData object.
- type file:
- param prefix:
Optional filename prefix before the matrix, feature, and barcode names. For files named
patientA_matrix.mtx,patientA_genes.tsv, andpatientA_barcodes.tsv, passprefix="patientA_".- type prefix:
- returns:
AnnData object with observations from the barcode file, variables from the feature file, and
.Xcontaining the transposed sparse count matrix.- rtype:
Examples
>>> from pathlib import Path >>> import snapatac2 as snap >>> adata = snap.read_10x_mtx(Path("filtered_feature_bc_matrix")) >>> adata.n_obs >= 0 True