Skip to main content

Phylo2Vec: integer vector representation of binary (phylogenetic) trees

Project description

Phylo2Vec

PyPI version Documentation DOI

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

Pip

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

pip install phylo2vec

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)

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

from phylo2vec.opt import HillClimbingOptimizer

# Perform phylogenetic inference
hc = HillClimbingOptimizer(raxml_cmd="/path/to/raxml-ng", verbose=True)
v_opt, taxa_dict, losses = hc.fit("/path/to/your_fasta_file.fa")

Documentation

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

How to Contribute

We welcome contributions to Phylo2Vec! Here's how you can help:

  1. Fork the repository and create your branch from main
  2. Make your changes and add tests if applicable
  3. Run the tests to ensure they pass
  4. Submit a pull request with a detailed description of your changes

Please make sure to follow our coding standards and write appropriate tests for new features.

Thanks to 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},
}

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.3.1.tar.gz (93.4 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.3.1-cp310-abi3-win_amd64.whl (819.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

phylo2vec-1.3.1-cp310-abi3-win32.whl (750.7 kB view details)

Uploaded CPython 3.10+Windows x86

phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_x86_64.whl (1.3 MB view details)

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

phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_i686.whl (1.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_armv7l.whl (1.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

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

phylo2vec-1.3.1-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.3.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

phylo2vec-1.3.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.5+ i686

phylo2vec-1.3.1-cp310-abi3-macosx_11_0_arm64.whl (940.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

phylo2vec-1.3.1-cp310-abi3-macosx_10_12_x86_64.whl (992.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for phylo2vec-1.3.1.tar.gz
Algorithm Hash digest
SHA256 f3e488338357055199475c992cb81e69ad4da2bbcbc45623aa8ccaf615896bec
MD5 a2e7fb94adf676c7cb014414810409f7
BLAKE2b-256 e2869510db81723223b80557f92eb8f3aa4c7b56abc3cd57be46a1f94bc34cbd

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a960e491d7c54eafa9c8cfce3993447ab672b67fa23a244357beabfdb8a53257
MD5 ad178e85dd02ff581eaee537a6a12660
BLAKE2b-256 d32a8dab1a5ea9fe547dfcbbeeef5e82dce46843968e031912b07822daa53294

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 462e0e0a001615ea0619e5a256722b3600cdc2e749dd3c52cebaf64848a3e679
MD5 afcace0b8f5b3dee1f9b0d96f5cae889
BLAKE2b-256 02d2038d9699c07df31029b6c74e25ca57fb3f4bc8ac0decc65382c208fe808b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cb33379ed68293a04da9edc6b7e299810d921ed4a9b605f00466e0a3731d546c
MD5 a1ac8eae8701667df8668fcd355d8fdb
BLAKE2b-256 16b529a34dbde4435e2a9818dc1067149a391a10163557b0e656bf2af24d8aeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 47f3077d18fc2d9f138966ed49417c7f6cae22b8ffd46106d11b2eb8c7f3a40d
MD5 d2b9e66cf082f2840f89a177cff94fef
BLAKE2b-256 e82f481deeffc13ff3792d2a5e5f251fb2f76f3826e9379e4c5b31f6a7eacff6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 ffa8e616b130efe6eb90c98cc4639b56fb2c552c374e4f83003f8c0bb60991af
MD5 7a9336e976a4773eeb974f9fe90999b5
BLAKE2b-256 55243f4f5f83c9d8803c05bf697a9bc67e157c00ef9d3e45b1a1b30305d7ee47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9e3262621b8ecd62566b7e64b9c6bab2d8b068390ea3a1b0bf472d5d0f43b380
MD5 09d5cf774f66c36dab2aa5d444b97600
BLAKE2b-256 fb47f9097728a9d88a956c05820b2c6d8a568dcbdc616c8fc9aed8d19dbff4c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9768cf6ae365383f93d2b27d6118dad247b2814c3fffa33395df908d064660a
MD5 0e9c59364d726beb5ced97d421eacfa1
BLAKE2b-256 b3b99a72030dcdff8f3d99d4270c49923764f8419c9ec6c5e55121d4f7c9542c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 95e7f91beef5737c5f6ffa14616c711c07396f99acf1cf5cf43d75cb80b4e895
MD5 0fb36117042d752f47631ed3afe050cb
BLAKE2b-256 71909f0e5e5d4e0eeaa1d11d23f07cb8fae61b5f2e6d72751e0be4940c63b4df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 59319eb06ed688492ac4b958a7e046d81680c2592811c309ef6a0c7b54f44b0e
MD5 f245400dd78840cadaea018a076ba633
BLAKE2b-256 1a71a7773d6d6e5da6c78cd8a98456e988de14958cafbbf882d41340928b4dd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 edbf9a6a244842378c3950d3f656cd2032068e2d3ec42838d8b4cf12c145beb7
MD5 3b5c42f9f91ffd6d1353b90991988531
BLAKE2b-256 2a88f0bdb166dcc61bc457548db8c2f4a7d2b9c5532adb5a829f708170447bce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6383c60067f2e24ef8c82fbba5e961ad26e7fc9b3be9500a96544697fced47f9
MD5 952561f3e43804b8d1c0c2c55eedf520
BLAKE2b-256 e704fee9d54786789f5c1223ffc68fb1a633ed0333cd422c87af6abaf4dd4d0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 740fc74dff5bc1e9aa4adc70c566afea0cad7be9771fe3194a5a6d27dffdd2ad
MD5 3f15b767dea27b30c88147edcb3b5635
BLAKE2b-256 e5db1af311e2b4e240b4219ec21ea061cf8b36faec03cd2e53d6a453f8efd285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60bbaa3506d29887b892aa3619f9f7cb9bde2f8d66c844bf436a2f554b4c2d62
MD5 847399da0bad370e36e063284a702756
BLAKE2b-256 f9fa4eb6ce3a6db45e86d7d7e38c45f28d736c8a17510f1aeeaa6165edd86fb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phylo2vec-1.3.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e9c37cfa3de8c8e7b3c0c301f635772fb3bb89e5c886cb3dc29acc3574000a1d
MD5 879cef8a6f680433e414d03893728a61
BLAKE2b-256 9806b79509d6315bb020b69c9dd404efcca54b5292a8c38513ca47d4b6641f5d

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