Skip to main content

streampile

Build Status Python Versions License: MIT basedpyright mypy uv Ruff

Forward-only pileups streamed from coordinate-sorted BAM and CRAM records, and a table of the alleles at every base.

Installation

pip install streampile

Quickstart

Building Pileups

A StreamingPileupBuilder reads records once and piles them up at the 0-based positions you ask for, moving forward only.

>>> from pysam import AlignmentFile
>>> from streampile import StreamingPileupBuilder
>>>
>>> with (
...     AlignmentFile("tests/data/reads.bam") as reads,
...     StreamingPileupBuilder(reads, min_base_quality=30) as builder,
... ):
...     first = builder.pileup("chr1", 10)
...     second = builder.pileup("chr1", 12)
>>>
>>> first.filtered_depth, first.bases
(4, ['A', 'T', 'G', 'A'])
>>> second.filtered_depth, second.bases
(3, ['G', 'G', 'G'])

Filter reads with read_filter, and count each template once with without_overlaps():

>>> with (
...     AlignmentFile("tests/data/reads.bam") as reads,
...     StreamingPileupBuilder(reads, read_filter=lambda read: read.is_paired) as builder,
... ):
...     pileup = builder.pileup("chr1", 50)
>>>
>>> pileup.bases, pileup.without_overlaps().bases
(['T', 'T'], ['T'])

Pass tap=writer.write to receive every record, in input order, once the builder has moved past it.

Sweeping a Territory

columns yields the pileup at every position of a span.

>>> with AlignmentFile("tests/data/reads.bam") as reads, StreamingPileupBuilder(reads) as builder:
...     sum(pileup.unfiltered_depth for pileup in builder.columns("chr1", 0, 20))
73

Tabulating Alleles

tabulate counts the reads of every allele at every base of a bedspec Territory. Alleles are normalized VCF alleles at 1-based positions, so they match a VCF by CHROM, POS, REF, and ALT.

>>> from bedspec import Bed3
>>> from bedspec import Territory
>>> from pysam import FastaFile
>>> from streampile import tabulate
>>>
>>> territory = Territory([Bed3("chr1", start=9, end=12)])
>>> with (
...     AlignmentFile("tests/data/reads.bam") as reads,
...     FastaFile("tests/data/reference.fa") as reference,
... ):
...     bases = list(tabulate(reads, reference, territory, min_base_quality=30))
>>>
>>> for base in bases:
...     print(base.pos, base.ref, base.depth, base.alts, base.alt_reads)
10 A 4 () ()
11 A 4 ('T', 'GG') (1, 1)
12 C 4 () ()

Each base also splits its reads by strand and counts no-calls apart from its depth.

Reading a Table

>>> from streampile import TabulationReader
>>>
>>> for base in TabulationReader.from_path("tests/data/counts.tsv"):
...     print(base.pos, base.depth, base.alts, base.alt_reads)
21 5 () ()
22 5 () ()
23 4 ('C',) (1,)
24 4 () ()

Command Line

streampile tabulate \
    --bam tests/data/reads.bam \
    --ref tests/data/reference.fa \
    --intervals tests/data/territory.bed \
    --min-base-quality 30 \
    --min-mapping-quality 20 \
    --out counts.tsv
##streampile-tabulation=1
##streampile-version=0.1.0
##bam=tests/data/reads.bam
##reference=tests/data/reference.fa
##territory=tests/data/territory.bed
##min_base_quality=30
##min_mapping_quality=20
##exclude_flags=0xf00
#contig	pos	ref	depth	no_calls	ref_reads	ref_fwd	ref_rev	alt_refs	alts	alt_reads	alt_fwd	alt_rev
chr1	21	T	5	0	5	3	2					
chr1	22	G	5	0	5	3	2					
chr1	23	C	4	0	3	2	1	CA	C	1	0	1
chr1	24	A	4	0	3	2	1					

Write to a .gz path with --index tbi to compress and index the table, then read a region back:

for base in TabulationReader.query("counts.tsv.gz", "chr1", 20, 24):
    print(base.pos, base.depth, base.alts)

Development and Testing

See the contributing guide for more information.

The streaming design follows the StreamingPileupBuilder of fgbio; see NOTICE.

Metadata

Release files for streampile 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streampile 0.1.0
File Size Uploaded
streampile-0.1.0.tar.gz 47.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streampile 0.1.0
File Interpreter ABI Platform
streampile-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 74.6 kB

Release files / streampile-0.1.0.tar.gz

Download URL streampile-0.1.0.tar.gz
Size 47.4 kB
Tags Source
SHA-256 checksum
How to use checksums
02a09857a55397de6760a198bdb3110d1aed992c7b6e834ebf2601f35daa5125
BLAKE2b-256 checksum
How to use checksums
a2023ebcbc972d6cffe1605c5cf107f14a044b7c658723bdf59f7a2d962df7f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / streampile-0.1.0-py3-none-any.whl

Download URL streampile-0.1.0-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf08a2257b6f738b30bff5d7098f7734063ec7951e9617d42cbbd670eb6f1952
BLAKE2b-256 checksum
How to use checksums
5f18ff162846ee1b07b7bcda1781d558230495995a2b77e2502e9e211efc3746
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page