A Python Environment for (phylogenetic) Tree Exploration
npx @tessl/cli install tessl/pypi-ete3@3.1.0ETE3 is a comprehensive Python toolkit for phylogenetic tree manipulation, analysis, and visualization. It provides advanced capabilities for evolutionary analysis, tree reconstruction, comparison, and sophisticated visualization with customizable rendering options, serving researchers in phylogenetics, genomics, and bioinformatics.
pip install ete3import ete3Most common imports for core functionality:
from ete3 import Tree, PhyloTree, SeqGroup, NCBITaxaFor visualization:
from ete3 import TreeStyle, NodeStyle, facesfrom ete3 import Tree, PhyloTree, NCBITaxa
# Create a tree from Newick format
tree = Tree("(A:1,(B:1,(E:1,D:1):0.5):0.5);")
# Basic tree operations
print(f"Tree has {len(tree)} nodes")
print(f"Leaves: {tree.get_leaf_names()}")
# Tree traversal
for node in tree.traverse():
print(f"Node: {node.name}, Distance: {node.dist}")
# Phylogenetic tree with species information
phylo_tree = PhyloTree("(human:1,(chimp:1,bonobo:1):0.5);")
phylo_tree.set_species_naming_function(lambda name: name)
# NCBI taxonomy integration
ncbi = NCBITaxa()
tree_with_taxonomy = ncbi.get_topology([9606, 9598, 9597]) # Human, chimp, bonobo
print(tree_with_taxonomy.get_ascii())ETE3 follows a hierarchical design centered around tree nodes:
This modular design allows users to work at different levels of complexity, from basic tree manipulation to advanced phylogenomic analysis.
Fundamental tree structure manipulation including node creation, traversal, modification, and basic analysis. These operations form the foundation for all other ETE3 functionality.
class Tree:
def __init__(self, newick=None, format=0, dist=None, support=None, name=None, quoted_node_names=False): ...
def add_child(self, child=None, name=None, dist=None, support=None): ...
def traverse(self, strategy="levelorder", is_leaf_fn=None): ...
def get_leaves(self, is_leaf_fn=None): ...
def get_common_ancestor(self, *target_nodes): ...
def prune(self, nodes, preserve_branch_length=False): ...
def write(self, features=None, outdir=None, format=0, is_leaf_fn=None): ...Advanced phylogenetic tree analysis including species handling, evolutionary event detection, tree reconciliation, and NCBI taxonomy integration.
class PhyloTree(Tree):
def set_species_naming_function(self, fn): ...
def reconcile(self, species_tree): ...
def get_my_evol_events(self, sos_thr=0.0): ...
def get_speciation_trees(self, map_features=None, autodetect_duplications=True): ...
def annotate_ncbi_taxa(self, taxid_attr='species', tax2name=None, tax2track=None): ...Multiple sequence alignment and sequence group operations for linking phylogenetic trees with molecular data.
class SeqGroup:
def __init__(self, sequences=None, format="fasta", fix_duplicates=True): ...
def get_seq(self, name): ...
def iter_entries(self): ...
def write(self, format="fasta", outfile=None): ...Complete integration with NCBI Taxonomy database for taxonomic annotation, lineage retrieval, and species tree construction.
class NCBITaxa:
def __init__(self, dbfile=None, taxdump_file=None, update=True): ...
def get_topology(self, taxids, intermediate_nodes=False, rank_limit=None): ...
def get_lineage(self, taxid): ...
def annotate_tree(self, tree, taxid_attr="name", tax2name=None, tax2track=None, tax2rank=None): ...Comprehensive tree visualization system with customizable styles, faces, and layouts for creating publication-quality tree figures.
class TreeStyle:
def __init__(self): ...
class NodeStyle:
def __init__(self): ...
def show(tree_style=None): ...Efficient handling of numerical data associated with trees and sequences, supporting matrix operations and statistical analysis.
class ArrayTable:
def __init__(self, matrix_file=None, mtype="float"): ...
def get_column_array(self, colname): ...
def transpose(self): ...Specialized clustering tree operations for hierarchical clustering analysis and cluster validation.
class ClusterTree(Tree):
def get_cluster_profile(self): ...
def get_silhouette(self): ...Support for reading and writing multiple phylogenetic data formats including PhyloXML, NeXML, and various sequence formats.
class Phyloxml:
def build_from_file(self, fname): ...
def export(self): ...
class Nexml:
def build_from_file(self, fname): ...
def export(self): ...