Skip to main content

Bam2Tensor

Project description

bam2tensor

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

bam2tensor is a Python package for converting .bam files to dense representations of methylation data (as .npz NumPy arrays). It is designed to evaluate all CpG sites and store methylation states for loading into other deep learning pipelines.

bam2tensor logo

Features

  • Parses .bam files using pysam
  • Extracts methylation data from all CpG sites
  • Supports any genome (Hg38, T2T-CHM13, mm10, etc.)
  • Stores data in sparse format (COO matrix) for efficient loading
  • Exports methylation data to .npz NumPy arrays
  • Easily parallelizable

Requirements

  • Python 3.9+
  • pysam, numpy, scipy, tqdm

Installation

You can install bam2tensor via pip from PyPI:

pip install bam2tensor

Usage

Please see the Reference Guide for full details.

Data Structure

One .npz file is generated for each separate .bam, which can be loaded using scipy.sparse.load_npz(). Each .npz file contains a single sparse SciPy COO matrix.

In the COO matrix, each row represents a read and each column represents a CpG site. The value at each row/column is the methylation state (0 = unmethylated, 1 = methylated, -1 = no data). Note that -1 can represent indels or point mutations.

Todo

  • Consider storing a Read ID: Row ID mapping?
  • Export / more stably store & import embedding mapping? (.npz or other instead of .json?)
  • Store metadata / object reference in .npz file?

Contributing

Contributions are welcome! Please see the Contributor Guide.

License

Distributed under the terms of the MIT license, bam2tensor is free and open source.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project is developed and maintained by Nick Semenkovich (@semenko), as part of the Medical College of Wisconsin's Data Science Institute.

This project was generated from Statistics Norway's SSB PyPI Template.

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

bam2tensor-1.3.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distribution

bam2tensor-1.3-py3-none-any.whl (14.3 kB view hashes)

Uploaded Python 3

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