pbzarr
A Zarr v3 convention for storing per-base resolution genomic data — read depths, methylation, boolean masks, and other cohort-shaped per-base values. Built as an alternative to D4 and bigWig that compresses cleanly across samples and integrates with the xarray / zarr ecosystem.
This repo provides:
pbzarr(Rust crate) — store layout, metadata, region I/O. Delegates array storage and compression tozarrs. This is the only crate published to crates.io.pbzarr-readers(Rust crate, unpublished) — input-format readers (currently d4). Kept separate so the core crate stays free of git dependencies and remains publishable. d4 import is reachable from the Python wheel or when building from this repo, not from the crates.iopbzarrcrate.pbzarr(Python wheel) — PyO3 binding forimport_d4plus pure-Pythoncreate_store/create_trackoverzarr-python. Read API is an xarray accessor.
The on-disk format is the same; both libraries write .pbz stores that the other can read.
Install — Rust
[]
= "0.1"
Install — Python
# or from source: pixi run install-wheel
The Python wheel pulls in zarr>=3, xarray>=2024.10, numpy>=2.
Quickstart — Python
# 1. Create the store
# 2. Register a 1D scalar track
# 2b. Or a 2D cohort track
# 3a. Bulk-import from d4 (PyO3 -> Rust)
# 3b. Or write arbitrary numpy data via zarr-python
=
= > 0.5
Read with xarray
= # xr.DataTree
# ['depth', 'mask']
# xr.Dataset (one contig, sliced)
# xr.DataArray
# 1D DataArray
The .pbz accessor on xr.DataTree is registered when you import pbzarr. Regions use 0-based, half-open coordinates (chr1:1000-2000 is [1000, 2000)).
Note: Python
create_store/create_trackconsolidate metadata after each call. Stores written by the Rust crate don't consolidate yet, sopbzarr.open(...)will emit a benignRuntimeWarningfor those; runzarr.consolidate_metadata(path)once to silence.
Quickstart — Rust
use Array2;
use Dtype;
use Config;
use ;
// d4 import lives in the unpublished pbzarr-readers crate (it carries a git
// dependency on d4); depend on this repo by path or git to use it.
use ;
Format at a glance
- Layout: contig-major Zarr v3 store with
<contig>/<track>arrays. Position is the first axis; an optional column dim (default name"column", often overridden to"sample") is the second. - Tracks: 1D for scalar (e.g., masks), 2D for cohort (e.g., per-sample depths). Rank-faithful on disk.
- Coordinates: 0-based, half-open.
- Compression: Blosc(zstd-5, byte-shuffle) on every data array.
- Coord arrays: cohort tracks write per-contig 1D string arrays at
<contig>/<column_dim>listing the column labels; xarray promotes them to coordinates automatically.
For the full design see docs/DESIGN.md.
Links
- Rust API docs: docs.rs/pbzarr
- Design doc:
docs/DESIGN.md - Motivating issues: d4-format#82, d4-format#64, clam#25
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.