Skip to main content

Phylo2Vec

PyPI version Documentation Zenodo JOSS

LGPL-3.0 License

pre-commit.ci status CI Python CI Rust CI R

Phylo2Vec (or phylo2vec) is a high-performance software package for encoding, manipulating, and analysing binary phylogenetic trees. At its core, the package contains representation of binary trees, which defines a bijection from any tree topology with 𝑛 leaves into an integer vector of size 𝑛 − 1. Compared to the traditional Newick format, phylo2vec was designed with fast sampling, fast conversion/compression from Newick-format trees to the Phylo2Vec format, and rapid tree comparison in mind.

This current version features a core implementation in Rust, providing significant performance improvements and memory efficiency while remaining available in Python (superseding the version described in the original paper) and R via dedicated wrappers, making it accessible to a broad audience in the bioinformatics community.

Link to the paper: https://doi.org/10.1093/sysbio/syae030

Installation

Python package

Pip

The easiest way to install the standard Python package is using pip:

pip install phylo2vec

Several optimization schemes based on Phylo2Vec are also available, but require extra dependencies. (See this notebook for a demo). To avoid bloating the standard package, these dependencies must be installed separately. To do so, run:

pip install "phylo2vec[opt]"

Manual installation

  • We recommend setting up pixi package management tool.
  • Clone the repository and install using pixi:
git clone https://github.com/sbhattlab/phylo2vec.git
cd phylo2vec
pixi run -e py-phylo2vec install-python

This will compile and install the package as the core functionality is written in Rust.

Installing R package

Option 1: from a release (Windows, Mac, Ubuntu >= 22.04)

Note: Pre-built Mac binaries are available for Apple Silicon (ARM64) and Intel (x86_64, macOS 15+ only). Intel Mac users on older macOS versions should use Option 2 or 3.

Retrieve one of the compiled binaries from the releases that fits your OS. Once the file is downloaded, simply run install.packages in your R command line.

install.packages("/path/to/package_file", repos = NULL, type = 'source')

Option 2: using devtools

⚠️ This requires installing Rust to build the core package.

devtools::install_github("sbhattlab/phylo2vec", subdir="./r-phylo2vec", build = FALSE)

Note: to download a specific version, use:

devtools::install_github("sbhattlab/phylo2vec@vX.Y.Z", subdir="./r-phylo2vec", build = FALSE)

Option 3: manual installation

⚠️ This requires installing Rust to build the core package.

Clone the repository and run the following install.packages in your R command line.

Note: to download a specific version, you can use git checkout to a desired tag.

git clone https://github.com/sbhattlab/phylo2vec
cd phylo2vec
install.packages("./r-phylo2vec", repos = NULL, type = 'source')

Basic Usage

Python

Conversion between Newick and vector representations

import numpy as np
from phylo2vec import from_newick, to_newick

# Convert a vector to Newick string
v = np.array([0, 1, 2, 3, 4])
newick = to_newick(v)  # '(0,(1,(2,(3,(4,5)6)7)8)9)10;'

# Convert Newick string back to vector
v_converted = from_newick(newick)  # array([0, 1, 2, 3, 4], dtype=int16)

Tree Manipulation

from phylo2vec.utils.vector import add_leaf, remove_leaf, reroot_at_random

# Add a leaf to an existing tree
v_new = add_leaf(v, 2)  # Add a leaf to the third position

# Remove a leaf
v_reduced = remove_leaf(v, 1)  # Remove the second leaf

# Random rerooting
v_rerooted = reroot_at_random(v)

Optimization

To run the hill climbing-based optimisation scheme presented in the original Phylo2Vec paper, run:

# A hill-climbing scheme to optimize Phylo2Vec vectors
from phylo2vec.opt import HillClimbing

hc = HillClimbing(verbose=True)
hc_result = hc.fit("/path/to/your_fasta_file.fa")

Command-line interface (CLI)

We also provide a command-line interface for quick experimentation on phylo2vec-derived objects.

To see the available functions, run:

phylo2vec --help

Examples:

phylo2vec samplev 5 # Sample a vector with 5 leaves
phylo2vec samplem 5 # Sample a matrix with 5 leaves
phylo2vec from_newick '((0,1),2);' # Convert a Newick to a vector
phylo2vec from_newick '((0:0.3,1:0.1):0.5,2:0.4);' # Convert a Newick to a matrix
phylo2vec to_newick 0,1,2 # Convert a vector to Newick
phylo2vec to_newick $'0.0,1.0,2.0\n0.0,3.0,4.0' # Convert a matrix to Newick

Datasets

Description of the datasets as well as download links are available in in the datasets directory.

Datasets for which a FASTA file is available can be downloaded and loaded into Biopython:

from phylo2vec.datasets import load_alignment

load_alignment("zika")

Readily downloadable datasets can be listed using:

from phylo2vec.datasets import list_datasets

list_datasets()

Documentation

For comprehensive documentation, tutorials, and API reference, visit: https://phylo2vec.readthedocs.io

How to Contribute (issues, feature requests...)

Found a bug or want a new feature? We welcome contributions to phylo2vec! 🤗 Feel free to report any bugs or feature requests on our Issues page. If you want to contribute directly to the project, fork the repository, create a new branch, and open a pull request (PR) on our Pull requests page.

Please refer to our Contributing guidelines for more details how to report bugs, request features, or submit code improvements.

Thanks to all our contributors so far!

Contributors

License

This project is distributed under the GNU Lesser General Public License v3.0 (LGPL).

Citation

If you use Phylo2Vec in your research, please cite:

@article{10.1093/sysbio/syae030,
    author = {Penn, Matthew J and Scheidwasser, Neil and Khurana, Mark P and Duchêne, David A and Donnelly, Christl A and Bhatt, Samir},
    title = {Phylo2Vec: a vector representation for binary trees},
    journal = {Systematic Biology},
    year = {2024},
    month = {03},
    doi = {10.1093/sysbio/syae030},
    url = {https://doi.org/10.1093/sysbio/syae030},
}

If you use the software, please cite:

@article{10.21105/joss.09040,
    doi = {10.21105/joss.09040},
    url = {https://doi.org/10.21105/joss.09040},
    year = {2025},
    publisher = {The Open Journal},
    volume = {10},
    number = {114},
    pages = {9040},
    author = {Scheidwasser, Neil and Nag, Ayush and Penn, Matthew J. and Jakob, Anthony and Andersen, Frederik Mølkjær and Khurana, Mark Poulsen and Setiawan, Landung and Duchêne, David A. and Bhatt, Samir},
    title = {phylo2vec: a library for vector-based phylogenetic tree manipulation},
    journal = {Journal of Open Source Software}
}

Metadata

Release files for phylo2vec 1.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phylo2vec 1.8.1
File Size Uploaded Provenance Actions
phylo2vec-1.8.1.tar.gz 109.3 kB Without provenance Details for phylo2vec-1.8.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for phylo2vec 1.8.1
File Actions
phylo2vec-1.8.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for phylo2vec-1.8.1-cp310-abi3-win_amd64.whl
phylo2vec-1.8.1-cp310-abi3-win32.whl CPython 3.10 abi3 Windows x86-32 Details for phylo2vec-1.8.1-cp310-abi3-win32.whl
phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_x86_64.whl
phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_i686.whl CPython 3.10 abi3 Linux musl 1.2+ x86-32 Details for phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_i686.whl
phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_armv7l.whl CPython 3.10 abi3 Linux musl 1.2+ ARMv7l Details for phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_armv7l.whl
phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_aarch64.whl
phylo2vec-1.8.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for phylo2vec-1.8.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
phylo2vec-1.8.1-cp310-abi3-manylinux2014_s390x.manylinux_2_17_s390x.whl CPython 3.10 abi3 Linux glibc 2.17+ IBM System/390x Details for phylo2vec-1.8.1-cp310-abi3-manylinux2014_s390x.manylinux_2_17_s390x.whl
phylo2vec-1.8.1-cp310-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl CPython 3.10 abi3 Linux glibc 2.17+ PowerPC 64-le Details for phylo2vec-1.8.1-cp310-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
phylo2vec-1.8.1-cp310-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl CPython 3.10 abi3 Linux glibc 2.17+ ARMv7l Details for phylo2vec-1.8.1-cp310-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl
phylo2vec-1.8.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for phylo2vec-1.8.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
phylo2vec-1.8.1-cp310-abi3-manylinux1_i686.manylinux_2_5_i686.whl CPython 3.10 abi3 Linux glibc 2.5+ x86-32 Details for phylo2vec-1.8.1-cp310-abi3-manylinux1_i686.manylinux_2_5_i686.whl
phylo2vec-1.8.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for phylo2vec-1.8.1-cp310-abi3-macosx_11_0_arm64.whl
phylo2vec-1.8.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for phylo2vec-1.8.1-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 16.5 MB

Release files / phylo2vec-1.8.1.tar.gz

Download URL phylo2vec-1.8.1.tar.gz
Size 109.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4fa1cb1e5e513dd7895337e5d947806c1aedc08d2188c28bcf9c68ae1e697634
BLAKE2b-256 checksum
How to use checksums
4f32bf772a1fead31f9d0614e78636f3ec7fb5662cfc5bd89f126b0c6affc8db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-win_amd64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-win_amd64.whl
Size 918.9 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
18bd898cd8201dc27e176758e308b65d097e66c55e816a4fc80a82602d99a2de
BLAKE2b-256 checksum
How to use checksums
52a8151c7ae33a662c6c238b57a1418bf6a883642a81e9926ffca8452a8cec06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-win32.whl

Download URL phylo2vec-1.8.1-cp310-abi3-win32.whl
Size 828.9 kB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
15dc45c91c7851f3bb55aeee6313c7e21a2ee5c6e3c6743cbedbb8dea4b07a0d
BLAKE2b-256 checksum
How to use checksums
df5c98b78cd731695f8f04debb4af04a7bedd5064586d9c958152b12e81eeae1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
6b98d0beea6ffeff361ba89732120d09d1bd5bafd3415cf39741f45666026a75
BLAKE2b-256 checksum
How to use checksums
0d960af41c39a85b49e6bf201e8febc1d8cb02e7211b2ee4ebd429ffcf1368c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_i686.whl

Download URL phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_i686.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
38cf286182e05b046ce968de731111ffe1db1fc6d26b2431902e604293c2e028
BLAKE2b-256 checksum
How to use checksums
7a6fdd807de65570d1e9ebabc6b39ff9ea1d8ac4a5eeff8e4010161d05417727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_armv7l.whl

Download URL phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_armv7l.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
d2fe5b06be82656ca1a47e36ac7307a94a248027537c92368b207b754b043908
BLAKE2b-256 checksum
How to use checksums
1a53bbe95ebc16fdf1cca1071c7094d2a76a9492440602e5a956075f67136b9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.3 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
88f42eb4be206a4592a3f5cff51daaf3fad8c05846844f0aa39f6eef4d9aae9a
BLAKE2b-256 checksum
How to use checksums
90796e2fa9f72130e0021be800f16ec429e580b1471ba4343c9eb37df2975425
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a8b52a3dab13211b2656790bc4b3d3bd8f116f5cab4a50d1a4a802714be4185a
BLAKE2b-256 checksum
How to use checksums
7b5a57d2ccc1ce22411182050a0ae6d08bc2b83bf71c4c79b1d617cc1ed98294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-manylinux2014_s390x.manylinux_2_17_s390x.whl

Download URL phylo2vec-1.8.1-cp310-abi3-manylinux2014_s390x.manylinux_2_17_s390x.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
7b6eee2fa86fe08df42d41cc6aa888f1e50a5fe58bf940c4156d29df50282dc9
BLAKE2b-256 checksum
How to use checksums
6d018f43557745055e37c0f6fb03a1d27d91407b3f29993ddf8a72f3899c3877
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl

Download URL phylo2vec-1.8.1-cp310-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
04d3b4f6491fc6504dc41a4b01d085aceecdb2224f2d173b2e4b2c474b2e8fb5
BLAKE2b-256 checksum
How to use checksums
7bb69f6991e08be335d20e79c97f7846756ed7a80a5273164660c04602127907
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl

Download URL phylo2vec-1.8.1-cp310-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
a5adfcc68ddbdce9130c63009fd47c3723bb2ac0034fbca07056cb8a5b931106
BLAKE2b-256 checksum
How to use checksums
bed6710461ba2b2db1494b602ac55c731520f1aaae4a9d8c37d9ae11cf8dbc89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f4bb72cf01183e564695b1b4cf34417061dfed10c6ecff1c113e12f1b1db7a45
BLAKE2b-256 checksum
How to use checksums
c1dfe4d3ee6b562fa0afc5dd48af36216dc067ef1d1ce5156f2010ddbf3a5915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-manylinux1_i686.manylinux_2_5_i686.whl

Download URL phylo2vec-1.8.1-cp310-abi3-manylinux1_i686.manylinux_2_5_i686.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
9c0727e746e79aaf9292c586e2818b5dd8dedeb7cd2b2398378c8353c12aeff7
BLAKE2b-256 checksum
How to use checksums
ba715bf6ba2af4fccae33b1d9d693d195fb3c36aa3953c7d18eb905b5aed4266
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b7c05009e9b42f06aa4fc3caff365f9a5d2d3a7bf6cb8c1d8f5554f12ffd9a3e
BLAKE2b-256 checksum
How to use checksums
c3e71953705dd1dcdba08d4a8a1e818c19bab5efd0d20156df73ba0422ecafb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / phylo2vec-1.8.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL phylo2vec-1.8.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f552038bbd06bded0fd32bd087043f957cc441ed1aa9f328a9b7eb6f2b26be32
BLAKE2b-256 checksum
How to use checksums
4f6c34228e0cfe20f53ccb724fe15d6b7c194e9394690649f69847b3588111ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Security for phylo2vec 1.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page