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!
If you would like to help out by contributing to the piqtree project, please check out our contributor guide!
from piqtree import build_tree
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, "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.
from piqtree import fit_tree
from cogent3 import load_aligned_seqs, make_tree
# 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, "JC")
print("Tree with branch lengths:", tree)
print("Log-likelihood:", tree.params["lnL"])
For more examples ranging from using ModelFinder, to making rapid neighbour-joining trees, or randomly generated trees be sure to check out the documentation!