CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dendropy

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

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

visualization-interop.mddocs/

Visualization & Interoperability

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

Capabilities

Tree Visualization

Classes for generating visual representations of phylogenetic trees in various formats.

class AsciiTreePlot:
    """
    ASCII-based tree visualization for console output.
    
    Parameters:
    - tree: Tree object to visualize
    - display_width: Maximum width for tree display
    - show_internal_node_labels: Display internal node labels
    - leaf_spacing_factor: Spacing between leaf nodes
    """
    
    def __init__(self, **kwargs): ...
    
    def compose(self, tree, **kwargs):
        """
        Generate ASCII representation of tree.
        
        Parameters:
        - tree: Tree to visualize
        - width: Display width in characters
        - margin: Left margin for tree display
        - show_edge_lengths: Include branch lengths in display
        - edge_length_format: Format string for branch lengths
        - node_label_compose_fn: Function for composing node labels
        
        Returns:
        str: ASCII art representation of tree
        """
    
    def write(self, tree, dest, **kwargs):
        """Write ASCII tree to file or stream."""

class TikzTreePlot:
    """
    LaTeX TikZ tree visualization for publication-quality figures.
    
    Parameters:
    - tree: Tree object to plot
    - tikz_options: TikZ-specific formatting options
    """
    
    def __init__(self, **kwargs): ...
    
    def compose(self, tree, **kwargs):
        """
        Generate TikZ code for tree visualization.
        
        Parameters:
        - tree: Tree to plot
        - tree_layout: Layout algorithm ('rectangular', 'slanted', 'radial')
        - scale_factor: Scaling factor for branch lengths
        - node_label_compose_fn: Function for node label formatting
        - edge_style_compose_fn: Function for edge styling
        - node_style_compose_fn: Function for node styling
        
        Returns:
        str: TikZ LaTeX code for tree
        """
    
    def write(self, tree, dest, **kwargs):
        """Write TikZ code to file or stream."""

External Software Integration

Classes for interfacing with popular phylogenetic analysis software.

class PaupService:
    """
    Interface to PAUP* phylogenetic analysis software.
    
    Parameters:
    - paup_path: Path to PAUP* executable
    - suppress_input_file_cleanup: Keep temporary input files
    - suppress_output_file_cleanup: Keep temporary output files
    """
    
    def __init__(self, **kwargs): ...
    
    def run(self, commands, **kwargs):
        """
        Execute PAUP* commands.
        
        Parameters:
        - commands: List of PAUP* command strings
        - input_data: Character matrix or tree data for analysis
        - timeout: Maximum execution time in seconds
        
        Returns:
        str: PAUP* output text
        """
    
    def estimate_tree(self, char_matrix, **kwargs):
        """
        Estimate phylogenetic tree from character data.
        
        Parameters:
        - char_matrix: CharacterMatrix for tree estimation
        - search_method: Tree search algorithm ('nj', 'mp', 'ml')
        - search_options: Additional search parameters
        
        Returns:
        Tree: Estimated phylogenetic tree
        """
    
    def bootstrap_trees(self, char_matrix, num_replicates=100, **kwargs):
        """
        Generate bootstrap trees.
        
        Parameters:
        - char_matrix: Character data for bootstrap analysis
        - num_replicates: Number of bootstrap replicates
        - search_method: Tree search method for each replicate
        
        Returns:
        TreeList: Collection of bootstrap trees
        """

class RaxmlRunner:
    """
    Interface to RAxML maximum likelihood phylogenetic software.
    
    Parameters:
    - raxml_path: Path to RAxML executable
    - temp_dir: Directory for temporary files
    """
    
    def __init__(self, **kwargs): ...
    
    def estimate_tree(self, char_matrix, **kwargs):
        """
        Estimate maximum likelihood tree using RAxML.
        
        Parameters:
        - char_matrix: Character data for tree estimation
        - substitution_model: Evolutionary model ('GTRGAMMA', etc.)
        - num_runs: Number of independent ML searches
        - bootstrap_replicates: Number of bootstrap replicates
        - random_seed: Random seed for reproducibility
        
        Returns:
        Tree: Best ML tree from RAxML analysis
        """
    
    def bootstrap_analysis(self, char_matrix, **kwargs):
        """
        Perform bootstrap analysis with RAxML.
        
        Parameters:
        - char_matrix: Character data
        - num_replicates: Number of bootstrap replicates
        - substitution_model: Evolutionary model
        
        Returns:
        TreeList: Bootstrap trees with support values
        """

class RService:
    """
    Interface to R statistical computing environment.
    
    Parameters:
    - r_path: Path to R executable
    - r_libs: Additional R library paths
    """
    
    def __init__(self, **kwargs): ...
    
    def run(self, r_script, **kwargs):
        """
        Execute R script and return results.
        
        Parameters:
        - r_script: R code to execute
        - data_objects: Python objects to pass to R
        - return_objects: R objects to return to Python
        
        Returns:
        dict: Results from R execution
        """
    
    def tree_to_ape(self, tree):
        """Convert DendroPy tree to R APE phylo object."""
    
    def tree_from_ape(self, ape_tree):
        """Convert R APE phylo object to DendroPy tree."""

class Rspr:
    """
    Interface to RSPR (Rooted Subtree Prune and Regraft) software.
    
    Parameters:
    - rspr_path: Path to RSPR executable
    """
    
    def __init__(self, **kwargs): ...
    
    def spr_distance(self, tree1, tree2, **kwargs):
        """
        Calculate SPR distance between trees.
        
        Parameters:
        - tree1, tree2: Trees for distance calculation
        - rooted: Whether trees should be treated as rooted
        
        Returns:
        int: SPR distance between trees
        """

class SeqGenRunner:
    """
    Interface to Seq-Gen sequence simulation software.
    
    Parameters:
    - seqgen_path: Path to Seq-Gen executable
    """
    
    def __init__(self, **kwargs): ...
    
    def generate_sequences(self, tree, **kwargs):
        """
        Generate sequences using Seq-Gen.
        
        Parameters:
        - tree: Tree for sequence simulation
        - seq_len: Length of sequences to generate
        - substitution_model: Evolution model ('HKY', 'GTR', etc.)
        - rate_params: Model-specific rate parameters
        
        Returns:
        CharacterMatrix: Simulated sequence alignment
        """

Database Integration

Classes for accessing phylogenetic and biological databases.

class GbifDb:
    """
    Interface to Global Biodiversity Information Facility (GBIF) database.
    
    Parameters:
    - api_key: GBIF API key for authenticated access
    - cache_dir: Directory for caching downloaded data
    """
    
    def __init__(self, **kwargs): ...
    
    def taxon_search(self, query, **kwargs):
        """
        Search for taxonomic information.
        
        Parameters:
        - query: Taxonomic search query
        - limit: Maximum number of results
        - rank: Taxonomic rank filter
        
        Returns:
        list: Taxonomic records matching query
        """
    
    def occurrence_search(self, taxon_key, **kwargs):
        """
        Search for species occurrence records.
        
        Parameters:
        - taxon_key: GBIF taxon identifier
        - geographic_bounds: Geographic bounding box
        - date_range: Date range for occurrences
        
        Returns:
        list: Occurrence records for taxon
        """

class GbifOccurrenceDb(GbifDb):
    """Specialized interface for GBIF occurrence data."""
    
    def download_occurrences(self, taxa, **kwargs):
        """Download occurrence data for multiple taxa."""

class GenBankResourceStore:
    """
    Interface to NCBI GenBank database.
    
    Parameters:
    - api_key: NCBI API key for enhanced access
    - email: Email address for NCBI Entrez access
    - cache_dir: Directory for caching sequence data
    """
    
    def __init__(self, **kwargs): ...
    
    def fetch_sequences(self, accession_ids, **kwargs):
        """
        Fetch sequences by GenBank accession numbers.
        
        Parameters:
        - accession_ids: List of GenBank accession numbers
        - sequence_type: Type of sequences ('nucleotide', 'protein')
        - format: Output format ('fasta', 'genbank')
        
        Returns:
        CharacterMatrix: Retrieved sequences
        """
    
    def search_sequences(self, query, **kwargs):
        """
        Search GenBank using query terms.
        
        Parameters:
        - query: Search query string
        - database: GenBank database ('nuccore', 'protein')
        - max_results: Maximum number of results
        
        Returns:
        list: Search results with accession numbers
        """

class GenBankNucleotide:
    """GenBank nucleotide sequence interface."""
    
    def __init__(self, accession, **kwargs): ...
    def fetch_sequence(self): ...

class GenBankDna(GenBankNucleotide):
    """GenBank DNA sequence interface."""

class GenBankRna(GenBankNucleotide):
    """GenBank RNA sequence interface."""

class GenBankProtein:
    """GenBank protein sequence interface."""
    
    def __init__(self, accession, **kwargs): ...
    def fetch_sequence(self): ...

Web Service Integration

Classes for integrating with phylogenetic web services and online tools.

class ItolService:
    """
    Interface to iTOL (Interactive Tree of Life) web service.
    
    Parameters:
    - api_key: iTOL API key for authenticated access
    - project_name: Name for iTOL project organization
    """
    
    def __init__(self, **kwargs): ...
    
    def upload_tree(self, tree, **kwargs):
        """
        Upload tree to iTOL for visualization.
        
        Parameters:
        - tree: Tree object to upload
        - tree_name: Display name for tree
        - public: Whether tree should be publicly accessible
        - annotations: Additional annotation data
        
        Returns:
        str: iTOL tree ID for accessing uploaded tree
        """
    
    def create_annotation_file(self, annotations, **kwargs):
        """
        Create iTOL annotation file for tree visualization.
        
        Parameters:
        - annotations: Annotation data for tree nodes/leaves
        - annotation_type: Type of annotation ('color', 'symbol', etc.)
        - output_format: iTOL annotation format
        
        Returns:
        str: Formatted annotation data for iTOL
        """
    
    def download_image(self, tree_id, **kwargs):
        """
        Download rendered tree image from iTOL.
        
        Parameters:
        - tree_id: iTOL tree identifier
        - image_format: Output format ('png', 'svg', 'pdf')
        - resolution: Image resolution for raster formats
        
        Returns:
        bytes: Image data
        """

Third-Party Library Integration

Integration with other Python scientific computing and phylogenetic libraries.

# BioPython integration
def tree_to_biopython(dendropy_tree):
    """
    Convert DendroPy tree to BioPython Phylo tree.
    
    Parameters:
    - dendropy_tree: DendroPy Tree object
    
    Returns:
    Bio.Phylo tree object
    """

def tree_from_biopython(biopython_tree, **kwargs):
    """
    Convert BioPython Phylo tree to DendroPy tree.
    
    Parameters:
    - biopython_tree: BioPython Phylo tree object
    - taxon_namespace: TaxonNamespace for converted tree
    
    Returns:
    dendropy.Tree: Converted tree object
    """

def char_matrix_to_biopython(dendropy_matrix):
    """Convert DendroPy character matrix to BioPython alignment."""

def char_matrix_from_biopython(biopython_alignment, **kwargs):
    """Convert BioPython alignment to DendroPy character matrix."""

# ETE integration  
def tree_to_ete(dendropy_tree):
    """Convert DendroPy tree to ETE tree."""

def tree_from_ete(ete_tree, **kwargs):
    """Convert ETE tree to DendroPy tree."""

# APE (R) integration via rpy2
def tree_to_ape_via_rpy2(dendropy_tree):
    """Convert DendroPy tree to R APE phylo object via rpy2."""

def tree_from_ape_via_rpy2(ape_tree, **kwargs):
    """Convert R APE phylo object to DendroPy tree via rpy2."""

Utility Functions for Interoperability

Utility functions that support integration with external tools and formats.

def write_mesquite_file(data_objects, dest, **kwargs):
    """
    Write data in Mesquite-compatible format.
    
    Parameters:
    - data_objects: Trees and/or character matrices
    - dest: Output file path or stream
    - include_trees: Whether to include tree data
    - include_characters: Whether to include character data
    """

def export_for_beast(trees, char_matrices, dest, **kwargs):
    """
    Export data in BEAST XML format.
    
    Parameters:
    - trees: Tree data for BEAST analysis
    - char_matrices: Character matrices for analysis
    - dest: Output XML file path
    - analysis_type: Type of BEAST analysis
    """

def export_for_mrbayes(char_matrix, dest, **kwargs):
    """
    Export character matrix in MrBayes NEXUS format.
    
    Parameters:
    - char_matrix: Character data for MrBayes
    - dest: Output NEXUS file path
    - include_mrbayes_block: Add MrBayes command block
    """

def validate_external_dependencies():
    """
    Check availability of external software dependencies.
    
    Returns:
    dict: Status of external software (installed/missing)
    """

def get_external_tool_version(tool_name):
    """
    Get version information for external phylogenetic software.
    
    Parameters:
    - tool_name: Name of external tool ('paup', 'raxml', etc.)
    
    Returns:
    str: Version string or None if not available
    """

Configuration and Error Handling

Classes and functions for managing external tool configuration and error handling.

class ExternalToolConfiguration:
    """
    Configuration manager for external phylogenetic tools.
    
    Parameters:
    - tool_paths: Dictionary mapping tool names to executable paths
    - temp_dir: Directory for temporary files
    - cleanup_temp_files: Whether to clean up temporary files
    """
    
    def __init__(self, **kwargs): ...
    
    def set_tool_path(self, tool_name, path):
        """Set executable path for external tool."""
    
    def get_tool_path(self, tool_name):
        """Get configured path for external tool."""
    
    def validate_tools(self):
        """Validate that all configured tools are accessible."""

# Interoperability exceptions
class ExternalToolError(Exception):
    """Raised when external tool execution fails."""

class ExternalToolNotFoundError(Exception):
    """Raised when external tool executable is not found."""

class ExternalToolTimeoutError(Exception):
    """Raised when external tool execution times out."""

class UnsupportedFormatConversionError(Exception):
    """Raised when format conversion is not supported."""

Install with Tessl CLI

npx tessl i tessl/pypi-dendropy

docs

character-data.md

core-data-models.md

data-io.md

index.md

simulation.md

tree-analysis.md

visualization-interop.md

tile.json