Skip to main content

Stream FASTA genomes into packed 4-bit Zarr stores

Project description

genome-zarr-4bit

genome-zarr-4bit turns a FASTA file into a standard, directory-backed Zarr v2 group. Each chromosome is a one-dimensional uint8 Zarr array containing two 4-bit base codes per byte: A=0, C=1, G=2, T=3, and N (or any unsupported IUPAC base) =4. This is the same packed layout used by zarr_compression_benchmark.py; unlike its manual backend, Zarr and numcodecs own the chunking and compression.

The implementation scans the FASTA once for record sizes and streams it on the second pass. It does not load chromosomes into memory. The default logical chunk is 1 MiB of bases (512 KiB packed bytes), matching the benchmark's default 1 MB base chunk.

Install

From this directory:

python -m pip install .

This deliberately uses the stable Zarr v2 API because its numcodecs.Zstd compressor is the format used in the existing benchmark. The package pins zarr<3 to make stores reproducible across installations.

Commands

# FASTA -> packed 4-bit Zarr with Zstandard compression
genome-zarr fasta-to-zstd genome.fa /data/genome.zarr

# compressed -> uncompressed, preserving arrays, chunks, and attributes
genome-zarr decompress /data/genome.zarr /data/genome-uncompressed.zarr

# uncompressed -> Zstandard (also works as a recompression operation)
genome-zarr compress /data/genome-uncompressed.zarr /data/genome-recompressed.zarr

Destinations must be new unless --overwrite is supplied. To select a chunk size or Zstandard level:

genome-zarr fasta-to-zstd genome.fa /data/genome.zarr --chunk-bases 2097152 --zstd-level 6

--chunk-bases must be even, since two bases occupy each byte. Store-level attributes document the encoding and each chromosome array has a logical_length attribute, which removes the one-base padding ambiguity for odd-length sequences.

Each command prints Starting <command>... immediately, then a completion summary with elapsed time, chromosome and base counts, packed-data size, compression mode, and apparent and allocated destination storage. Transcoding commands also print the source store's apparent size.

Python API

from genome_zarr import fasta_to_zstd, decompress_zarr, compress_zarr

fasta_to_zstd("genome.fa", "genome.zarr")
decompress_zarr("genome.zarr", "genome-uncompressed.zarr")
compress_zarr("genome-uncompressed.zarr", "genome-zstd.zarr")

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

genome_zarr_4bit-0.1.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

genome_zarr_4bit-0.1.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file genome_zarr_4bit-0.1.1.tar.gz.

File metadata

  • Download URL: genome_zarr_4bit-0.1.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for genome_zarr_4bit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 72655b07e6f2e22d6cdca0bebb9b3668208a858577d84af3e752ae9e2d7d0b47
MD5 c967d1e08e879de8c56f1e89164159f2
BLAKE2b-256 7d2d4ce79bc0fbfd0118b7e86b8f6e73175544a05d9c0f61d3a221c5b503c28e

See more details on using hashes here.

File details

Details for the file genome_zarr_4bit-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for genome_zarr_4bit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f69e8e0468732846cfa63a67f11123e7de50470f8a55315e689f540aa126cfc0
MD5 565f45c11f9da018935fc12526fb85ee
BLAKE2b-256 c66da348ad2057f9b5801dda22844e58591447a3358355216c67e67b71114565

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