Skip to main content

Crate nj

Crate nj 

Source
Expand description

Neighbor-Joining phylogenetic tree inference library.

§Data flow

[FASTA / Python dict / JS object]
        │
        ▼
     NJConfig  (config.rs)
        │
        ▼
  detect_alphabet()  ──►  Alphabet::DNA | Alphabet::Protein
        │
        ▼
    MSA<DNA|Protein>  (msa.rs)
     ├── bootstrap() ──► bootstrap_clade_counts()
     └── into_dist::<Model>()
              │
              ▼
          DistMat  (dist.rs)
              │
              ▼
        neighbor_joining()  ──►  NJState::run()  (nj.rs)
              │
              ▼
          TreeNode  (tree.rs)
              │
              ▼
          to_newick()  ──►  Newick String

§Public API

The single public entry point is [nj], which accepts an NJConfig and returns a Newick string. Everything else is internal implementation detail exposed only to the Python and WASM wrapper crates.

§Model–alphabet compatibility

ModelDNAProtein
PDiff
JukesCantor
Kimura2P
Poisson

Providing an incompatible model returns an Err from [nj].

Re-exports§

pub use crate::config::DistConfig;
pub use crate::config::MSA;
pub use crate::config::NJConfig;
pub use crate::config::NJResult;
pub use crate::config::SequenceObject;
pub use crate::distance_matrix::DistanceResult;
pub use crate::error::NJError;
pub use crate::event::LogLevel;
pub use crate::event::NJEvent;
pub use crate::fasta::parse_fasta;

Modules§

alphabet
Alphabet definitions and encoding for DNA and protein sequences.
config
Public configuration types shared between the core library, Python bindings, and WASM bindings.
distance_matrix
Lower-triangular pairwise distance matrix and entry point for NJ.
error
Error type for the nj library.
event
Event types fired by the NJ algorithm and forwarded to wrapper callbacks.
fasta
FASTA parser for multiple sequence alignment input.
models
Substitution models for computing pairwise evolutionary distances.
msa
Multiple sequence alignment container and bootstrap resampling.
nj
Core Neighbor-Joining algorithm implementation.
tree
Binary tree representation for Neighbor-Joining output.

Functions§

average_distance
Computes the mean of all n*(n-1)/2 unique pairwise distances.
distance_matrix
Computes pairwise distances from an aligned MSA and returns a DistanceResult.
nj
Infers a phylogenetic tree from an aligned MSA and returns an NJResult.