This release is a pre-release and may not be stable for production use.
zani 🧬🗜️🤪
pronounced zany (/ˈzeɪni/)
Average Nucleotide Identity (ANI) estimator using Zstandard compression distance.
About
zani computes pairwise genomic distances using the Normalized Compression Distance (NCD) metric.
Inspired by the pioneering work of LZ-ANI, zani leverages the
blazing-fast Zstandard (zstd) compression algorithm to estimate Average Nucleotide Identity (ANI) without the need
for expensive sequence alignments or k-mer counting.
The Algorithm
At its core, zani treats reference genomes as compression dictionaries. For a given reference genome $x$ and a query genome $y$:
- Dictionary Training: A Zstd dictionary is trained on the reference genome $x$.
- Baseline Compression: We compute $C(x)$, the size of the reference genome compressed with its own dictionary.
- Conditional Compression: The query genome $y$ is compressed using the dictionary trained on $x$. This yields $C(y|x)$, representing the amount of novel information in $y$ not found in $x$.
The Math
zani calculates distance using the standard Normalized Compression Distance (NCD) formula:
$$ NCD(x,y) = \frac{C(x,y) - \min(C(x), C(y))}{\max(C(x), C(y))} $$
To achieve maximum execution speed, zani approximates the joint compression size $C(x,y)$ as:
$$ C(x,y) \approx C(x) + C(y|x) $$
Furthermore, to avoid the performance penalty of compressing the query genome twice to find its baseline $C(y)$, zani rapidly estimates $C(y)$ using the ratio of their uncompressed lengths ($|x|$ and $|y|$):
$$ C(y) \approx C(x) \times \frac{|y|}{|x|} $$
This mathematical approach, combined with zero-copy memoryviews and thread-local C-contexts, allows zani to stream thousands of genomes through concurrent worker threads, achieving massive I/O throughput and utilizing 100% of available CPU cores.
Installation
zani can be installed with pip:
pip install zani
CLI Usage 💻
zani has a very basic CLI, use it like so:
❯ uv run zani -h
usage: zani <genomes ...> [options]
🧬🗜️🤪 Average Nucleotide Identity (ANI) estimator using Zstandard compression distance.
📁:
Input arguments
<genomes ...> Paths to genomes in fasta format; Files may be compressed.
-a, --allvsall Run all-vs-all comparison
🛠️:
Other options
-t, --max-workers Maximum number of threads to use for parallelization
-v, --version Show version number and exit
-h, --help Show this help message and exit
API Usage 💻
from pathlib import Path
from zani import ZaniEngine
genomes = Path('genomes').glob('*.fasta.gz')
with ZaniEngine() as engine:
for result in engine.query(genomes):
print(result)
💭 Feedback
⚠️ Issue Tracker
Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.
Release files for zani 0.0.1a2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zani-0.0.1a2.tar.gz | 36.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zani-0.0.1a2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 69.9 kB
Release files / zani-0.0.1a2.tar.gz
| Download URL | zani-0.0.1a2.tar.gz |
|---|---|
| Size | 36.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b56c6d2533ccafb8fbb5f44537cd7433a21ca2fd4a40184bd9d42344c38a8ff
|
|
BLAKE2b-256 checksum How to use checksums |
f66e07b2a6c8fcaaf1925ddb53fd5cc1c52ddd8aa76ec13b233aae6da800e824
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 8, 2026.
Transparency logRelease files / zani-0.0.1a2-py3-none-any.whl
| Download URL | zani-0.0.1a2-py3-none-any.whl |
|---|---|
| Size | 33.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52d60f71bdc8ef0c24fd9b89757da320802d1be84fbbf0bfd105641bb669bbca
|
|
BLAKE2b-256 checksum How to use checksums |
8fbea6f4099a509bd3fcb2a91fbd8bbdbce5114210dad550011aaafd57c24fe4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 8, 2026.
Transparency log