A Python Environment for (phylogenetic) Tree Exploration
npx @tessl/cli install tessl/pypi-ete3@3.1.00
# ETE3 - Environment for Tree Exploration
1
2
ETE3 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.
3
4
## Package Information
5
6
- **Package Name**: ete3
7
- **Language**: Python
8
- **Installation**: `pip install ete3`
9
10
## Core Imports
11
12
```python
13
import ete3
14
```
15
16
Most common imports for core functionality:
17
18
```python
19
from ete3 import Tree, PhyloTree, SeqGroup, NCBITaxa
20
```
21
22
For visualization:
23
24
```python
25
from ete3 import TreeStyle, NodeStyle, faces
26
```
27
28
## Basic Usage
29
30
```python
31
from ete3 import Tree, PhyloTree, NCBITaxa
32
33
# Create a tree from Newick format
34
tree = Tree("(A:1,(B:1,(E:1,D:1):0.5):0.5);")
35
36
# Basic tree operations
37
print(f"Tree has {len(tree)} nodes")
38
print(f"Leaves: {tree.get_leaf_names()}")
39
40
# Tree traversal
41
for node in tree.traverse():
42
print(f"Node: {node.name}, Distance: {node.dist}")
43
44
# Phylogenetic tree with species information
45
phylo_tree = PhyloTree("(human:1,(chimp:1,bonobo:1):0.5);")
46
phylo_tree.set_species_naming_function(lambda name: name)
47
48
# NCBI taxonomy integration
49
ncbi = NCBITaxa()
50
tree_with_taxonomy = ncbi.get_topology([9606, 9598, 9597]) # Human, chimp, bonobo
51
print(tree_with_taxonomy.get_ascii())
52
```
53
54
## Architecture
55
56
ETE3 follows a hierarchical design centered around tree nodes:
57
58
- **TreeNode/Tree**: Base classes providing core tree structure and manipulation
59
- **PhyloNode/PhyloTree**: Extended classes with phylogenetic-specific features
60
- **EvolNode/EvolTree**: Specialized classes for evolutionary analysis
61
- **SeqGroup**: Sequence alignment and multiple sequence file handling
62
- **NCBITaxa**: Integration with NCBI Taxonomy database
63
- **Visualization System**: Modular rendering with styles, faces, and layouts
64
- **External Parsers**: Support for multiple tree and sequence formats
65
66
This modular design allows users to work at different levels of complexity, from basic tree manipulation to advanced phylogenomic analysis.
67
68
## Capabilities
69
70
### Core Tree Operations
71
72
Fundamental tree structure manipulation including node creation, traversal, modification, and basic analysis. These operations form the foundation for all other ETE3 functionality.
73
74
```python { .api }
75
class Tree:
76
def __init__(self, newick=None, format=0, dist=None, support=None, name=None, quoted_node_names=False): ...
77
def add_child(self, child=None, name=None, dist=None, support=None): ...
78
def traverse(self, strategy="levelorder", is_leaf_fn=None): ...
79
def get_leaves(self, is_leaf_fn=None): ...
80
def get_common_ancestor(self, *target_nodes): ...
81
def prune(self, nodes, preserve_branch_length=False): ...
82
def write(self, features=None, outdir=None, format=0, is_leaf_fn=None): ...
83
```
84
85
[Core Tree Operations](./core-tree.md)
86
87
### Phylogenetic Analysis
88
89
Advanced phylogenetic tree analysis including species handling, evolutionary event detection, tree reconciliation, and NCBI taxonomy integration.
90
91
```python { .api }
92
class PhyloTree(Tree):
93
def set_species_naming_function(self, fn): ...
94
def reconcile(self, species_tree): ...
95
def get_my_evol_events(self, sos_thr=0.0): ...
96
def get_speciation_trees(self, map_features=None, autodetect_duplications=True): ...
97
def annotate_ncbi_taxa(self, taxid_attr='species', tax2name=None, tax2track=None): ...
98
```
99
100
[Phylogenetic Analysis](./phylogenetic.md)
101
102
### Sequence Handling
103
104
Multiple sequence alignment and sequence group operations for linking phylogenetic trees with molecular data.
105
106
```python { .api }
107
class SeqGroup:
108
def __init__(self, sequences=None, format="fasta", fix_duplicates=True): ...
109
def get_seq(self, name): ...
110
def iter_entries(self): ...
111
def write(self, format="fasta", outfile=None): ...
112
```
113
114
[Sequence Handling](./sequences.md)
115
116
### NCBI Taxonomy Integration
117
118
Complete integration with NCBI Taxonomy database for taxonomic annotation, lineage retrieval, and species tree construction.
119
120
```python { .api }
121
class NCBITaxa:
122
def __init__(self, dbfile=None, taxdump_file=None, update=True): ...
123
def get_topology(self, taxids, intermediate_nodes=False, rank_limit=None): ...
124
def get_lineage(self, taxid): ...
125
def annotate_tree(self, tree, taxid_attr="name", tax2name=None, tax2track=None, tax2rank=None): ...
126
```
127
128
[NCBI Taxonomy](./ncbi-taxonomy.md)
129
130
### Tree Visualization
131
132
Comprehensive tree visualization system with customizable styles, faces, and layouts for creating publication-quality tree figures.
133
134
```python { .api }
135
class TreeStyle:
136
def __init__(self): ...
137
138
class NodeStyle:
139
def __init__(self): ...
140
141
def show(tree_style=None): ...
142
```
143
144
[Visualization](./visualization.md)
145
146
### Data Tables and Arrays
147
148
Efficient handling of numerical data associated with trees and sequences, supporting matrix operations and statistical analysis.
149
150
```python { .api }
151
class ArrayTable:
152
def __init__(self, matrix_file=None, mtype="float"): ...
153
def get_column_array(self, colname): ...
154
def transpose(self): ...
155
```
156
157
[Data Tables](./data-tables.md)
158
159
### Clustering Analysis
160
161
Specialized clustering tree operations for hierarchical clustering analysis and cluster validation.
162
163
```python { .api }
164
class ClusterTree(Tree):
165
def get_cluster_profile(self): ...
166
def get_silhouette(self): ...
167
```
168
169
[Clustering](./clustering.md)
170
171
### External Format Support
172
173
Support for reading and writing multiple phylogenetic data formats including PhyloXML, NeXML, and various sequence formats.
174
175
```python { .api }
176
class Phyloxml:
177
def build_from_file(self, fname): ...
178
def export(self): ...
179
180
class Nexml:
181
def build_from_file(self, fname): ...
182
def export(self): ...
183
```
184
185
[External Formats](./external-formats.md)