← Back to PhyNetPy

PhyNetPy Documentation

Library for the Development and Use of Phylogenetic Network Methods

PhyloNet Module v1.0.0

The PhyloNet module provides a Python wrapper for the PhyloNet Java software, enabling seamless integration of PhyloNet's network inference algorithms within Python workflows.

Author:
Mark Kessler
Last Edit:
3/11/25
Source:
PhyloNet.py
Requirements

This module requires Java to be installed and the PhyloNet JAR file to be accessible. The JAR file path is hardcoded to PhyNetPy/src/PhyNetPy/PhyloNetv3_8_2.jar.

Contents

jarWrapper

def jarWrapper(*args) -> list[str]

Wrapper function for running Java JAR files from within Python. Captures both stdout and stderr.

Parameter Type Description
*args tuple Arguments to pass to the Java command (JAR path, input file, etc.)
Returns: list[str] - List of output lines from PhyloNet

run

def run(nex_file_loc: str) -> list[str]

Run PhyloNet on a Nexus file containing trees and PhyloNet commands.

Parameter Type Description
nex_file_loc str Path to the Nexus file with PhyloNet commands
Returns: list[str] - Lines of output from PhyloNet execution

PhyloNet Commands

PhyloNet supports various network inference commands. Common ones include:

Command Description
InferNetwork_MPL Maximum pseudo-likelihood network inference
InferNetwork_ML Maximum likelihood network inference
InferNetwork_MP Maximum parsimony network inference
CalGTProb Calculate gene tree probabilities
DeepCoalCount Count deep coalescence events

Usage Examples

from PhyNetPy.PhyloNet import run
from PhyNetPy.Newick import NexusTemplate

# Create a Nexus file with PhyloNet commands
template = NexusTemplate()
template.add("((A:1,B:1):1,(C:1,D:1):1);")
template.add("((A:1,C:1):1,(B:1,D:1):1);")
template.add("((A:1,D:1):1,(B:1,C:1):1);")
template.add_phylonet_cmd("InferNetwork_MPL (all) 1 -bl;")
template.generate("/tmp", "analysis.nex")

# Run PhyloNet
output = run("/tmp/analysis.nex")

# Process output
for line in output:
    if "Network" in line:
        print(line)

# Example Nexus file format for PhyloNet:
nexus_content = """
#NEXUS

BEGIN TAXA;
DIMENSIONS NTAX=4;
TAXLABELS A B C D;
END;

BEGIN TREES;
Tree gt1 = ((A:1,B:1):1,(C:1,D:1):1);
Tree gt2 = ((A:1,C:1):1,(B:1,D:1):1);
Tree gt3 = ((A:1,D:1):1,(B:1,C:1):1);
END;

BEGIN PHYLONET;
InferNetwork_MPL (all) 1 -bl;
END;
"""
Warning

Ensure Java is installed and accessible from the command line. The PhyloNet JAR file must be present at the expected location relative to the PhyNetPy installation.

See Also

Navigation

Modules

This Page