Process genomes with ease
Project description
snputils: A Python Library for Processing Genetic Variation and Population Structure
snputils is a Python package designed to ease the processing and analysis of genomic datasets, while handling all the complexities of different genome formats and operations very efficiently. The library provides robust tools for handling sequencing and ancestry data, with a focus on performance, ease of use, and advanced visualization capabilities.
Developed in collaboration between Stanford University's Department of Biomedical Data Science, UC Santa Cruz Genomics Institute, and more collaborators worldwide.
Note: snputils is under active development. While the core API is stabilizing, we are continuously adding features, optimizing performance, and expanding format support.
Installation
Basic installation using pip:
pip install snputils
Optionally, for PyTorch-backed features, install with the [torch] extra:
pip install 'snputils[torch]'
Key Features
Ease of Use
snputils is designed to be user-friendly and intuitive, with a simple API that allows you to quickly load, process, and visualize genomic data. For example, reading a whole genome VCF file is as simple as:
import snputils as su
snpobj = su.read_snp("path/to/file.vcf.gz")
Similarly, reading BED or PGEN filesets is straightforward:
snpobj = su.read_snp("path/to/file.pgen")
Working with ancestry files, performing processing operations, and creating visualizations is just as straightforward. See the tutorial notebooks for examples.
File Format Support
snputils aims to provide the fastest available readers and writers for various genomic data formats:
- VCF: Support for
.vcfand.vcf.gzfiles - PLINK1: Support for
.bed,.bim,.famfilesets - PLINK2: Support for
.pgen,.pvar,.psamfilesets - Local Ancestry: Handle
.msplocal ancestry format - Admixture: Read and write
.Qand.Pfiles
Processing & Analysis Tools
-
Basic Data Manipulation
- Filter variants and samples, correct SNP flips, and filter out ambiguous SNPs
- Compute cohort allele frequency and ancestry-specific allele frequencies via
SNPObject.allele_freq(...)or in streaming for memory efficiency withsnputils.stats.allele_freq_stream(...) - Standardized querying across genotype, local ancestry, global ancestry, and IBD data
-
Dimensionality Reduction
- Standard PCA with optional GPU acceleration
- Missing-data PCA (mdPCA)
- Multi-array ancestry-specific MDS (maasMDS)
-
Population Genetic Statistics
- Compute $D$, $f_2$, $f_3$, $f_4$, the $f_4$-ratio, and $F_{ST}$ (Hudson and Weir-Cockerham)
- Includes block jackknife standard errors and optional ancestry masking
-
Identity-by-Descent (IBD) & Relatedness
- Read
hap-IBDandancIBDoutputs into a unified format - Fast filtering and ancestry-restricted segment trimming using local ancestry
- Read
-
Admixture Analysis & Simulation
- Admixture Mapping: Locus-by-locus regression of local ancestry dosage on traits
- Simulation: Lightweight haplotype-based simulation of admixed mosaics from real founder haplotypes
Visualization
- Interactive global ancestry bar plots
- Detailed scatter plots of PCA, mdPCA, and maasMDS
- Admixture mapping Manhattan plots
- Local ancestry visualization
- Chromosome painting (with Tagore)
- Dataset-level
Performance
- Fast file I/O through built-in methods or optimized wrappers (e.g., Pgenlib for PLINK files)
- Memory-efficient operations using NumPy and Polars
- Optional GPU acceleration via PyTorch for computationally intensive tasks
- Support for large-scale genomic datasets through efficient memory management
Our benchmark demonstrates superior performance compared to existing tools:
Reading performance comparison for chromosome 22 data across different tools. See the benchmark directory for detailed methodology and results.
The snputils package is continuously updated with new features and improvements.
Documentation & Support
- Documentation: User guide, tutorials, and API reference at docs.snputils.org.
- Examples & Tutorials: Browse the tutorials in the documentation or the source notebooks in
docs/tutorials. - Issues & Community: Report bugs, ask questions, or request features via GitHub Issues.
Citation
If you use snputils in your research, please cite our paper:
@article{snputils2026,
author = {Bonet, David and Comajoan Cara, Marçal and Barrabés, Míriam and Smeriglio, Riccardo and Agrawal, Devang and Aounallah, Khaled and Geleta, Margarita and Dominguez Mantes, Albert and Thomassin, Christophe and Shanks, Cole and Huang, Edward C. and Franquesa Monés, Marc and Luis, Aina and Saurina, Joan and Perera, Maria and López, Cayetana and Sabat, Benet Oriol and Abante, Jordi and Moreno-Grau, Sonia and Mas Montserrat, Daniel and Ioannidis, Alexander G.},
title = {{snputils}: A High-Performance {Python} Library for Genetic Variation and Population Structure},
year = {2026},
month = feb,
doi = {10.64898/2026.02.28.708618},
url = {https://www.biorxiv.org/content/10.64898/2026.02.28.708618},
journal = {bioRxiv},
publisher = {Cold Spring Harbor Laboratory},
}
Acknowledgments
We would like to thank the open-source packages that make snputils possible.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snputils-0.2.38.tar.gz.
File metadata
- Download URL: snputils-0.2.38.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13d4c6e2621928c025eb5c39f62a9e80fc5075c4b772f9d6cfd8bb12d863590e
|
|
| MD5 |
dadc61ec1bb0eab46ce492906277be0f
|
|
| BLAKE2b-256 |
7471bfd0523a128c053f72fcd59be363368cce6d9568c27776a3c5a0633ee903
|
File details
Details for the file snputils-0.2.38-py3-none-any.whl.
File metadata
- Download URL: snputils-0.2.38-py3-none-any.whl
- Upload date:
- Size: 242.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
069babb374d69a2a9031c2bdad46c89bae0a45a79f73d18bc31684172ea093d7
|
|
| MD5 |
0810e8bec800d3b653a739d81dab55a4
|
|
| BLAKE2b-256 |
42ccd720ca5adfe07590c201b343692b3c690c22f4502af44f619e25ccbbabb3
|