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.19.tar.gz (54.1 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.19-cp312-cp312-win_amd64.whl (190.6 kB view details)

Uploaded CPython 3.12Windows x86-64

nj_py-0.0.19-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (310.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nj_py-0.0.19-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (303.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nj_py-0.0.19-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (570.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.19-cp311-cp311-win_amd64.whl (191.1 kB view details)

Uploaded CPython 3.11Windows x86-64

nj_py-0.0.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (309.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nj_py-0.0.19-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (303.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

nj_py-0.0.19-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (570.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.19-cp310-cp310-win_amd64.whl (191.0 kB view details)

Uploaded CPython 3.10Windows x86-64

nj_py-0.0.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (309.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nj_py-0.0.19-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (303.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

nj_py-0.0.19-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (570.2 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.19.tar.gz.

File metadata

  • Download URL: nj_py-0.0.19.tar.gz
  • Upload date:
  • Size: 54.1 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.19.tar.gz
Algorithm Hash digest
SHA256 97ba3ed16d23986076f0d53bb94a19fec5877310da58b55a528a5b26b35dff24
MD5 709d8250eb3b1ec6ab40ceb98edfa235
BLAKE2b-256 8b0e1855e5645023063062daf87b16541f6d6543891bc9d4ea03b26a2593e51a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nj_py-0.0.19-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 190.6 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.19-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b8d00f036cdc7827f05098f313867e7175e83968d0a19241f7029b7e562b9a1f
MD5 c0f97ab6bd4e7e9ff586a6b27c4de6c0
BLAKE2b-256 25ec43e32155dd5e17f71446db92af93be1329b17794812a069d548aaa13810d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.19-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ffa249c9c7501f322edcf9a672b15ef3d239fa5fa2dc0f5b17630ad1c36ab0f
MD5 bbc040f71876242bcc6c941ddf8f9b19
BLAKE2b-256 80befe2d63d73efcc0cbacec6140a88720cb1ecd385601cb357553582e635911

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.19-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a736ccb148253340e0e207a4a741f28a0ced846008146c2d7fa6353e754a3cb
MD5 a4095f7f1ea8fcc05b4874777c9d3e27
BLAKE2b-256 0be6d9d3f29d5887bcea491af7d40b726a7d59dc6e4ac66ebe262d7138d8e344

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.19-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.19-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.19-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 308b4545dfe357e4eba3bf9cc4f8e2d3645e1a4392a3f39c80372791a2430a73
MD5 7db9508521eaa7f1dff2a2e7ee06e89c
BLAKE2b-256 b9bd3f26adb3f58911bc3ba73faa83985957ac0d8677fe01853abb79e6ccec49

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nj_py-0.0.19-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 191.1 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.19-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3c407966e16d08d2bca055b08089272ce164ef276d591cbb90dfcb087c54e01d
MD5 44b7b9159855a601ba34cb51d8f7604e
BLAKE2b-256 f075a23ec2f0597eb63622a89e3f6ff087ef3adfe2daecda08c43e9204e61ea9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f07bea851cc0998da32d77fb373c499efcdbe17c5d14b18dbffce95335d9c7d6
MD5 10408c16f0565b984c39cebe44010c40
BLAKE2b-256 db9d49fd1e439601ea75d608cbef77d0b5e0f3e6a8a17496400b896585ae4f9a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.19-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e17d35d8c2bb5e01006d99e554643a11e42e710dab8c6f440610504810ebdc15
MD5 445811d6001084b053494bd3c5b17618
BLAKE2b-256 0a0ca0db84cd155b8617345eb302903a9459a7883a450e733f45daa60de3af08

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.19-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.19-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.19-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 1efd8bc183fa4e0886376bf50b365dac65f914dd089def14fc696537fa5b3542
MD5 9184bcf89c804d76c70cfcca79a1bef7
BLAKE2b-256 f9bea4cfd12a0fb42d8f05a3dce62879a3fcab4952f0c724b29f8040b7d5a069

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nj_py-0.0.19-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 191.0 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.19-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 04f48c14ccc6a2138808ea520db7f4c9679e942681ded2c8dc59ec2fd0baf3dd
MD5 dc6aed7c24c9392779f150bc9f492219
BLAKE2b-256 3d207d409d3b52e5a651f0ba70fbae4a204a1191e725e69ff65837420c5e1e38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fca63f8b158ef5995e9deb75546b488d0a2ae3c560a62725fea456b8cddc8a50
MD5 94020ac78c0e1785427881ad8e5d2e4f
BLAKE2b-256 d0b90c470cd67ba871f02a3817dfe6b4c7762265fa38e8d58880a9765f5465a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nj_py-0.0.19-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 252d65d58c378362f19d31c51c90b9dd6b4231f484745e4b0137de161b946c51
MD5 2fb53178c358af9db3199f3fed92c1f2
BLAKE2b-256 d1ff9312899127859534e2ca51734766775834e9bff80d9154c2df49b4ef3d8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nj_py-0.0.19-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.19-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.19-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 7cb4d12b926f4c7beafae4b9a5f317d69d37c362ea80de4880eebd4783e98174
MD5 fb8f9e5393afe963fb02bb68b061398d
BLAKE2b-256 af9a270b24263456bbe7a33d95934fc9b3a37654fcc5dc44ad7aa454d6a10c9a

See more details on using hashes here.

Provenance

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