Skip to main content

Neighbor-Joining phylogenetic tree inference. Auto-detects DNA/protein, supports multiple substitution models and bootstrap.

Project description

nj.rs

Neighbor-Joining phylogenetic tree inference in Rust, with Python and WASM bindings.

Release Tests

Crates.io Version PyPI - Version NPM Version

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

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' });

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

nj_py-0.0.22.tar.gz (55.4 kB view details)

Uploaded Source

Built Distributions

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

nj_py-0.0.22-cp312-cp312-win_amd64.whl (193.4 kB view details)

Uploaded CPython 3.12Windows x86-64

nj_py-0.0.22-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nj_py-0.0.22-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (307.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nj_py-0.0.22-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

nj_py-0.0.22-cp311-cp311-win_amd64.whl (193.7 kB view details)

Uploaded CPython 3.11Windows x86-64

nj_py-0.0.22-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nj_py-0.0.22-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (306.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

nj_py-0.0.22-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.4 kB view details)

Uploaded CPython 3.11macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

nj_py-0.0.22-cp310-cp310-win_amd64.whl (193.6 kB view details)

Uploaded CPython 3.10Windows x86-64

nj_py-0.0.22-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (313.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nj_py-0.0.22-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (306.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

nj_py-0.0.22-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.6 kB view details)

Uploaded CPython 3.10macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file nj_py-0.0.22.tar.gz.

File metadata

  • Download URL: nj_py-0.0.22.tar.gz
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nj_py-0.0.22.tar.gz
Algorithm Hash digest
SHA256 3e407afc55b45330d6eb1ca80e37e9c7efa4adf43b4c1f6bb65eba390607a17d
MD5 c1f75ba0035f00359872d5683e424107
BLAKE2b-256 cc50364f25da4d273d8bbc88789b4c5e31cdaf977a1218b9686a43f2a186cc13

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22.tar.gz:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nj_py-0.0.22-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 193.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nj_py-0.0.22-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f506e6386441abc28465217173ae8f4bf158b97a09ebd5cfecc4ad5de593e431
MD5 0adc2479f27f081e40e2d3d4a03f54bb
BLAKE2b-256 3c719f89ee72a3ce3600b28284c601897ab08dfb4079227caa811d213be84c6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp312-cp312-win_amd64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07344bb2f1eadde293982385952c033ed1b1777f597c24477f6db1112d157eef
MD5 2ee0584e5ae598b64230b890a9a8e330
BLAKE2b-256 b679fe4852a0d77be081b3226aba1aeba146e61be1c8680e03abc62cf179fdff

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 86ce67ba09fe39e55587d2a9f86818e5fecead293f46b4f44ab08696e5b66d83
MD5 c287560f3e4081a89b678fdc34b4df21
BLAKE2b-256 c758869a95dcc3eadbbedf9369f158cdc0ce08510ad63de8ac3017baadaf4ff6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ec742e74b9e9c0de75f7d062393f288f060f2a1fb001db6f6da755567174f0c6
MD5 9a39b7be06250625912f48e190407f95
BLAKE2b-256 456a3f6ce394eaec066bd350caede5690089c488c55e4b70c98adb79ed29f884

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: nj_py-0.0.22-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 193.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nj_py-0.0.22-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3eda335aab7d08e8678e4c60ba15a82d97381f5c22c8b14de311ecc740579f30
MD5 79c5430cb705d313b6c4d14a37a796da
BLAKE2b-256 0e2b8e196f493f19a6a8b6b6041bdeb250e2bd1affb7eff75c2d4b92fed761fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp311-cp311-win_amd64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35109a2afde316dc4279c95b3cdb58f3135fc3c27f6f145f2e68887e35e1f3d6
MD5 6c8505465fb1cf46bd963ec831d6fc90
BLAKE2b-256 477eb4271d2048b69b6b59d4057e2608a69f9734a0fb3d9035f1723d74aac4c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 947d69c73fdcb8a7c0be57cb104269421a26476b476587637ffc3095b0875759
MD5 d69483faa2d7c053563f2b4d7c50aff1
BLAKE2b-256 4ce819009c3b4466552fbd91bf64f03ee1b2123c96f195ec687d53c2f54ef11a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 aee45b5f2b98e33b6de2f222079e5a3b055c20dd2087b53cff31e822cc8711f0
MD5 dc18484cca26e5f8eeafef83ad417855
BLAKE2b-256 1816d518068c1703211432115b269fefb388e519fedb0aee43516edf3554eaad

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: nj_py-0.0.22-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 193.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nj_py-0.0.22-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cc389b01893b7877b37f87b34cf5e1c113f33ba769ce0b001c739daff2bc8abd
MD5 bbc3c269451e135ea9ba1c1d7c2ea4c1
BLAKE2b-256 be6375a304a9d18fbc607df3f06417863dce9383606327c065cd7b3e4718360b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp310-cp310-win_amd64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a66880fd365ed9b46afbc79b4e5c9bd0126b7fed8a01520964f4c18ac9a2e61f
MD5 28a5fadb15f2700d9e19fb1a9003756d
BLAKE2b-256 47c5825c9f83eba675687680fbf5daa2eaaf48188fa7d09bf79869de15c07a5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d1c70e7b6d62b6e3253c9592fba3ebde3927f47c18e6d4c17efa22fb26720d31
MD5 e9f2e6936ac6e6db2f7603b9c33c1af0
BLAKE2b-256 cca296fecff939d47ac7cac1b3733cbe09382760740f2a739c91b4ed36b03c75

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nj_py-0.0.22-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for nj_py-0.0.22-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 2a0977095f20203991694be4b57678edfa6dd8cbbefa29d91ab2d2a2d108e68b
MD5 4baded089e40af603fa4110a8536ef84
BLAKE2b-256 58e6f4c2900f699fc990d00bec06ec1051415473ddafa058701a163712eb9b7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.22-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on holmrenser/nj.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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