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 include:

  • 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

BamNado is useful in a range of workflows, including single-cell and Micro-Capture-C (MCC), but is not limited to those applications.


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)
  • collapse-bedgraph utility to merge adjacent bins with identical scores
  • 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 Interface

BamNado provides Python bindings for selected high-performance operations and is available directly from PyPI.

Python Installation

pip install bamnado
# or
uv pip install bamnado

ReadFilter

All read filtering options are controlled through the ReadFilter class:

Parameter Type Default Description
min_mapq int 0 Minimum mapping quality score
proper_pair bool True Keep only properly paired reads
min_length int 0 Minimum read length (bp)
max_length int 1000 Maximum read length (bp)
strand str "both" Strand to keep: "forward" / "fwd" / "+", "reverse" / "rev" / "-", or "both"
min_fragment_length int | None None Minimum insert size / TLEN (bp); requires paired-end data
max_fragment_length int | None None Maximum insert size / TLEN (bp); requires paired-end data
blacklist_bed str | None None Path to a BED file of regions to exclude
whitelisted_barcodes list[str] | None None Cell barcodes (CB tag) to include
read_group str | None None Read group (RG tag) to keep
filter_tag str | None None Two-character SAM tag to filter on (e.g. "VP")
filter_tag_value str | None None Required string value for filter_tag

A ValueError is raised if min_fragment_length or max_fragment_length is set on a single-end BAM file.

Example

import bamnado
import numpy as np

# Basic coverage — default filter settings
signal = bamnado.get_signal_for_chromosome(
    bam_path="input.bam",
    chromosome_name="chr1",
    bin_size=50,
    scale_factor=1.0,
    use_fragment=False,
    ignore_scaffold_chromosomes=True,
)
print(f"Mean coverage: {np.mean(signal):.3f}")

# Forward-strand nucleosome-free region coverage (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="input.bam",
    chromosome_name="chr1",
    bin_size=10,
    scale_factor=1.0,
    use_fragment=True,
    ignore_scaffold_chromosomes=True,
    read_filter=nfr_filter,
)

# Tag-filtered coverage (e.g. MCC viewpoint)
vp_filter = bamnado.ReadFilter(
    filter_tag="VP",
    filter_tag_value="BCL2",
    min_mapq=30,
)
vp_signal = bamnado.get_signal_for_chromosome(
    bam_path="input.bam",
    chromosome_name="chr1",
    bin_size=50,
    scale_factor=1.0,
    use_fragment=True,
    ignore_scaffold_chromosomes=True,
    read_filter=vp_filter,
)

Command-line usage

List available commands:

bamnado --help

Get help for a specific command:

bamnado <command> --help

Available commands

  • bam-coverage – generate coverage from a BAM file
  • multi-bam-coverage – coverage from multiple BAMs
  • split – split BAMs based on filters (e.g. barcodes)
  • split-exogenous – split endogenous vs exogenous reads
  • modify – apply transformations and filters to BAMs
  • bigwig-compare – compare two BigWigs
  • bigwig-aggregate – aggregate multiple BigWigs
  • collapse-bedgraph – merge adjacent bedGraph bins with identical scores

Read filtering

All coverage commands share a common set of read filter flags:

Flag Default Description
--strand both Include only forward, reverse, or both strands
--proper-pair off Keep only properly-paired reads
--min-mapq 20 Minimum mapping quality
--min-length 20 Minimum read sequence length (bp)
--max-length 1000 Maximum read sequence length (bp)
--min-fragment-length Minimum insert size / TLEN (bp); requires paired-end data
--max-fragment-length Maximum insert size / TLEN (bp); requires paired-end data
--blacklisted-locations BED file of regions to exclude
--whitelisted-barcodes Text file of cell barcodes to keep (one per line)
--read-group Keep only reads belonging to this read group
--filter-tag / --filter-tag-value Keep reads where SAM tag equals the given value

Fragment length filtering operates on the SAM TLEN field and is only meaningful for paired-end BAMs. BamNado will return an error if these flags are used with a single-end file.


Example: BAM coverage

bamnado bam-coverage \
  --bam input.bam \
  --output output.bedgraph \
  --bin-size 100 \
  --norm-method rpkm \
  --scale-factor 1.5 \
  --use-fragment \
  --proper-pair \
  --min-mapq 30

Example: strand- and fragment-length-filtered coverage

Useful for isolating nucleosome-free regions in ATAC-seq data:

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

Example: tag-filtered BigWig generation

bamnado bam-coverage \
  --bam input.bam \
  --output BCL2.bw \
  --bin-size 50 \
  --filter-tag "VP" \
  --filter-tag-value "BCL2" \
  --use-fragment \
  --min-mapq 30

BigWig comparison

bamnado bigwig-compare \
  --bw1 sample1.bw \
  --bw2 sample2.bw \
  --comparison log-ratio \
  --pseudocount 1e-3 \
  -o output.bw

BigWig aggregation

bamnado bigwig-aggregate \
  --bigwigs sample1.bw sample2.bw sample3.bw \
  --method mean \
  -o aggregated.bw

collapse-bedgraph

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.5.8.tar.gz (98.0 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.5.8-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

bamnado-0.5.8-cp310-abi3-win_amd64.whl (901.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

bamnado-0.5.8-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.5.8-cp310-abi3-macosx_11_0_arm64.whl (710.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

bamnado-0.5.8-cp310-abi3-macosx_10_12_x86_64.whl (755.5 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for bamnado-0.5.8.tar.gz
Algorithm Hash digest
SHA256 d951c9c5c1cb6aecda72839841e25eb0c76b29504e4a3dc7c72fed01d535aa18
MD5 2dfa1cf7ea027c3c0435729e1ab65fd8
BLAKE2b-256 80851ca66c652498638fed9edf1f53cb5f58f8ad5a0cd7d285545cf2752c8e95

See more details on using hashes here.

File details

Details for the file bamnado-0.5.8-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bamnado-0.5.8-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97ba6264bc8136c48a1107ce5675ffc22b022c80bfb1ccf7273aa3664005b376
MD5 f4615222a4d8f221c8c48c86bd052a4f
BLAKE2b-256 9c07107c5a15e58ac2b034a053ca490a5013fe011f185f7ef93e60b6d3b2332c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bamnado-0.5.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e6f53069cf031b2b2e6a7166dd1a9b8eabbf39af5f348d7afd9108b2c7828aa6
MD5 33f7c383d89785d64a167409018b27cb
BLAKE2b-256 ddaeacd15a8e4e4e46a4854fb6bcb6d4841f834d2971620eea9b0bcd2d007abd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bamnado-0.5.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21bae01516adc6f694530677740510a4678c4923f98059d564869b550601131a
MD5 cf9ea0c1322cf9b7d163c9f620895992
BLAKE2b-256 2ba4935262711deb646f8454a01fc7a86a17abe2599003a4199b3aa44965ab21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bamnado-0.5.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a379b0c19ec9daa31dab920f87679df2cc4be1ce2c3e08e728d90246a9349e0
MD5 f94c2b2c90cbc73277a6d76f7d4699cc
BLAKE2b-256 196bc583b80efec55de7fef3ff4d1e6db868fb8a2bd5e737165a7a0b6c89536d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bamnado-0.5.8-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 830bfed5dba5fa4ef0d86b6cf90edec8f11706b9989cee06339e728b9ee4acca
MD5 5fe38e3d5fc24ad83aae09b40a5e0e16
BLAKE2b-256 f5a585da2ce0814ade22bc8e7fde0ea3acee28839697cc3457ecc53820091cbf

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