Skip to main content

Python bindings for IQTree

Project description

piqtree2

PyPI Version Python Version License CI

piqtree2 is a library which allows you use IQ-TREE directly from Python! The interface with python is through cogent3 objects, as shown below.

Note

This project is still in early development, if you encounter any problems or have any feature requests feel free to raise an issue!

Examples

Phylogenetic Reconstruction

from piqtree2 import build_tree
from piqtree2.model import DnaModel
from cogent3 import load_aligned_seqs # Included with piqtree2!

# Load Sequences
aln = load_aligned_seqs("tests/data/example.fasta", moltype="dna")
aln = aln.take_seqs(["Human", "Chimpanzee", "Rhesus", "Mouse"])

# Reconstruct a phylogenetic tree with IQ-TREE!
tree = build_tree(aln, DnaModel.JC, rand_seed=1) # Optionally specify a random seed.

print("Tree topology:", tree) # A cogent3 tree object
print("Log-likelihood:", tree.params["lnL"])
# In a Jupyter notebook, try tree.get_figure() to see a dendrogram

Note See the cogent3 docs for examples on what you can do with cogent3 trees.

Fit Branch Lengths to Tree Topology

from piqtree2 import fit_tree
from piqtree2.model import DnaModel
from cogent3 import load_aligned_seqs, make_tree # Included with piqtree2!

# Load Sequences
aln = load_aligned_seqs("tests/data/example.fasta", moltype="dna")
aln = aln.take_seqs(["Human", "Chimpanzee", "Rhesus", "Mouse"])

# Construct tree topology
tree = make_tree("(Human, Chimpanzee, (Rhesus, Mouse));")

# Fit branch lengths with IQ-TREE!
tree = fit_tree(aln, tree, DnaModel.JC, rand_seed=1) # Optionally specify a random seed.

print("Tree with branch lengths:", tree) # A cogent3 tree object
print("Log-likelihood:", tree.params["lnL"])

Create a Collection of Random Trees

from piqtree2 import TreeGenMode, random_trees

num_taxa = 5
num_trees = 3 

# Also supports YULE_HARDING, CATERPILLAR, BALANCED, BIRTH_DEATH and STAR_TREE
tree_gen_mode = TreeGenMode.UNIFORM 

# Randomly generate trees
trees = random_trees(num_taxa, tree_gen_mode, num_trees, rand_seed=1) # Optionally specify a random seed.

print(trees) # A tuple of 3 trees with 5 taxa each.

Pairwise Robinson-Foulds Distance between Trees

from piqtree2 import robinson_foulds
from cogent3 import make_tree # Included with piqtree2!

# Construct trees
tree1 = make_tree("(a,b,(c,(d,e)));")
tree2 = make_tree("(e,b,(c,(d,a)));")
tree3 = make_tree("(a,b,(d,(c,e)));")

# Calculate pairwise distances
pairwise_distances = robinson_foulds(tree1, tree2, tree3) # Supports any number of trees (for a sequence of trees use *seq_of_trees)

print(pairwise_distances) # A numpy array containing pairwaise Robinson-Foulds distances between trees

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

piqtree2-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.5 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

piqtree2-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (3.6 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

piqtree2-0.2.0-cp312-cp312-macosx_10_9_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

piqtree2-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.5 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

piqtree2-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (3.6 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

piqtree2-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

piqtree2-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

piqtree2-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (3.6 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

piqtree2-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

piqtree2-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

piqtree2-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (3.6 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

piqtree2-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page