nj.rs
Neighbor-Joining phylogenetic tree inference in Rust, with Python and WASM bindings.
Takes a mutiple sequence alignment and returns a Newick string. Alphabet (DNA/protein) is auto-detected. Supports optional bootstrap support values on internal nodes. Optionally, only the distance matrix or average distance can be computed. Wrappers use a plugin system for implementing progress/error logging.
Substitution models: PDiff (DNA + protein), JukesCantor (DNA), Kimura2P (DNA), Poisson (protein)
CLI
cargo install nj --features cli
nj sequences.fasta
nj --substitution-model kimura2-p --n-bootstrap-samples 100 sequences.fasta > tree.nwk
# Bootstrap and distance computation run in parallel by default (the `cli`
# feature enables threading). Cap the worker count with -t/--num-threads:
nj -t 4 --n-bootstrap-samples 1000 sequences.fasta > tree.nwk
A progress bar is shown on stderr when bootstrapping.
Rust
[dependencies]
nj = "0.0.18"
use nj::{NJConfig, NJEvent, SequenceObject, nj, parse_fasta};
use nj::models::SubstitutionModel;
// Parse from a FASTA string
let sequences = parse_fasta(">A\nACGTACGT\n>B\nACCTACGT\n>C\nTCGTACGT\n")?;
// Run Neighbor-Joining
let newick = nj(
NJConfig {
msa: sequences,
n_bootstrap_samples: 100,
substitution_model: SubstitutionModel::JukesCantor,
alphabet: None,
num_threads: None,
},
Some(Box::new(|event| {
if let NJEvent::BootstrapProgress { completed, total } = event {
eprintln!("{completed}/{total}");
}
})),
)?;
Distance-only computation (no tree, no bootstrap):
use nj::{DistConfig, distance_matrix};
use nj::models::SubstitutionModel;
let result = distance_matrix(DistConfig {
msa: sequences,
substitution_model: SubstitutionModel::JukesCantor,
alphabet: None,
num_threads: None,
})?;
// result.names — Vec<String> of taxon names
// result.matrix — n×n Vec<Vec<f64>>, symmetric, diagonal zero
average_distance takes the same DistConfig and returns the mean of all pairwise distances as an f64.
Python
pip install nj_py
from nj_py import nj, distance_matrix
msa = [
{"identifier": "A", "sequence": "ACGTACGT"},
{"identifier": "B", "sequence": "ACCTACGT"},
{"identifier": "C", "sequence": "TCGTACGT"},
]
def on_event(event):
if event["type"] == "BootstrapProgress":
print(f"{event['completed']}/{event['total']}")
newick = nj(msa, substitution_model="JukesCantor", n_bootstrap_samples=100, on_event=on_event)
Distance-only computation:
result = distance_matrix(msa, substitution_model="JukesCantor")
# result["names"] — list of taxon names
# result["matrix"] — n×n list of lists, symmetric, diagonal zero
JavaScript / WASM
npm install @holmrenser/nj
import { nj, distance_matrix } from '@holmrenser/nj';
const msa = [
{ identifier: 'A', sequence: 'ACGTACGT' },
{ identifier: 'B', sequence: 'ACCTACGT' },
{ identifier: 'C', sequence: 'TCGTACGT' },
];
const newick = nj(
{ msa, n_bootstrap_samples: 100, substitution_model: 'JukesCantor' },
(event) => {
if (event.type === 'BootstrapProgress') {
progressBar.value = event.completed / event.total * 100;
}
}
);
const { names, matrix } = distance_matrix({ msa, substitution_model: 'JukesCantor' });
Release files for nj-py 0.0.25
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nj_py-0.0.25.tar.gz | 76.3 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| nj_py-0.0.25-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| nj_py-0.0.25-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| nj_py-0.0.25-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| nj_py-0.0.25-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.10 | abi3 | macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 | Details |
Total release size: 2.1 MB
Release files / nj_py-0.0.25.tar.gz
| Download URL | nj_py-0.0.25.tar.gz |
|---|---|
| Size | 76.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea4d189219fcf411a0296851c1c84d2fc41f269fce3393dc48358a9473b8bd7f
|
|
BLAKE2b-256 checksum How to use checksums |
544256dcc3b75ce4679c08c81c39fed6d91ad6369844e2a5500aa31b874927c0
|
| 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 Jun 4, 2026.
Transparency logRelease files / nj_py-0.0.25-cp310-abi3-win_amd64.whl
| Download URL | nj_py-0.0.25-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 332.2 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6aa493525e774ccbd49979ef9aaf90369094ed4df4559e3782dc9da87e0bb7b7
|
|
BLAKE2b-256 checksum How to use checksums |
312912d61d3221e3fde73f45cd4c563b6749893071448dc69c735e6eee776752
|
| 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 Jun 4, 2026.
Transparency logRelease files / nj_py-0.0.25-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | nj_py-0.0.25-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 446.9 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
109cba7a092aabe3e5c190c6527ff46a55ac7a5476f9dd555691c7e8cb63429b
|
|
BLAKE2b-256 checksum How to use checksums |
bf6ad60ee193e2855ebc54e4bef7766e768ee5c246e4f063acf5f8346a0f3b8e
|
| 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 Jun 4, 2026.
Transparency logRelease files / nj_py-0.0.25-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | nj_py-0.0.25-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 435.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e2428622bf6bcd9aa7103aefe240b9727823a89d9ed28785dd448a72b8c46171
|
|
BLAKE2b-256 checksum How to use checksums |
124c7b79261687bee5a26830462679eca19b10189b1ded9d3da3a5767d1ba6f8
|
| 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 Jun 4, 2026.
Transparency logRelease files / nj_py-0.0.25-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | nj_py-0.0.25-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 818.4 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5f5e2d5b667fd9ed3b39609024f2d563da11c9cbd886b53e011b86d607aaf4be
|
|
BLAKE2b-256 checksum How to use checksums |
250f72ad614ea1b5e69a7728045e6fdb3a6d8daa2a40e6d327653c9f0919b357
|
| 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 Jun 4, 2026.
Transparency log