or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

character-data.mdcore-data-models.mddata-io.mdindex.mdsimulation.mdtree-analysis.mdvisualization-interop.md
tile.json

tessl/pypi-dendropy

A Python library for phylogenetics and phylogenetic computing: reading, writing, simulation, processing and manipulation of phylogenetic trees and characters.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/dendropy@5.0.x

To install, run

npx @tessl/cli install tessl/pypi-dendropy@5.0.0

index.mddocs/

DendroPy

DendroPy is a comprehensive Python library for phylogenetic computing, providing extensive functionality for reading, writing, simulation, processing, and manipulation of phylogenetic trees and character matrices. It supports the reading and writing of phylogenetic data in multiple formats (NEXUS, NEWICK, NeXML, Phylip, FASTA), and can function as a stand-alone library for phylogenetics, a component of complex multi-library phyloinformatic pipelines, or as scripting "glue" that assembles and drives such pipelines.

Package Information

  • Package Name: DendroPy
  • Language: Python
  • Installation: pip install dendropy or conda install -c conda-forge dendropy
  • Documentation: https://jeetsukumaran.github.io/DendroPy/

Core Imports

import dendropy

Most common usage patterns:

# Core data model classes
from dendropy import Tree, Node, Taxon, TaxonNamespace
from dendropy import DataSet, TreeList

# Character matrices
from dendropy import DnaCharacterMatrix, ProteinCharacterMatrix
from dendropy import StandardCharacterMatrix, ContinuousCharacterMatrix

# Predefined alphabets
from dendropy import DNA_STATE_ALPHABET, PROTEIN_STATE_ALPHABET

# Tree analysis and comparison (from submodules)
from dendropy.calculate.treecompare import unweighted_robinson_foulds_distance
from dendropy.calculate.phylogeneticdistance import PhylogeneticDistanceMatrix

Basic Usage

import dendropy

# Read a tree from a file
tree = dendropy.Tree.get(path="example.nwk", schema="newick")
print(f"Tree has {len(tree.leaf_nodes())} taxa")

# Read multiple trees
trees = dendropy.TreeList.get(path="trees.nex", schema="nexus")
print(f"Read {len(trees)} trees")

# Create a simple tree manually
tns = dendropy.TaxonNamespace(["A", "B", "C", "D"])
tree = dendropy.Tree(taxon_namespace=tns)
root = tree.seed_node
n1 = root.new_child(taxon=tns[0])  # Leaf A
n2 = root.new_child()
n2.new_child(taxon=tns[1])  # Leaf B
n3 = n2.new_child()
n3.new_child(taxon=tns[2])  # Leaf C
n3.new_child(taxon=tns[3])  # Leaf D

# Work with character data
dna = dendropy.DnaCharacterMatrix.get(path="sequences.fasta", schema="fasta")
print(f"Matrix has {len(dna)} sequences of length {dna.max_sequence_size}")

# Basic tree analysis
from dendropy.calculate import treecompare
rf_distance = treecompare.unweighted_robinson_foulds_distance(tree1, tree2)

Architecture

DendroPy is built around a hierarchical object model that mirrors phylogenetic data structures:

  • TaxonNamespace: Central registry of operational taxonomic units
  • Tree: Phylogenetic tree with nodes and edges, supporting rich metadata
  • Node: Tree vertices with parent-child relationships and optional taxon associations
  • DataSet: Container that can hold multiple trees and character matrices with shared taxon namespaces
  • CharacterMatrix: Alignment data for various sequence types (DNA, protein, morphological)
  • I/O Framework: Pluggable readers and writers for all major phylogenetic file formats

This design enables seamless integration between tree and character data, automatic taxon namespace management, and flexible data interchange between different phylogenetic file formats.

Capabilities

Core Data Models

Fundamental phylogenetic data structures including trees, nodes, taxa, character matrices, and datasets. These classes form the foundation of DendroPy's phylogenetic computing capabilities.

class Tree:
    def __init__(self, taxon_namespace=None): ...
    def get(cls, **kwargs): ...
    def read(self, **kwargs): ...
    def write(self, **kwargs): ...
    def nodes(self): ...
    def leaf_nodes(self): ...
    def internal_nodes(self): ...
    def find_node(self, filter_fn): ...
    def mrca(self, **kwargs): ...

class Node:
    def __init__(self, **kwargs): ...
    def add_child(self, node): ...
    def new_child(self, **kwargs): ...
    def remove_child(self, node): ...
    def leaf_nodes(self): ...
    def preorder_iter(self): ...

class Taxon:
    def __init__(self, label=None): ...

class TaxonNamespace:
    def __init__(self, taxa=None): ...
    def new_taxon(self, label): ...
    def get_taxon(self, label): ...

Core Data Models

Data Input/Output

Comprehensive I/O framework supporting all major phylogenetic file formats with configurable reading and writing options. Handles NEXUS, Newick, NeXML, FASTA, PHYLIP, and more.

# Tree I/O
@classmethod
def get(cls, **kwargs): ...
def read(self, **kwargs): ...
def write(self, **kwargs): ...
def write_to_stream(self, dest, schema, **kwargs): ...

# Factory functions for readers/writers
def get_reader(schema, **kwargs): ...
def get_writer(schema, **kwargs): ...
def get_tree_yielder(files, schema, **kwargs): ...

Data I/O

Tree Analysis & Comparison

Phylogenetic tree analysis including distance calculations, tree comparison metrics, summarization algorithms, and topological analysis. Supports Robinson-Foulds distances, consensus trees, and statistical comparisons.

def symmetric_difference(tree1, tree2): ...
def unweighted_robinson_foulds_distance(tree1, tree2): ...
def weighted_robinson_foulds_distance(tree1, tree2): ...
def euclidean_distance(tree1, tree2): ...

class PhylogeneticDistanceMatrix:
    def __init__(self, tree): ...
    def patristic_distances(self): ...

class TreeSummarizer:
    def __init__(self): ...
    def summarize(self, trees): ...

Tree Analysis

Character Data & Evolution

Character matrices for molecular and morphological data, state alphabets, and evolutionary models. Supports DNA, RNA, protein, restriction sites, standard morphological, and continuous character data.

class DnaCharacterMatrix:
    def __init__(self, **kwargs): ...
    def get(cls, **kwargs): ...
    def read(self, **kwargs): ...
    def concatenate(self, other_matrices): ...

class ProteinCharacterMatrix:
    def __init__(self, **kwargs): ...

# Predefined alphabets
DNA_STATE_ALPHABET: StateAlphabet
PROTEIN_STATE_ALPHABET: StateAlphabet
BINARY_STATE_ALPHABET: StateAlphabet

def new_standard_state_alphabet(symbols): ...

Character Data

Simulation & Modeling

Tree simulation using birth-death and coalescent processes, character evolution simulation, and phylogenetic modeling. Includes population genetics simulation and parametric evolutionary models.

def birth_death_tree(birth_rate, death_rate, **kwargs): ...
def pure_kingman_tree(taxon_namespace, pop_size): ...
def uniform_pure_birth_tree(taxon_namespace, birth_rate): ...

def simulate_discrete_char_dataset(tree, seq_len, **kwargs): ...
def hky85_chars(tree, seq_len, **kwargs): ...

class DiscreteCharacterEvolver:
    def __init__(self, **kwargs): ...
    def evolve_states(self, tree): ...

Simulation

Visualization & Interoperability

Tree visualization, plotting, and integration with external phylogenetic software and databases. Supports ASCII tree plots, LaTeX TikZ output, and interfaces to PAUP*, RAxML, R, and other tools.

class AsciiTreePlot:
    def __init__(self, **kwargs): ...
    def compose(self, tree): ...

class TikzTreePlot:
    def __init__(self, **kwargs): ...
    def compose(self, tree): ...

# External software interfaces
class PaupRunner:
    def __init__(self): ...
    def run(self, commands): ...

class RaxmlRunner:
    def __init__(self): ...
    def estimate_tree(self, char_matrix): ...

Visualization & Interoperability

Types

# Core type aliases and constants
from typing import List, Dict, Optional, Union, Callable, Iterator

TreeList = List[Tree]
NodeList = List[Node]
TaxonList = List[Taxon]

# State alphabet constants
DNA_STATE_ALPHABET: StateAlphabet
RNA_STATE_ALPHABET: StateAlphabet
NUCLEOTIDE_STATE_ALPHABET: StateAlphabet
PROTEIN_STATE_ALPHABET: StateAlphabet
BINARY_STATE_ALPHABET: StateAlphabet
RESTRICTION_SITES_STATE_ALPHABET: StateAlphabet
INFINITE_SITES_STATE_ALPHABET: StateAlphabet