PhyNetPy Documentation

Library for the Development and Use of Phylogenetic Network Methods

PhyNetPy API Reference

Welcome to the PhyNetPy documentation. PhyNetPy is a comprehensive Python library for phylogenetic network analysis, providing tools for network construction, manipulation, simulation, and inference.

Version:
0.3.0
Authors:
Mark Kessler, Luay Nakhleh
Copyright:
2025

Module Index

Module Description
Alphabet Character-to-state mapping for biological sequence data (DNA, RNA, Protein, Codon, SNP).
BiMarkers SNP (biallelic marker) likelihood computation for phylogenetic networks, with optional GPU acceleration.
BirthDeath Birth-death process network simulators (Yule and CBDP models).
Executor Computation backend abstraction layer providing CPU (NumPy) and GPU (CuPy) array operations.
GTR Time-reversible nucleotide substitution models (GTR, JC, K80, F81, HKY, K81, SYM, TN93).
GeneTrees Gene tree container and analysis utilities including consensus tree construction and concordance factors.
GraphUtils Graph and network utility functions for topology analysis, manipulation, and ASCII rendering.
IO Central I/O hub for reading and writing phylogenetic file formats (FASTA, VCF, Newick, Nexus).
Logger Simple debug logger for internal model move compatibility.
MSA Multiple Sequence Alignment parsing, storage, grouping, and distance computation.
Matrix Data matrix storage and reduction for sequence alignments with unique site pattern compression.
MetropolisHastings Metropolis-Hastings MCMC and Hill Climbing search algorithms for phylogenetic inference.
ModelFactory Component-based model building factory for constructing probabilistic phylogenetic models.
ModelGraph Probabilistic graphical model for phylogenetics with typed model nodes and visitor pattern support.
ModelMove Network topology move operations for MCMC search (add/remove/flip reticulation, SPR).
Network Core phylogenetic network data structures: Node, Edge, and Network classes.
NetworkMoves Network topology modification operations for MCMC search (add/remove hybrid, NNI, node height).
Newick Newick format label extraction and Nexus file generation utilities.
Phylo Core Branch class for storing phylogenetic edge attributes (length, inheritance probability).
PhyloNet PhyloNet Java wrapper for running external phylogenetic analysis tools.
SNPSimulator SNP data simulator for phylogenetic networks using a forward-in-time 2-state CTMC.
State State management for MCMC accept/reject decisions with model validation.
Strategy Strategy pattern interface for node-level computations dispatched during bottom-up traversal.
Traversal Iterator-based graph traversal for model nodes supporting pre-order, post-order, and level-order.
Validation Comprehensive file format validation for phylogenetic data files (Newick, Nexus, FASTA, PHYLIP, etc.).
Visitor Visitor pattern interface for ModelNode traversals with typed dispatch.
graph_core Graph core data structures with automatic Cython acceleration for NodeSet and EdgeSet.

Getting Started

Installation

pip install phynetpy

Quick Example

from PhyNetPy import Network, Node, Edge
from PhyNetPy import read_nexus, read_newick

# Parse a network from a Nexus file
networks = read_nexus("my_network.nex")
network = networks[0]

# Access network properties
print(f"Number of nodes: {len(network.V())}")
print(f"Number of edges: {len(network.E())}")
print(f"Leaves: {[leaf.label for leaf in network.get_leaves()]}")

# Parse from a Newick string
net = read_newick("((A:0.1,B:0.2):0.3,C:0.4);")

# Simulate a network
from PhyNetPy import CBDP
sim = CBDP(gamma=1.0, mu=0.5, n=10)
simulated_net = sim.generate_network()

Module Categories

Core Data Structures

  • Alphabet - Character-to-state mapping for biological sequence data (DNA, RNA, Protein, Codon, SNP).
  • MSA - Multiple Sequence Alignment parsing, storage, grouping, and distance computation.
  • Matrix - Data matrix storage and reduction for sequence alignments with unique site pattern compression.
  • Network - Core phylogenetic network data structures: Node, Edge, and Network classes.
  • Phylo - Core Branch class for storing phylogenetic edge attributes (length, inheritance probability).

Models

  • GTR - Time-reversible nucleotide substitution models (GTR, JC, K80, F81, HKY, K81, SYM, TN93).

Simulation

  • BirthDeath - Birth-death process network simulators (Yule and CBDP models).
  • SNPSimulator - SNP data simulator for phylogenetic networks using a forward-in-time 2-state CTMC.

Inference

  • BiMarkers - SNP (biallelic marker) likelihood computation for phylogenetic networks, with optional GPU acceleration.
  • MetropolisHastings - Metropolis-Hastings MCMC and Hill Climbing search algorithms for phylogenetic inference.
  • ModelMove - Network topology move operations for MCMC search (add/remove/flip reticulation, SPR).
  • NetworkMoves - Network topology modification operations for MCMC search (add/remove hybrid, NNI, node height).
  • State - State management for MCMC accept/reject decisions with model validation.

Analysis

  • GeneTrees - Gene tree container and analysis utilities including consensus tree construction and concordance factors.
  • GraphUtils - Graph and network utility functions for topology analysis, manipulation, and ASCII rendering.

I/O

  • IO - Central I/O hub for reading and writing phylogenetic file formats (FASTA, VCF, Newick, Nexus).
  • Newick - Newick format label extraction and Nexus file generation utilities.
  • PhyloNet - PhyloNet Java wrapper for running external phylogenetic analysis tools.
  • Validation - Comprehensive file format validation for phylogenetic data files (Newick, Nexus, FASTA, PHYLIP, etc.).

Infrastructure

  • Executor - Computation backend abstraction layer providing CPU (NumPy) and GPU (CuPy) array operations.
  • Logger - Simple debug logger for internal model move compatibility.
  • ModelFactory - Component-based model building factory for constructing probabilistic phylogenetic models.
  • ModelGraph - Probabilistic graphical model for phylogenetics with typed model nodes and visitor pattern support.
  • Strategy - Strategy pattern interface for node-level computations dispatched during bottom-up traversal.
  • Traversal - Iterator-based graph traversal for model nodes supporting pre-order, post-order, and level-order.
  • Visitor - Visitor pattern interface for ModelNode traversals with typed dispatch.
  • graph_core - Graph core data structures with automatic Cython acceleration for NodeSet and EdgeSet.

Navigation

Modules