Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

pbzarr

pbzarr

What is this?

pbzarr is a library for storing and analyzing genomic measurements at base-pair resolution. It stores measurements in two-dimensional arrays: one dimension for genomic position, and another for samples or other labels. You can run calculations across either dimension or both.

pbzarr uses Zarr, an existing format for compressed arrays. It adds conventions for genomic coordinates and column labels, plus tools to import and analyze the data.

Motivation

Most bioinformatics files (BAM, BED, bigWig) hold data for one sample. And this makes sense, because most primary bionformatics analyses (i.e alignment) are sample independent. But many downstream analyses need comparisons across samples, over the whole genome or in regions of interest. That means opening each sample's files, reading the relevant data, performing computations, and storing the result.

Often these analyses are exploratory. We run them several times as we decide which samples to include, which regions to look at, or where to set a threshold. With a few regions or a small sample set, this is not that big of a deal. But as cohorts and region sets grow, more work goes into reading the files and bringing the measurements together. During exploratory analysis, we can repeat that work every time we ask a slightly different question, even though the underlying measurements have not changed.

pbzarr builds on the idea that these analyses often need the same two-dimensional array: one dimension for genomic position, and another for samples. pbzarr builds this array for the whole genome once and stores it in compressed chunks using Zarr. Each analysis can then read the regions and samples it needs, without rebuilding the array from individual sample files.

This also has a few useful side effects:

  • Xarray lets us attach genomic positions, sample names, and other labels to the dimensions, and organize different measurements together.
  • Dask lets us run calculations in parallel, on one machine or across a cluster.
  • Zarr supports local and cloud storage. We can read the chunks we need from the cloud without downloading the whole dataset.

Data model

pbzarr uses the dataset model of xarray. A .pbz store opens as one xarray Dataset. Each track is one variable, and all tracks share the store's reference genome and labels.

A track has at most two dimensions: genomic position and one labeled column axis, such as sample. The column axis is homogeneous, so every column shares the track's data type, fill value, and compression settings. When values need different data types or settings, each kind goes into its own track. For example, depth, mapping quality, and a mask become three tracks in one store.

The store fixes its reference (contig names and lengths) when it is created. Every track covers that whole reference. See format for more details.

Install

The Python package needs Python 3.12 or newer:

pip install pbzarr

To install the pbz command-line tool on Linux x86_64 or macOS on Apple Silicon:

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/pbzarr/pbzarr/releases/latest/download/pbz-installer.sh | sh

The script downloads pbz from the latest release, checks its checksum, and puts it in $CARGO_HOME/bin (by default ~/.cargo/bin). Set PBZ_INSTALL_DIR to use a different directory. You can also build it from source:

cargo install --locked --git https://github.com/pbzarr/pbzarr pbz

The prebuilt Linux wheels and binaries need glibc 2.28 or newer (RHEL and Rocky 8+, Ubuntu 20.04+). On older systems, build from source.

Python examples

Import d4 files

import pbzarr

pbzarr.import_d4(
    "depth.pbz",
    "depth",
    [("brain.d4", "brain"), ("liver.d4", "liver")],
    dim="sample",
)

This creates the store depth.pbz and a depth track with one row per genomic position and one column per sample. The import takes the store's reference from the source headers. All sources must have the same contig names, lengths, and order.

Each source is a path or a (path, label) tuple. Give a list for several sources. If one source has a label, all sources must have labels. A missing source file raises FileNotFoundError, and a bad argument raises ValueError. Other failures raise pbzarr.PbzError.

When the store exists, the import adds the track to it. The sources must then match the store's reference. The import refuses a track name that the store already uses. The CLI imports follow the same rule.

Read a region

ds = pbzarr.open("depth.pbz")

window = pbzarr.region(ds["depth"], "chr1:100000-101000")
brain = window.sel(sample="brain")

values = window.compute()

pbzarr.open returns an ordinary xarray.Dataset, and ds["depth"] is a lazy xarray.DataArray of the whole genome. pbzarr.region gives a view of one locus. The view labels each base as "contig:pos", and its numeric pos coordinate holds the contig-local positions. pbz uses zero-based, half-open coordinates.

Calculate statistics over regions

peaks = [
    ("chr1", 100000, 100200),
    ("chr1", 150000, 150300),
    ("chr2", 200000, 200150),
]

peak_means = pbzarr.reduce_regions(ds, peaks, "mean")
result = peak_means.compute()

The result has one mean for each peak and sample. Row i of the result is peak i of the input, and the peaks can overlap. Other reductions include sum, min, max, count, std, var, median, quantile (with q=), and summit (with by=). Regions can also be a list of strings such as "chr1:100000-100200", or a dataframe with chrom, start, and end columns. Tracks on a bin_N dimension are left out of the result, with a warning.

Dask keeps reads and calculations lazy until compute(). The computed result must still fit in memory.

Mask positions inside regions

mask = pbzarr.interval_mask(ds, peaks)
peak_depth = ds["depth"].where(mask)

pbzarr.interval_mask gives a lazy bool array over position. A value is True inside a region and False outside it. It takes the same region forms as reduce_regions, and the regions can overlap.

Write a derived track

ds = pbzarr.open("depth.pbz")
ds = pbzarr.write(ds, {"over_10": (ds["depth"] >= 10).mean("sample")})

A derived track must cover the whole reference on position, or have no genomic dimension. The write drops 0-d coordinates, for example quantile after quantile(0.5). pbzarr.write takes a path, a URL, or a Dataset from pbzarr.open. It adds the track to the store and returns the store opened again. It does not change the Dataset that you give it. A new track on position gets the import layout of chunks and shards, unless encoding= sets the layout.

Import other files

pbzarr.import_bigwig("signals.pbz", "signal", "sample.bw")

pbzarr.import_bed(
    "scores.pbz",
    "sites.bed.gz",
    genome="genome.fai",
    track="score",
    column="score",
    dtype="float32",
)

BED does not record chromosome lengths. To create a store, a BED import needs a .fai or chromosome-sizes file (genome=, or --genome in the CLI). An import into an existing store takes the lengths from the store.

import_bigwig and import_bed take fill=: a number, True or False for a bool column, or "na". By default, gaps are missing, as in the CLI (see below). A schema= entry of import_bed is a dtype string or a dict with the optional keys "track", "dtype", and "fill". xarray reads an integer track with nulls as a float track: float32 for 8- and 16-bit integers, and float64 for 32- and 64-bit integers. reduce_regions reads the stored integers and skips the nulls, so it does not hold the rows as floats.

pbzarr.create(path, reference=...) makes an empty store for pbzarr.write. Imports do not need it.

CLI examples

Every pbz command takes the store path as its first argument. Use --track to name the track.

Import a bigWig file into a signal track:

pbz import bigwig signal.pbz sample.bw --track signal

The import reads chromosome lengths from the bigWig header and stores values as float32. A bigWig does not say what a base outside its intervals means, so by default such a base is missing: it contains NaN. Use --fill 0 when the gaps mean 0:

pbz import bigwig signal.pbz sample.bw --track signal --fill 0

A BED import uses the same rule for its value columns. By default, a base that no interval covers holds the null of the dtype: NaN for a float, and the type maximum for an integer. The track declares the null as its _FillValue, so xarray reads an integer track with nulls as a float track with NaN. If you need nullable values, use a float dtype. A bool column and a BED3 mask hold false at a gap. pbz import bed --fill 0 makes the gaps 0. A schema row can give the fill of one track in a fourth column.

dtype null
float32, float64 NaN
int8 to int64, uint8 to uint64 the type maximum
bool none

d4 and BAM/CRAM imports fill gaps with 0, because these sources give a value at every base.

Import several files as labeled columns:

pbz import bigwig cohort.pbz brain.bw:brain liver.bw:liver --track signal --dim sample --shard-columns 1

All sources must describe the same genome. Without explicit labels, the import uses the file name without its format extension as the column label. For example, s1.bed.gz, s1.bw, and s1.cram all give s1. The text after the last : is a label only when it contains no / or \. Thus a URL such as https://host/s1.bam stays one path.

The command accepts the same import options as pbz import d4. These include --file-list, --threads, chunk and shard sizes, --codecs, and --no-progress.

Add samples to an existing cohort track. Append can grow only a track whose shard holds one column, so import with --shard-columns 1 if you plan to append:

pbz append bigwig cohort.pbz heart.bw:heart --track signal

Every variable over the appended dimension grows. Tracks that receive no data read their fill value in the new columns.

Read the sources from a list file:

pbz import bigwig cohort.pbz --file-list sources.tsv --track signal

The source list contains one path per line, optionally followed by a tab and a label. A relative path starts from the directory of the list file. If any source has a label, all sources must have labels.

An import or append writes one summary line to stderr. -q hides the summary line and the progress display. -v gives more log output. You can put -q and -v before or after the subcommand.

Export a track as bedGraph-like text:

pbz view cohort.pbz --track signal -o signal.bedgraph.gz

Select regions for pbz stat or pbz view:

pbz stat cohort.pbz --track signal -s mean -R targets.bed
pbz view cohort.pbz --track signal -r chr1:0-1000000 -r chr2:500-900

-r CHROM:START-END selects one region. You can repeat -r. -R FILE.bed reads regions from a BED file. Coordinates are 0-based and half-open, as in BED. Without -r or -R, pbz view reads the whole genome and pbz stat writes one row per contig.

pbz view and pbz stat write to stdout when you do not give -o. When the store has one track, --track is optional.

pbz view and pbz stat read a track only when position is its first dimension and it has at most one other dimension. They do not read tracks on a bin_N dimension. Use Python for the other shapes. A null marks a missing value. In a float track, the null is NaN. In an integer track, the null is the value of the _FillValue attribute, when the track has one. A float _FillValue must be NaN. pbz view prints a null as NaN and does not write rows where all columns are null. pbz stat skips nulls in all statistics.

Show the layout of a store:

pbz info cohort.pbz
pbz info cohort.pbz --json

pbz info prints the format version, the contigs and their lengths, and the size of each dimension. For each variable, it prints the dtype, dimensions, shape, chunk shape, shard shape, codecs, fill value, null (none when the variable declares no _FillValue), stored bytes, and number of stored objects. --json prints the same data as one JSON object.

Check a store against the format rules:

pbz validate cohort.pbz

pbz validate prints each problem as one line of text. The exit code is 0 when the store is valid and 1 when it is not valid. The check reads metadata, the reference arrays, and the dimension labels. It does not read track values. --json prints the status and the problems, and each problem gives the code of the format rule that it breaks.

Single-file stores

Import into a single zip file:

pbz import d4 cohort.pbz.zip s1.d4 s2.d4 --track depth --zip

A store path that ends in .zip (in any case) also writes a zip store, so --zip is optional here. The store path must not exist. The import writes a temporary file beside the store path and renames it at the end, so a failed import leaves no file.

A zip store is written once. pbz import cannot add tracks to it, and pbz append refuses it. A zip store uses the same chunk and shard defaults as a directory store. An import refuses --codecs without a sharding_indexed codec. pbz view, pbz stat, pbz info, and pbz validate read zip stores.

Open a zip store in Python:

ds = pbzarr.open("cohort.pbz.zip")

The open is read-only. The Dataset works as one from a directory store. pbzarr.write and the Python imports refuse a zip path.

Format

A .pbz store is one Zarr v3 group. Tracks and coordinates are arrays directly under the root.

cohort.pbz/
├── zarr.json        root attributes (zarr_conventions, pbz:version), metadata copy
├── contig_id        contig names     (contig)
├── contig_length    contig lengths   (contig)
├── sample           column labels
├── depth            (position, sample)
└── over_10          (position,)
  • The reference is the two root arrays contig_id and contig_length, over the dimension contig. The names are fixed. Their order defines the genome: the position dimension is all contigs concatenated in that order. An optional contig_md5 array can hold a checksum for each contig.
  • Readers find arrays by name and dimension names. A track is an array whose first dimension is position or bin_N. The coordinates attribute that pbzarr writes is only for xarray; a store without it opens the same way.
  • Offsets are not stored. The first row of contig i is the sum of the lengths before it, so the rows for chr2:10-20 are that sum plus 10 up to that sum plus 20. All coordinates are zero-based and half-open.
  • A column axis such as sample has a label array of the same name. Tracks that share it share its labels.
  • Binned tracks use a bin_N dimension. Bins restart at each contig, so a contig's last bin can be short.
  • The root zarr.json holds a consolidated copy of the metadata of every array. Each import, append, and pbzarr.write replaces it as its last step, so a reader that cannot list the store can still find every array.

Every track declares one data type and fill value. Imported tracks are chunked and compressed with Blosc (zstd with byte shuffle) by default; imports can override the codec pipeline and chunk grid with standard Zarr v3 metadata (--codecs on the CLI, codecs= in Python). A store opens with plain xarray (xr.open_zarr), with no pbzarr code.

pbzarr reads and writes format 0.5 only. It refuses a format 0.4 store, which used one group per track. To read such a store, use pbzarr 0.7, or import the data again.

See the format specification for the full rules and the design document for the Rust API.

Status

pbzarr is under active development and has not reached version 1.0. The API and file rules can change. Remote writes and variable chunk sizes are planned.

Development note

The per-base Zarr format that pbzarr standardizes was first prototyped by hand in clam, where the initial concepts (the contig-major layout, cohort-shaped tracks, and the zarr/ndarray I/O path) were fleshed out before AI tooling was introduced. pbzarr lifts those concepts into a dedicated, spec-driven library.

From that point, development of pbzarr was heavily assisted by Claude (Anthropic), accelerating the library implementation, d4 import, tests, and documentation. The architecture, domain knowledge, and direction remain the author's own; Claude was used as an accelerant, not an author.

Metadata

Release files for pbzarr 0.9.0

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

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Built distributions (wheels)

Table of built distributions (wheels) for pbzarr 0.9.0
File Interpreter ABI Platform Actions
pbzarr-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for pbzarr-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl
pbzarr-0.9.0-cp312-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 10.12+ x86-64, macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64) Details for pbzarr-0.9.0-cp312-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl

Total release size: 14.1 MB

Release files / pbzarr-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL pbzarr-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl
Size 5.2 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
d5ec2346cc85fe325c2764630cb887130260cd108055926a21c0d8b074224a5d
BLAKE2b-256 checksum
How to use checksums
b1107f17f97ef260eb0df52a2dd56728cdc5ee65eb3a1c0d78133c2397c8d1a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 14, 2026.

Transparency log

Release files / pbzarr-0.9.0-cp312-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL pbzarr-0.9.0-cp312-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl
Size 8.9 MB
Tags CPython 3.12 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2c1045ba26f4c66eae6d778f121d4a609e4e453e0bd24c7fc1efb4f45a0b1c93
BLAKE2b-256 checksum
How to use checksums
a6825d238111a22f745f92c5c5bb689212f05e5471ffe4c68641e4703aad28b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 14, 2026.

Transparency log

Security for pbzarr 0.9.0

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.

Change of provenance

The configuration that created this release differs from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for pbzarr-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl

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 Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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