Skip to main content

SNP utils

Project description

snputils logo

snputils: A Python library for processing diverse genomes

License BSD-3 PyPI Python Version

snputils is a Python package designed to ease the processing and analysis of common and diverse genomic datasets, while handling all the complexities of diverse 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.

This is an early access release, parts of the code are likely to change significantly in the upcoming weeks.

Installation

Basic installation using pip:

pip install snputils

Optionally, for GPU-accelerated functionalities, install the package with the [gpu] extra:

pip install snputils[gpu]

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 demos directory for examples.

File Format Support

snputils aims to provide the fastest available readers and writers for various genomic data formats:

  • VCF: Support for .vcf and .vcf.gz files
  • PLINK1: Support for .bed, .bim, .fam filesets
  • PLINK2: Support for .pgen, .pvar, .psam filesets
  • Local Ancestry: Handle .msp local ancestry format
  • Admixture: Read and write .Q and .P files

Processing Tools

  • Basic Data Manipulation

    • Filter variants and samples
    • Correct SNP flips
    • Filter out ambiguous SNPs
  • Dimensionality Reduction

    • Standard PCA with optional GPU acceleration
    • Missing-DNA PCA (mdPCA)
    • Multi-array ancestry-specific MDS (maasMDS)
  • Admixture Mapping

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](benchmark/) for detailed methodology and results.*

The snputils package is continuously updated with new features and improvements. Future releases will include support for statistical computations, admixture simulations, command-line tools, and more.

Documentation & Support

Acknowledgments

We would like to thank the open-source Python packages that make snputils possible: matplotlib, NumPy, pandas, Pgenlib, polars, pong, PyTorch, scikit-allel, scikit-learn, Tagore.

Citation

If you use snputils in your research, please cite:

Bonet, D.*, Comajoan Cara, M.*, Barrabés, M.*, Smeriglio, R., Agrawal, D., Dominguez Mantes, A., López, C., Thomassin, C., Calafell, A., Luis, A., Saurina, J., Franquesa, M., Perera, M., Geleta, M., Jaras, A., Sabat, B. O., Abante, J., Moreno-Grau, S., Mas Montserrat, D., Ioannidis, A. G., snputils: A Python library for processing diverse genomes. Annual Meeting of The American Society of Human Genetics, November 2024, Denver, Colorado, USA. * Equal contribution.

Journal paper coming soon!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snputils-0.2.0.tar.gz (92.3 kB view details)

Uploaded Source

Built Distribution

snputils-0.2.0-py3-none-any.whl (118.2 kB view details)

Uploaded Python 3

File details

Details for the file snputils-0.2.0.tar.gz.

File metadata

  • Download URL: snputils-0.2.0.tar.gz
  • Upload date:
  • Size: 92.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.2

File hashes

Hashes for snputils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3a45d4d1ca509322acc7357807aa1e0f5a0eea1f7a203368cf9054a62deabd6e
MD5 2c3d0f7df4294f997d9b75fea4ef0c16
BLAKE2b-256 f5f805c550cd63babdbd0452813bd5028c60c6fc711563e028433ec85de54a55

See more details on using hashes here.

File details

Details for the file snputils-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: snputils-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 118.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.2

File hashes

Hashes for snputils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7f9ba0897ab1ad752e8f32e9c67090ae3aed4f42907df1558694e9a0ac9a431
MD5 4deca34bf9d3dfaa433be9ae2167e7a2
BLAKE2b-256 51297206315851719d1e861b4f51b3c4098aa5cbb8443028809e343ae9347d9c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page