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.20.tar.gz (55.7 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.20-cp312-cp312-win_amd64.whl (193.4 kB view details)

Uploaded CPython 3.12Windows x86-64

nj_py-0.0.20-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nj_py-0.0.20-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (307.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nj_py-0.0.20-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.5 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.20-cp311-cp311-win_amd64.whl (193.6 kB view details)

Uploaded CPython 3.11Windows x86-64

nj_py-0.0.20-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (313.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nj_py-0.0.20-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (306.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

nj_py-0.0.20-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.3 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.20-cp310-cp310-win_amd64.whl (193.5 kB view details)

Uploaded CPython 3.10Windows x86-64

nj_py-0.0.20-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.20-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (306.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

nj_py-0.0.20-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.3 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.20.tar.gz.

File metadata

  • Download URL: nj_py-0.0.20.tar.gz
  • Upload date:
  • Size: 55.7 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.20.tar.gz
Algorithm Hash digest
SHA256 1b1ea635e2ee550de296ff38cc10c5910dff4e48ea70e88bda35bf3a9579ea1d
MD5 53bc3cb0191e56639dad38d4e9fc2db7
BLAKE2b-256 565d61289ab4dd892003d317eff753271f73a4a9e974767eed63de6ca83b6f2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20.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.20-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nj_py-0.0.20-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.20-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9bf1223b204f19118d4eb3b1f3e71342b95432c075a4a0deacc757c97f5eb876
MD5 729ad3e9f49c2d53ded88826c7f59192
BLAKE2b-256 2dcc395fa7ce3526abcce8bdf939f85107f8ea59a0455e149523c304ea730500

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.20-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b2b21dda372be5e3ea4488e88850c8c0b96fee29b0ccfbc56ae325e095f5f70
MD5 1c56415779cad76856d3ccf6f9383d7c
BLAKE2b-256 2bdd44408fdc43c1f4862978c37360f16b7bb2ac8bca87d4e9e1df46f2d34f36

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.20-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1b4c19d399cdda5e675d0d6af6832e43ca986e05546c3f198b5dd67b7eaeab70
MD5 f011e4b7b731b9b6eba154188d3aabb6
BLAKE2b-256 4b3ffea237fca91083d10b3eef778e30607d3d2c4b248974c6e6d950e2368b63

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-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.20-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 94faaff62ad485369eeba2218b37d64fa8176a045e9d3e5e540ca9ddc157afc5
MD5 9c4a314c3801e6905ca26849a9394c79
BLAKE2b-256 33136d5e76332cbfde5a65dcfda0ec173a78dbcadb262e49d160bf31de13f42c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: nj_py-0.0.20-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 193.6 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.20-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4fdfa8077d1a0daeb3198811c5001e743141f8c75215b77b3d966df0f98c31cd
MD5 688dfe78e87d6735594704ac859e25b8
BLAKE2b-256 d1b0d676f93a83c1a7c8d080bd4ae341740d80bce187434559be462b2aded6cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.20-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c236394c5c227369b9dedbf055a9c97a2170cd376921ab214e509d45713a643
MD5 67afa004837608750cc38f2a615e3942
BLAKE2b-256 640e37db1fdabf6687434df0420b754757b01d08a355a048022596d060906fd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.20-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a3f1aeb22cd8606bc3053662e14a0d565b478859b326e30f228d79d102ad4504
MD5 546ccc6dead6b19cdf46f17f56e40287
BLAKE2b-256 c389b20b00b83332f3a6aa2ff5fc24cf506c5abe9889e5a936d8b167a117ba75

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-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.20-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 66e710b787d07ac932b429ee29402cd3d4e2e68a37e3050e0a6ad1bd615419dd
MD5 70abe6760d8a61b633961b6c30c45312
BLAKE2b-256 414a1917b6eb2c112614afd57acc2d09882a6db57a147c8a8b8ec3189cc90708

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: nj_py-0.0.20-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 193.5 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.20-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c7dc7b759525b6c08d409207782ef92d47eda4f07679b994ba6e8873c114b44c
MD5 ea66d2a1d938ed1bb1a556b2ded55a0b
BLAKE2b-256 2ddc4c1d2cc70b04b6cb71ac67f620d0a07271eaa7f75c7ab52b427306b85009

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.20-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99d278919b1d2f95f1105ed9ee37e0912dd9baee6003fa0bf8572c8705dea746
MD5 f8b5bb87f9f04fe7757b7d9420bade8e
BLAKE2b-256 e78442faae43124cf7d532e304b3a3080d6971d0de6f733729d84b4f348747ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nj_py-0.0.20-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e32f8c27efbaf52fcb2582ff2792582869bb6a0d65e392f27534ee286c5d6aa5
MD5 6bfb2fdf0b188ee36525f5a150b39acd
BLAKE2b-256 5d78d208814fcb5873ef176ceb1c50e29e1e1cc707841cae03ad0d73d2579287

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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.20-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.20-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a07c53e3e47d1f6643b7feaf98c3ea7dab01f541a17d8a3539bec83439e8ef4d
MD5 b13a94474fa92d3af16e60e950304902
BLAKE2b-256 605fb522a2f4d1d3e02fb3ae852c3a85b5f3541812316570b9c56d209424ed47

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.20-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