ETE 3 (Environment for Tree Exploration)

3.1.3 · maintenance · verified Thu Apr 16

ETE (Environment for Tree Exploration) 3 is a Python toolkit for the manipulation, analysis, and visualization of phylogenetic and other hierarchical trees. While version 4 is the actively developed major release, ETE 3.1.3 is the last stable version of the 3.x series, primarily receiving maintenance updates. It offers a comprehensive API for tree handling, node annotation, and customizable tree drawing into various image formats.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple phylogenetic tree from a Newick string, access and annotate its nodes, and prepare a custom visualization style. For graphical output (rendering to file or interactive display), `PyQt5` is required.

from ete3 import Tree, TreeStyle, NodeStyle, TextFace

# Create a tree from a Newick string
t = Tree("((A:1.0,B:1.0):0.5,C:1.5);")

# Print the tree topology to console
print("Tree topology:")
print(t.get_ascii(show_length=True))

# Access nodes and add features
for node in t.traverse():
    node.add_features(my_feature="value")
    if node.is_leaf():
        print(f"Leaf name: {node.name}, feature: {node.my_feature}")
    else:
        print(f"Internal node: {node.name if node.name else 'Unnamed'}, feature: {node.my_feature}")

# Create a custom tree style
ts = TreeStyle()
ts.show_branch_length = True
ts.show_branch_support = True
ts.show_leaf_name = True
ts.title.add_face(TextFace("My Phylogenetic Tree"), column=0)

# Render the tree to a file (requires PyQt5)
# t.render("my_tree.png", w=600, h=600, tree_style=ts)

# For interactive visualization (requires PyQt5 and an X server/display)
# t.show(tree_style=ts)

print("Quickstart complete. For visualization, uncomment t.render() or t.show() and ensure PyQt5 is installed.")

view raw JSON →