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.21.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.21-cp312-cp312-win_amd64.whl (193.4 kB view details)

Uploaded CPython 3.12Windows x86-64

nj_py-0.0.21-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nj_py-0.0.21-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.21-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.4 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.21-cp311-cp311-win_amd64.whl (193.7 kB view details)

Uploaded CPython 3.11Windows x86-64

nj_py-0.0.21-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nj_py-0.0.21-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (306.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

nj_py-0.0.21-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.5 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.21-cp310-cp310-win_amd64.whl (193.6 kB view details)

Uploaded CPython 3.10Windows x86-64

nj_py-0.0.21-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nj_py-0.0.21-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.21-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (577.5 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.21.tar.gz.

File metadata

  • Download URL: nj_py-0.0.21.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.21.tar.gz
Algorithm Hash digest
SHA256 451300292f0139d3928967a43747b1b79f5576def4592666d8b1258c8265d646
MD5 4d00c85ff3b0fa120f6f82e87331646b
BLAKE2b-256 79f19336e9cd26e3b84bc44e7ef73a693fa830cb0c09281354c02a1f21b94bb2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nj_py-0.0.21-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.21-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7fd21368180c5d9ae5979a97c33143057a5bf091ce9347f39ad16f1a924bad2f
MD5 ae7b160d0996cdb46f846e0dffec8429
BLAKE2b-256 ff386032a942229914d69d86f2ee12c7687b65ccfb64429369b4a2e190d6502c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.21-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 48c08d33526313667240cd064d496add70bda41a7e41f361a5226ec1be92bc87
MD5 7fed27bd46c689fa062745e04f0a7d01
BLAKE2b-256 2d3e6e8cfddeb64ccdd183fa8890e99ac36107d79106494cdc3a3577adfa9b1c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.21-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0f586379ad18da10708590d6399151896f38d0fc2af7e6b6040466f6831dffb6
MD5 9100d85573d79f24b96c6db4c87af46f
BLAKE2b-256 f336a93d3f566c6a615ab7b977e8121c409378ef920518c10f9b407a9bae7a3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.21-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.21-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.21-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8ac33bf25bc2b712b0ca3157b0d34053534983194ddbb3a976a2051617ed058b
MD5 e74c92e0f0982ed94872f30a5ef799b7
BLAKE2b-256 9bbd47011fc967b095af7ecb85f208edc630380d92201cbc65ca520ba025c59b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nj_py-0.0.21-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.21-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 31172c01439e6fc55bb57f099a31ad496a08a51c13d4946594d9294ce35da82e
MD5 c26e4a08574d8e0e512a7ff3ac1a1bfa
BLAKE2b-256 651208a7ffb7d5a06ffa10789fd9c64bab4f773dfebfb56bf9e4e93e0ac268f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.21-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89d0b293c79ed51de9c3a419a07621a77132ff287a822e516173dc74a882d778
MD5 c5c0b2b00c42a27096c963b099f67e01
BLAKE2b-256 808ff175c6d692e4ee43a7f279134328e24b829dbd8c1872b9edb13ac2d57805

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.21-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2d148a3fd44687da2683ae7ef4537c332031c80bb83209b3d76136c80c3c114d
MD5 8a9f8a702ae072a94535f4c1921a5ee2
BLAKE2b-256 2799c18a5db3113132280fb25a490dc9762b5d01438208f2ed08e1638d8b2f94

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.21-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.21-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.21-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 76c8ead774f786673cda8912d69f65005ae19ef4589507fd5b3453e60a543d65
MD5 923f3568fbb5b0f8e807d4cc84cabca8
BLAKE2b-256 df9b01925be112ba6e11a3bf73e820ae2fbe5f0300e06927d87add95ef848fb6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nj_py-0.0.21-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.21-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7c6e559697da6245c9c50fc4e3ce41e761ed134d5b310c73153b7ce48dff51ce
MD5 4e9afeb1fc248c0332c219ffe6de2eb8
BLAKE2b-256 438b62cf14676eb1f723e3574e8794cc5a83239b03ece5b7d06986582b0a0400

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.21-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5996f36ae9729aa55156f9f0af7ac21d99887a1a67797310e9df26fe60114240
MD5 ff839252873a94be57ec3641d9289326
BLAKE2b-256 3c63195889a6270666738aa0d2ae21bac050ff2a50c325d5e2c529b71d987ca2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.21-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 45a5f6dbc869401400ef579b4628926d0b45ad1c4ac9eedc79f49974b7d8e6f4
MD5 8a269dea65f33ba08231b01918dd7c1d
BLAKE2b-256 3311e6e215f49683b539d59bbd72d305e0befad028db2f8bf4749b77ce67c385

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.21-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.21-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.21-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 07dd6b11178ab4d2dec8e71be289bc6b218af7e5129e9790dbf323a4b976d35d
MD5 3b58676faa4405890c7d7adfa6d3643d
BLAKE2b-256 580fc6d710d5c2c81098b7501f32171fe47d484858fde4f6e745a05157a5f02d

See more details on using hashes here.

Provenance

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