Skip to main content

Phylo2Vec: integer vector representation of binary (phylogenetic) trees

Project description

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

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

phylo2vec-1.8.0.tar.gz (106.1 kB view details)

Uploaded Source

Built Distributions

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

phylo2vec-1.8.0-cp310-abi3-win_amd64.whl (921.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

phylo2vec-1.8.0-cp310-abi3-win32.whl (832.6 kB view details)

Uploaded CPython 3.10+Windows x86

phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_i686.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_armv7l.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

phylo2vec-1.8.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.5+ i686

phylo2vec-1.8.0-cp310-abi3-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

phylo2vec-1.8.0-cp310-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file phylo2vec-1.8.0.tar.gz.

File metadata

  • Download URL: phylo2vec-1.8.0.tar.gz
  • Upload date:
  • Size: 106.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for phylo2vec-1.8.0.tar.gz
Algorithm Hash digest
SHA256 0a80bcab34cd21b41dd9c9350f2f0a77808d132534a80a698d06777726db3e6a
MD5 e3f79142eb04b9e66a08744a94154ae0
BLAKE2b-256 273fe693c793c9cd075cb31546d1123c8a6f9dc8af5bf7fcca50032acabab09e

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: phylo2vec-1.8.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 921.1 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d15017c7af85474c684f1d53eee482e67bc2b7a5ce964896dad05faad1154e82
MD5 365c779c306a6ac0c5c66c305dd36c48
BLAKE2b-256 9d40c3daf913d36d57e9dad986cfccb7fee713db91fea1bac9924cfc4b728353

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: phylo2vec-1.8.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 832.6 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 30ba15f0e71c6f94f6166b6786368a36401cc9e4a660e03afa74c2e4b57339f4
MD5 808da173f01702066a24d516d0f34e4f
BLAKE2b-256 6e31bba7b78b70564f3967c3c726f19066ab6fefa1ed3d140e7eea3ff2a3f918

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2f5347eb041035c691e3b0381f00b1ced4f7b93611292ba6080c2d8a8fde242a
MD5 864d97558f086c1e07eea60bc8515767
BLAKE2b-256 6128a51d80531543f14578a096c816b82ab7d7fe2bf98940499e01ac64917bcb

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e4eeada2d8141bf4e45668bc5f43c91f061b0a322c5f1ce1705a04ecc56c0308
MD5 5abc8485a74f00e08d33a8b7e182d93a
BLAKE2b-256 a03d4c6eb04264abb29f1b982efbd6a2e0af33a73f7929a8bebc95b49775b50a

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 3f15c2590a11d72e7f11beb18d58aa5653c17642d1c774d4150e56bd78306ff0
MD5 16fe830f52f13552699931eef6bcaed6
BLAKE2b-256 9cbc67bb035298f379d84d5f2ad3ad8282ea8225d8437b0e0b4abfef2b837da5

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 16d04082b2e904a9a266b8b17abd74028e08b5cd774d7c2eda40268887d37ff5
MD5 d41498139901f56dd16120a896077167
BLAKE2b-256 1c892fd1004241f12b8895906eb5aae07f6dc47a5d7bf0c5946665e995bc6f7e

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 91ebe20449b129991e00b9cd54c8f16568c29d2dfb42c0ab5e705170e4731608
MD5 9d01c58991881cb5141e71a4b6261c9d
BLAKE2b-256 6b31c3b4221c7d32a6a313e8ba92142b0a3d63c8a3969e55ef55a78eeb849ae3

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 2e3552fee4f7bc3aa0af09df2eecccc3c114150c2e4d7636f4d7ffe395a6d244
MD5 3436ba8d93f81684b412acacf01b88f4
BLAKE2b-256 a3be62a33cd60f7c410ae19e0cffd73f4cdf77cce5899cb4d965e4de89b621db

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 b8de4d3fad3c913d50faa67407aa6cbd2b06c2bbd720d60cccd6efe6c666b1cb
MD5 ffac9a7ee698ae62a0660ee8bb4a0c33
BLAKE2b-256 6394225bc271f43f367e892ec41662c9296ef30ac01a74c87391b0c4cdd8eb87

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 545633e17a86105310d1d55b5ab70d1916783702389e054be63e948e83e7105d
MD5 9f56a595e841cb1b17efd5e1941327a5
BLAKE2b-256 6f10bb4641d73dc183b7140b5f960fedddd42f9968eaa39359ce4c4181b0cbb3

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c5991c69f67a069bf33896aa7ceefdc9a532b21bcec198f5475f7d77317ae007
MD5 f5a4222d50132a17d0b34583fe0c6a0b
BLAKE2b-256 ca009043bd2ce3b5733f56865af6b4128538fcd14148012b393d88f9380fb7de

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 16a47af0275acfb958771f46efa6aaaeb5198fbcec59cedf274218858551a622
MD5 bfdfc7b9bb8758655c634bf3f2ed901d
BLAKE2b-256 0ae9299e4305895172b7096f41a9316597172aa04fd32dfb7228e000ae686459

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10b924aabbd90968f0c2b31b8e9bd72320cd5f33c8b13fa3305037075f2f7e28
MD5 da16b0e381794f379b7a88e8d1b65121
BLAKE2b-256 221ffbb5ba0eca6b45bac8721243e648f7ad502113e402ceff78d6df3f057ec6

See more details on using hashes here.

File details

Details for the file phylo2vec-1.8.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for phylo2vec-1.8.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b84e7e30c4b916d2d6b684f8a2ecd1345e20c6b9b29c8b3fffaab6b07ec3514a
MD5 aca4ee076bfba2af33efd7a7bac4e4c4
BLAKE2b-256 85c3d0bfdccf5619ed2d03bb7b00b783adf7d51198422ac7f1d929866fc08176

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