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}
}

Related Work

Metadata

Release files for phylo2vec 1.8.0

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.0
File Size Uploaded
phylo2vec-1.8.0.tar.gz 106.1 kB Details

Built distributions (wheels)

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

Total release size: 16.7 MB

Release files / phylo2vec-1.8.0.tar.gz

Download URL phylo2vec-1.8.0.tar.gz
Size 106.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0a80bcab34cd21b41dd9c9350f2f0a77808d132534a80a698d06777726db3e6a
BLAKE2b-256 checksum
How to use checksums
273fe693c793c9cd075cb31546d1123c8a6f9dc8af5bf7fcca50032acabab09e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-cp310-abi3-win_amd64.whl
Size 921.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d15017c7af85474c684f1d53eee482e67bc2b7a5ce964896dad05faad1154e82
BLAKE2b-256 checksum
How to use checksums
9d40c3daf913d36d57e9dad986cfccb7fee713db91fea1bac9924cfc4b728353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-cp310-abi3-win32.whl
Size 832.6 kB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
30ba15f0e71c6f94f6166b6786368a36401cc9e4a660e03afa74c2e4b57339f4
BLAKE2b-256 checksum
How to use checksums
6e31bba7b78b70564f3967c3c726f19066ab6fefa1ed3d140e7eea3ff2a3f918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-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
2f5347eb041035c691e3b0381f00b1ced4f7b93611292ba6080c2d8a8fde242a
BLAKE2b-256 checksum
How to use checksums
6128a51d80531543f14578a096c816b82ab7d7fe2bf98940499e01ac64917bcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-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
e4eeada2d8141bf4e45668bc5f43c91f061b0a322c5f1ce1705a04ecc56c0308
BLAKE2b-256 checksum
How to use checksums
a03d4c6eb04264abb29f1b982efbd6a2e0af33a73f7929a8bebc95b49775b50a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-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
3f15c2590a11d72e7f11beb18d58aa5653c17642d1c774d4150e56bd78306ff0
BLAKE2b-256 checksum
How to use checksums
9cbc67bb035298f379d84d5f2ad3ad8282ea8225d8437b0e0b4abfef2b837da5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-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
16d04082b2e904a9a266b8b17abd74028e08b5cd774d7c2eda40268887d37ff5
BLAKE2b-256 checksum
How to use checksums
1c892fd1004241f12b8895906eb5aae07f6dc47a5d7bf0c5946665e995bc6f7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_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
91ebe20449b129991e00b9cd54c8f16568c29d2dfb42c0ab5e705170e4731608
BLAKE2b-256 checksum
How to use checksums
6b31c3b4221c7d32a6a313e8ba92142b0a3d63c8a3969e55ef55a78eeb849ae3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_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
2e3552fee4f7bc3aa0af09df2eecccc3c114150c2e4d7636f4d7ffe395a6d244
BLAKE2b-256 checksum
How to use checksums
a3be62a33cd60f7c410ae19e0cffd73f4cdf77cce5899cb4d965e4de89b621db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_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
b8de4d3fad3c913d50faa67407aa6cbd2b06c2bbd720d60cccd6efe6c666b1cb
BLAKE2b-256 checksum
How to use checksums
6394225bc271f43f367e892ec41662c9296ef30ac01a74c87391b0c4cdd8eb87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

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

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

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

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

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

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

Download URL phylo2vec-1.8.0-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
10b924aabbd90968f0c2b31b8e9bd72320cd5f33c8b13fa3305037075f2f7e28
BLAKE2b-256 checksum
How to use checksums
221ffbb5ba0eca6b45bac8721243e648f7ad502113e402ceff78d6df3f057ec6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

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

Download URL phylo2vec-1.8.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b84e7e30c4b916d2d6b684f8a2ecd1345e20c6b9b29c8b3fffaab6b07ec3514a
BLAKE2b-256 checksum
How to use checksums
85c3d0bfdccf5619ed2d03bb7b00b783adf7d51198422ac7f1d929866fc08176
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release history Release notifications | RSS feed

This release

1.8.0 This release

15 release files

1.7.0

15 release files

1.6.0

23 release files

1.4.1

15 release files

1.3.1

15 release files

1.2.0

15 release files

1.1.1

15 release files

1.1.0

15 release files

0.1.12

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

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