Library for the Development and Use of Phylogenetic Network Methods
The PhyloNet module provides a Python wrapper for the PhyloNet Java software, enabling seamless integration of PhyloNet's network inference algorithms within Python workflows.
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.
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.) |
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 |
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 |
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;
"""
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.