Skip to main content

Fast NeighbourNet (Rust) with Python bindings

Project description

DOI

fast-nnt

fast-nnt (read Fast Ent) is a simple Rust implementation of the Neighbour Net algorithm with both R and Python bindings.

Introduction

Fast-NNT is a Rust implementation of the NeighbourNet algorithm, designed for efficient phylogenetic analysis. It constructs split trees from distance matrices, providing a fast and reliable tool for researchers in evolutionary biology. R and Python bindings are provided so that users can easily integrate Fast-NNT into their existing workflows.

Why does this exist when SplitsTree is available?

Well, SplitsTree4/6 are GUI-based applications, while Fast-NNT is a command-line tool that can be easily integrated into automated workflows and pipelines. It's meant to be lightweight and simple to use, you provide a simple input and it generates the nexus file. You can then use this file in R or Python to generate your own plots. This is perfect for people who love to manually beautify their visualizations.

Additionally, we provide R and Python bindings that allow you pass in memory data matrices directly with a single command and get results without having to write intermediate files. For installation instructions, please refer to the respective documentation for R and Python.

How do the results compare to SplitsTree?

Fast-NNT aims to produce results that are consistent with those generated by SplitsTree, but there may be differences due to the underlying implementations and algorithms used. Users are encouraged to compare the output from Fast-NNT with that of SplitsTree to assess any discrepancies and determine the best tool for their specific needs.

Comparison to SplitsTree4/6 Comparison of network outputs between SplitsTree4 GUI, SplitsTree6 GUI, and fastnnt CLI using multi-way ordering with conjugate-gradient and active-set inference.

Benchmarks Performance benchmarks comparing fast-nnt, phangorn, splitspy, and splitstree6 across panmictic and three-island population models. Panels show PCA of input data (a–d), elapsed time (e–f), and peak RAM usage (g–h).

Installation

Install Rust via rustup.

Python

You can install the Python package via pip:

pip install fastnntpy

R

You can install the R package via:

install.packages("fastnntr")

# Or if CRAN is unavailable and you have Rust on your machine, i think this will work
devtools::install_github("rhysnewell/fast-nnt", subdir = "fastnntr")

If you are developing locally and have changed the R bindings:

rextendr::document()
devtools::load_all()

CLI

cargo install fast-nnt
fast_nnt --help # or fastnnt --help

Alternatively, you can build from source. Clone and install this repo via:

git clone https://github.com/rhysnewell/fast-nnt.git
cd fast-nnt
cargo install --path .
fast_nnt --help # or fastnnt --help

Usage

For Python and R, complete usage examples can be found in test/python and test/R. But a brief summary is as follows.

Ordering and inference methods

Fast-NNT exposes two knobs that match the algorithmic choices in SplitsTree:

  • Ordering (ordering_method / -O): the cycle construction step.
    • multiway (default) — multi-way agglomerative ordering (alias: splitstree4)
    • closest-pair — closest-pair agglomeration from Bryant & Huson 2023 (alias: huson2023)
  • Inference (inference_method / --inference): the split-weight solver.
    • active-set (default) — active-set NNLS with CGNR inner solver
    • cg — conjugate-gradient NNLS solver (alias: splitstree4)
  • For SplitsTree6-style defaults, use ordering_method="multiway" with inference_method="active-set" (or -O multiway --inference active-set in the CLI).
  • For SplitsTree4-style defaults, use ordering_method="multiway" with inference_method="cg" (or -O multiway --inference cg in the CLI).

Note: When using cg inference on large matrices (N > 2000), we recommend using closest-pair ordering (-O closest-pair). The multiway ordering can produce cycles that cause highly variable convergence times in the CG weight solver depending on input row/column order, while closest-pair ordering produces more consistently performant cycles.

Ordering variance Elapsed time variance across ordering and inference method combinations on n=3333 taxa, showing that closest-pair + active-set is the most consistent.

Python

Set the thread count once per session:

import fastnntpy as fn
fn.set_fastnnt_threads(4)

Read data in via numpy, pandas, or polars:

import fastnntpy as fn
import pandas as pd
data = pd.read_csv("test/data/large/large_dist_matrix.csv")
n = fn.run_neighbour_net(
    data,
    ordering_method="closest-pair",
    inference_method="active-set",
)
print("Labels")
print(len(n.get_labels()))
print("Splits Records")
print(len(n.get_splits_records()))
print("Node Translations")
print(len(n.get_node_translations()))
print("Node Positions")
print(len(n.get_node_positions()))
print("Graph Edges")
print(len(n.get_graph_edges()))

R

Set the thread count once per session:

library(fastnntr)
fastnntr::set_fastnnt_threads(4)

Read your distance matrix in using your preferred method (e.g., data.table):

library(fastnntr)
library(data.table)
data <- fread("test/data/large/large_dist_matrix.csv", header=TRUE)
# Load network
Nnet <- fastnntr::run_neighbournet_networkx(
  data,
  ordering_method="closest-pair",
  inference_method="active-set"
)

The run_neighbournet_networkx function will return an object almost identical to that produced by phangorn, so should be compatible with existing workflows.

CLI

Required input is a symmetrical distance matrix, ideally with a header row indicating the taxa labels. Can be separated by any delimiter.

To generate a split nexus file (mostly) identical to SplitsTree4 and SplitsTree6:

fastnnt neighbour_net -t 4 -i test/data/large_dist_matrix.csv -d output_dir -o prefix -O multiway

Use the closest-pair ordering algorithm:

fastnnt neighbour_net -t 4 -i test/data/large_dist_matrix.csv -d output_dir -o prefix -O closest-pair

Select the split-weight inference method:

fastnnt neighbour_net -t 4 -i test/data/large_dist_matrix.csv -d output_dir -o prefix --inference active-set
fastnnt neighbour_net -t 4 -i test/data/large_dist_matrix.csv -d output_dir -o prefix --inference cg

Output

The output will include a nexus file containing the split network and network layout.

Citations

If you use this tool in your work, please cite the original authors work:

  • Bryant & Huson 2023: D. Bryant and DH Huson, NeighborNet- improved algorithms and implementation. Front. Bioinform. 3, 2023.
  • Bryant & Moulton 2004: D. Bryant and V. Moulton. Neighbor-net: An agglomerative method for the construction of phylogenetic networks. Molecular Biology and Evolution, 21(2):255– 265, 2004.

You can also cite this repository directly:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

fastnntpy-0.2.5-cp313-cp313-win_amd64.whl (429.7 kB view details)

Uploaded CPython 3.13Windows x86-64

fastnntpy-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (693.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fastnntpy-0.2.5-cp313-cp313-macosx_11_0_arm64.whl (553.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fastnntpy-0.2.5-cp312-cp312-win_amd64.whl (432.4 kB view details)

Uploaded CPython 3.12Windows x86-64

fastnntpy-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (692.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastnntpy-0.2.5-cp312-cp312-macosx_11_0_arm64.whl (553.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastnntpy-0.2.5-cp311-cp311-win_amd64.whl (429.7 kB view details)

Uploaded CPython 3.11Windows x86-64

fastnntpy-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (694.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastnntpy-0.2.5-cp311-cp311-macosx_11_0_arm64.whl (555.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastnntpy-0.2.5-cp310-cp310-win_amd64.whl (432.8 kB view details)

Uploaded CPython 3.10Windows x86-64

fastnntpy-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (693.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastnntpy-0.2.5-cp310-cp310-macosx_11_0_arm64.whl (556.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fastnntpy-0.2.5-cp39-cp39-win_amd64.whl (432.9 kB view details)

Uploaded CPython 3.9Windows x86-64

fastnntpy-0.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (694.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

fastnntpy-0.2.5-cp39-cp39-macosx_11_0_arm64.whl (556.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

fastnntpy-0.2.5-cp38-cp38-win_amd64.whl (429.7 kB view details)

Uploaded CPython 3.8Windows x86-64

fastnntpy-0.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (694.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

fastnntpy-0.2.5-cp38-cp38-macosx_11_0_arm64.whl (555.9 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file fastnntpy-0.2.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fastnntpy-0.2.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 429.7 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fastnntpy-0.2.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 dc5780576ae6a8f8f7646a0097f8c87e20b327da5eae436bfd41ecb7edd18733
MD5 99b28282c3f2b95cddbdc66dd9ac9523
BLAKE2b-256 f01053465abe1071ad7dcd2f3604ecb9e5478519ccaf67495ecc7f299c7dddf3

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d09b8c8453fc1efbba5d62962f6768e3630e859ddd42e25dedaf75fde73ea38
MD5 9559e690a5fe97ead4069c1c546854ea
BLAKE2b-256 876265078650b68bd0e139d0fc11ff33dfd8f9333911c3a88fd2005d171e4ed0

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d47a85dd4efac2d27f588d6ba713dc03452cfe63deec8e4f9454d7246248f6c
MD5 05c5c49823faa911140fa86411faa27b
BLAKE2b-256 569f3d0df22c0536de56686bd92884570ff6c9d5a2cec47b99a6e39e78f174ff

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fastnntpy-0.2.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 432.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fastnntpy-0.2.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 85fdcb5b87e9ea80ffff039c6f49bea074c0af864eff88e8e732d2a0673ed582
MD5 3eeac21ff316596a9ebffb6f3725ead2
BLAKE2b-256 7464ffd09ad0aa2fbe0e10171caf0ec32028395c40c4e9af21b670a4f579e358

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4293d32bc004efa1ac7984c43e0881747d84f68ee14df13eeaea7276478b5055
MD5 939babe1cfb355dddbebb5c7d47d766a
BLAKE2b-256 377100f450d5d3a9c22fac02b1b61021069665436882cb77672f5df3cf9de0b5

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ff68722ce45461eb497c2b4c92737f7b74dd0a6da84dfd0cfb7462163f2e667
MD5 5985e6ce2509f4e6b7e6fb373cd63cf5
BLAKE2b-256 39fcfdd0b54206db356349f3720da160da6b495d02dbb1b4aeb9d6d871db9f39

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fastnntpy-0.2.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 429.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fastnntpy-0.2.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3dd7634c1b15e45d470b621ccd61b5612a9927b90f777400bcd47aedee61e115
MD5 d7a96c6e999e12831dcb2a9c751707b2
BLAKE2b-256 8e4a1d128e7241adcc57260b0624a282186ef3c06647dab6e3e89fd33b27a865

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2d3d8c76ffb9b1282111c4cfcf4818c77f5db10c4dd6a222a4f61c909c49c53
MD5 36136e96020183be4ee4cd18a27cc275
BLAKE2b-256 b326b6fcf58247237c18cbc82decd155e621c9580852f7fc6bea2befcbb7a86e

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ac17ba3d9d2a231b5f0ff6712196d8eed6c5e626e645305fe559371e887a8dd
MD5 53fbbcc8f1fad675dd0e0c01565ddf08
BLAKE2b-256 de950a00610d0dbbc4f8ecac8302bb184a12c908a429139708f7b684cbc18d0c

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: fastnntpy-0.2.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 432.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fastnntpy-0.2.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2cf0a6aa66a4cf37b740d447d3d0faefd0b352b7fc7257ebc3e93894d9198f8b
MD5 c8d3d87e708ec43d3c6dcb9b2d2d0328
BLAKE2b-256 65140aba90d3a13e1d53e1c440ee270968393ef063c4df15a23b30a0f5816c0e

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ada01063f9c5623f1ce41273472d9bb46fc05e59d889f5139acd4d6f1f68118e
MD5 213dfaadcadabcb5e09965b6f0275013
BLAKE2b-256 17a3721d8e1c23c293fcb20771faaf0834480490ff68ee91eb16870469092168

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 980fb77fd6e51251c987e60fe6d7b126a72d5d6216997a32358c78be325fb9db
MD5 f4da93b2b693685692871961ed33e8ae
BLAKE2b-256 ab12d244d9e81c738d6856b373b8c70a1e0ae1af3e77194a24c37e33e552f22b

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: fastnntpy-0.2.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 432.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fastnntpy-0.2.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f5d79852933afd78c7b40c5fd126ffea6ba8e2d9390fdc2f42095c2844fff084
MD5 b1ee4e51c03c5745ddbdf741db40c03b
BLAKE2b-256 dcea5a82d2f7ebffc4f9d3210bed79d92ee98c149823e1596bdf949966f7cc69

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ce6e1287fd792cd0248cd721f8fe6b9a1f5115fccb20d4f894233ab4e525ebf
MD5 afc9cc979f39c10a578293184b6b5cca
BLAKE2b-256 52b2cf76913628f20a2003d5593242f97422467eaeef0fb837a32861e2e1b2e2

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 acc6330156139780282b66ffefa2c264ed7e3900e524975d01b466d7ec534195
MD5 9ac30ba07d6ff997c84ea1880ebead5e
BLAKE2b-256 299519479631d525f5029881520ba95d56456dc9ab4b58ef0f440b6a5eb2501e

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: fastnntpy-0.2.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 429.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fastnntpy-0.2.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0bb6a33b703f474b7f2d29b7b527843a1afee0cc9b38b51b756b8327cd44cc10
MD5 0c5c80629673a29318a2ce58f56e6ff2
BLAKE2b-256 93ee2d5296286f1427eab1c976a19b6b63aa2f27e0ed5e90135f23243a02cb5a

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8fa35e88de5c1730db7dc79ddc381ad00672e23d47ae4991e81712e603f4701
MD5 aa1d2d48d948407a2c486669521f4afb
BLAKE2b-256 8e1ccc7aa95b1cdbc6d34f8e83e2a9cf850b133f07492918bb47d809da77456f

See more details on using hashes here.

File details

Details for the file fastnntpy-0.2.5-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastnntpy-0.2.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc28967c1779d2f51b8d8e5134bc3f714698b03bf15876bd14207b982c5925e8
MD5 0d46b3d409d862a3a2483a1c4502b89b
BLAKE2b-256 e31458677a87b6c5e051e245baf91134fa9f0c8a705a88788b39d0a6ed73d0e1

See more details on using hashes here.

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