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 v3
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 owns 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 .
The package requires Zarr v3 and explicitly creates every group with
zarr_format=3. Zstandard compression uses Zarr v3's native
zarr.codecs.ZstdCodec; no numcodecs dependency is used for this codec.
Transcode commands can read an existing package-created v2 store as a
migration source, but every destination they create is Zarr v3.
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,
Zarr format, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genome_zarr_4bit-0.2.0.tar.gz.
File metadata
- Download URL: genome_zarr_4bit-0.2.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89da9e4653798e00557f17fcabea18df2b134b8472579e3563c0366d02f681cb
|
|
| MD5 |
8004d81701d8aa53edd5010b294c5264
|
|
| BLAKE2b-256 |
86b8cddd674e53c2e5c51714f60856a92cf7856bc0f7277a578931c85bc9a272
|
File details
Details for the file genome_zarr_4bit-0.2.0-py3-none-any.whl.
File metadata
- Download URL: genome_zarr_4bit-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8722d129d0caeb3a6ba9cf39ebcbb2443f895775c3693595405c2afff38a5cb8
|
|
| MD5 |
72d0cdbc9751ca7490647e3f37334697
|
|
| BLAKE2b-256 |
c4a53bc4b02e76c741e2cc01f5def89f98e7702ca85f6ce5ac4e05390829da8c
|