Skip to main content

Python bindings for BamNado

Project description

BamNado

High-performance tools and utilities for working with BAM and BigWig files in modern genomics workflows. BamNado is written in Rust for speed and low memory use and provides both a command-line interface and Python bindings.

Overview

BamNado is designed for efficient, streaming manipulation of BAM files and signal tracks. It focuses on fast coverage generation, flexible filtering, and lightweight post-processing of bedGraph and BigWig data.

Common use cases:

  • Rapid generation of coverage tracks from large BAM files
  • Filtering reads by tags or barcodes to produce targeted BigWigs
  • Fragment-aware coverage for ATAC-seq and related assays
  • BigWig comparison and aggregation across samples
  • Post-processing of binned signal tracks for visualization

Useful in workflows including single-cell and Micro-Capture-C (MCC), and many others.

Documentation: API docs on docs.rs

Features

  • High-performance, streaming implementations in Rust
  • Cross-platform support (Linux, macOS, Windows)
  • BAM → bedGraph / BigWig coverage generation
  • Fragment-aware and strand-specific pileups
  • Read filtering by mapping quality, length, strand, fragment size, tags, and barcodes
  • BigWig comparison (subtraction, ratio, log-ratio)
  • BigWig aggregation (sum, mean, median, min, max)
  • bedGraph post-processing with collapse-bedgraph
  • Python bindings for selected functionality

Installation

Pre-built binaries (recommended)

Download the appropriate binary from the releases page.

After downloading:

chmod +x bamnado
./bamnado --version

(Optional) install system-wide:

sudo cp bamnado /usr/local/bin/

Docker

docker pull ghcr.io/alsmith151/bamnado:latest
docker run --rm ghcr.io/alsmith151/bamnado:latest --help

Images are available for linux/amd64 and linux/arm64.

Cargo

If you have Rust installed:

cargo install bamnado

Build from source

git clone https://github.com/alsmith151/BamNado.git
cd BamNado
cargo build --release

Optional dependency: samtools

samtools is not required but is strongly recommended if your BAM files have non-standard or incomplete headers (e.g. files produced by CellRanger). BamNado automatically falls back to samtools view -H to parse the header when the built-in parser fails. Without samtools on your PATH, BamNado will error on such files.

Install via conda or your system package manager:

conda install -c bioconda samtools
# or
brew install samtools

Python API

BamNado provides Python bindings for high-performance BAM signal generation with flexible read filtering. Install from PyPI:

pip install bamnado
# or
uv pip install bamnado

Quick start

import bamnado
import numpy as np

# Generate coverage from a BAM file
signal = bamnado.get_signal_for_chromosome(
    bam_path="input.bam",
    chromosome_name="chr1",
    bin_size=50,
)
print(f"Mean coverage: {np.mean(signal):.2f}")

ReadFilter class

Customize read filtering with the ReadFilter class. All parameters are optional:

import bamnado

# Create a filter for high-quality, properly-paired reads
strict_filter = bamnado.ReadFilter(
    min_mapq=30,
    proper_pair=True,
    min_length=50,
)

# Apply the filter
signal = bamnado.get_signal_for_chromosome(
    bam_path="input.bam",
    chromosome_name="chr1",
    bin_size=100,
    read_filter=strict_filter,
)

Filter parameters

Parameter Type Default Description
min_mapq int 0 Minimum mapping quality
proper_pair bool False Require properly paired reads
min_length int 0 Minimum read length (bp)
max_length int 1000 Maximum read length (bp)
strand str "both" "forward", "reverse", or "both"
min_fragment_length int | None None Minimum insert size (bp); paired-end only
max_fragment_length int | None None Maximum insert size (bp); paired-end only
blacklist_bed str | None None BED file of excluded regions
whitelisted_barcodes list[str] | None None Cell barcodes to include (CB tag)
read_group str | None None Read group to keep (RG tag)
filter_tag str | None None SAM tag to filter on (e.g. "VP")
filter_tag_value str | None None Required value for filter_tag

Usage examples

Basic coverage

import bamnado
import numpy as np

signal = bamnado.get_signal_for_chromosome(
    bam_path="sample.bam",
    chromosome_name="chr1",
    bin_size=50,
    scale_factor=1.0,
    use_fragment=False,
)
print(f"Signal shape: {signal.shape}, type: {signal.dtype}")
print(f"Mean: {np.mean(signal):.2f}, Max: {np.max(signal):.2f}")

Nucleosome-free regions (ATAC-seq)

import bamnado

# Forward-strand reads, 100–200 bp fragments
nfr_filter = bamnado.ReadFilter(
    strand="forward",
    min_fragment_length=100,
    max_fragment_length=200,
    min_mapq=20,
)

nfr_signal = bamnado.get_signal_for_chromosome(
    bam_path="atac.bam",
    chromosome_name="chr1",
    bin_size=10,
    use_fragment=True,
    read_filter=nfr_filter,
)

Barcode-filtered coverage (single-cell)

import bamnado

# Get coverage for specific cell barcodes
cell_barcodes = ["ACGTACGT-1", "TGCATGCA-1", "AAATAAAA-1"]

barcode_filter = bamnado.ReadFilter(
    whitelisted_barcodes=cell_barcodes,
    min_mapq=25,
)

signal = bamnado.get_signal_for_chromosome(
    bam_path="possorted_genome_bam.bam",
    chromosome_name="chr1",
    bin_size=100,
    use_fragment=True,
    read_filter=barcode_filter,
)

Tag-filtered coverage (e.g. MCC viewpoint)

import bamnado

# Get coverage for specific viewpoint
vp_filter = bamnado.ReadFilter(
    filter_tag="VP",
    filter_tag_value="BCL2",
    min_mapq=30,
)

vp_signal = bamnado.get_signal_for_chromosome(
    bam_path="mcc.bam",
    chromosome_name="chr1",
    bin_size=50,
    use_fragment=True,
    read_filter=vp_filter,
)

High-confidence coverage

import bamnado

# High-quality, properly-paired reads
confident_filter = bamnado.ReadFilter(
    min_mapq=30,
    proper_pair=True,
    min_length=50,
    min_fragment_length=100,
    max_fragment_length=500,
)

signal = bamnado.get_signal_for_chromosome(
    bam_path="sample.bam",
    chromosome_name="chr1",
    bin_size=50,
    scale_factor=1e6,  # CPM normalization
    use_fragment=True,
    read_filter=confident_filter,
)

get_signal_for_chromosome parameters

Parameter Type Default Description
bam_path str Path to indexed BAM file
chromosome_name str Chromosome to process (e.g. "chr1")
bin_size int 50 Bin width in base pairs
scale_factor float 1.0 Linear scaling factor
use_fragment bool False Use fragment (pair) coordinates instead of read
ignore_scaffold_chromosomes bool True Skip non-standard chromosomes
read_filter ReadFilter | None None Optional read filter

Returns: numpy.ndarray of dtype float32 with length = chromosome size / bin_size

Note: Fragment length filtering (min_fragment_length, max_fragment_length) requires paired-end BAM files and will raise ValueError on single-end data.

Command-line interface

Getting help

bamnado --help                      # List all commands
bamnado <command> --help            # Help for a specific command

Available commands

  • Coverage generation: bam-coverage (coverage), multi-bam-coverage (multi-coverage)
  • BAM manipulation: split, split-exogenous, modify
  • BigWig tools: bigwig-compare (compare-bigwigs), bigwig-aggregate (aggregate-bigwigs)
  • bedGraph tools: collapse-bedgraph (collapse)

Common naming cleanups

The CLI now exposes shorter, more descriptive option names. Older names still work as compatibility aliases.

Read filtering

All coverage commands share common read filter flags:

Flag Default Description
--strand both forward, reverse, or both
--proper-pairs off Keep only properly-paired reads
--min-mapq 20 Minimum mapping quality
--min-length 20 Minimum read length (bp)
--max-length 1000 Maximum read length (bp)
--min-fragment-len Minimum insert size (bp); paired-end only
--max-fragment-len Maximum insert size (bp); paired-end only
--blacklist BED file of regions to exclude
--barcode-allowlist Text file of cell barcodes (one per line)
--read-group Keep only this read group
--tag / --tag-value Keep reads where TAG == VALUE

Coverage-specific flags

Flag Default Description
--normalize raw Signal normalization method: raw, rpkm, or cpm
--fragment-counts off Count fragments instead of individual read alignments
--ignore-scaffolds off Skip scaffold or unplaced chromosomes
--threads 6 Threads used when writing BigWig output

Examples

Generate basic coverage

bamnado bam-coverage \
  --bam sample.bam \
  --output coverage.bedgraph \
  --bin-size 100

Generate high-quality, normalized coverage

bamnado bam-coverage \
  --bam sample.bam \
  --output coverage_hq.bw \
  --bin-size 100 \
  --normalize rpkm \
  --min-mapq 30 \
  --proper-pairs

Extract nucleosome-free regions from ATAC-seq

bamnado bam-coverage \
  --bam atac.bam \
  --output nfr_forward.bw \
  --bin-size 10 \
  --strand forward \
  --min-fragment-len 100 \
  --max-fragment-len 200 \
  --fragment-counts \
  --min-mapq 20

Filter by cell barcode (single-cell)

bamnado bam-coverage \
  --bam possorted_genome_bam.bam \
  --output cell_coverage.bw \
  --bin-size 100 \
  --barcode-allowlist barcodes.txt \
  --fragment-counts

Filter by SAM tag (MCC viewpoint)

bamnado bam-coverage \
  --bam mcc.bam \
  --output BCL2_viewpoint.bw \
  --bin-size 50 \
  --tag VP \
  --tag-value BCL2 \
  --fragment-counts \
  --min-mapq 30

Compare two BigWig files

bamnado bigwig-compare \
  --bw1 sample_treated.bw \
  --bw2 sample_control.bw \
  --comparison log-ratio \
  --pseudocount 1e-3 \
  --threads 6 \
  -o treated_vs_control.bw

Aggregate multiple BigWig files

bamnado bigwig-aggregate \
  --bigwigs sample1.bw sample2.bw sample3.bw \
  --method mean \
  --threads 6 \
  -o mean_coverage.bw

Simplify bedGraph file

bamnado collapse-bedgraph \
  --input signal.bedgraph \
  --output signal.collapsed.bedgraph

Development

cargo build --release
cargo test

License

Apache-2.0 OR MIT

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

bamnado-0.6.1.tar.gz (104.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bamnado-0.6.1-cp310-abi3-win_amd64.whl (894.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

bamnado-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

bamnado-0.6.1-cp310-abi3-macosx_11_0_arm64.whl (704.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

bamnado-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl (744.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file bamnado-0.6.1.tar.gz.

File metadata

  • Download URL: bamnado-0.6.1.tar.gz
  • Upload date:
  • Size: 104.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for bamnado-0.6.1.tar.gz
Algorithm Hash digest
SHA256 99b4a87ba749a2d60a9a3883d033d036e06ee843ca0a8bb03aabd709e2926406
MD5 bc7c34294c88150fc8c9efe0ea20c53b
BLAKE2b-256 d78c09c1d940979f3dcd645f9b570ab9f2d943e46c0df39b7c7639cbeede6c12

See more details on using hashes here.

File details

Details for the file bamnado-0.6.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: bamnado-0.6.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 894.8 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for bamnado-0.6.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bb119724bf558bdfa84bfe9e0b2ae8a069fcba1e75075a3e9e9923cbf9b11df1
MD5 44fc0a2db9e071a3bf4a5bed63afc53f
BLAKE2b-256 9cef7ad138c9912dd6eb401864cf3000043fb29201ef409b03fa7bc538477696

See more details on using hashes here.

File details

Details for the file bamnado-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bamnado-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7f197826a741f0e01fae59c725c262095a9607a2b5bffae0fd242018d4ebe74
MD5 9b120cef9bea1ae3882038e47ab87959
BLAKE2b-256 0f89155d9082294854f7107d120ca297cf87fcba0f03cb8c1ee4e831e2e08928

See more details on using hashes here.

File details

Details for the file bamnado-0.6.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bamnado-0.6.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f1fddeef78e771894b48955dde46442ada928f369e47d6c8e646b64d74a400c7
MD5 0d8d8395d6753fb18ef77666092f0233
BLAKE2b-256 b0b8f2540e56d89070803e0a8794964a6268b0c5a9d45f26f8bb50595b20becd

See more details on using hashes here.

File details

Details for the file bamnado-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bamnado-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7ae67011dc808b2ff2ecb4335b45265420fa489b8c5a2506dcae0c3f310835ba
MD5 a581c83e0c6d6eabe0c38eb6f7e8915a
BLAKE2b-256 30fd41b82b63b3d34f9dd31357a7028134c1f968d002656dc78b1b1d10c5daab

See more details on using hashes here.

Supported by

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