Skip to content
/ piqtree Public

a python library that exposes features from iqtree2 - efficient software for phylogenomic inference

License

Notifications You must be signed in to change notification settings

iqtree/piqtree

Repository files navigation

piqtree

PyPI Version Python Version License

CI Coverage Status Documentation Status

piqtree is a library which allows you use IQ-TREE directly from Python! The interface with python is through cogent3 objects. For usage, please refer to the documentation or the examples below.

If you encounter any problems or have any feature requests feel free to raise an issue!

Examples

Phylogenetic Reconstruction

from piqtree import build_tree
from piqtree.model import Model
from cogent3 import load_aligned_seqs # Included with piqtree!

# 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, Model("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 piqtree import fit_tree
from piqtree.model import Model
from cogent3 import load_aligned_seqs, make_tree # Included with piqtree!

# 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, Model("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 piqtree import TreeGenMode, random_trees

num_trees = 3 
num_taxa = 5

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

# Randomly generate trees
trees = random_trees(num_trees, num_taxa, tree_gen_mode, 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 piqtree import robinson_foulds
from cogent3 import make_tree # Included with piqtree!

# 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

About

a python library that exposes features from iqtree2 - efficient software for phylogenomic inference

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages