Skip to main content

PhyNetPy

PhyNetPy is a Python library for phylogenetic network inference and analysis. It provides improved implementations of methods from PhyloNet, plus a framework for building new Bayesian and simulation-based methods.

Current version: v0.7.0 (see CHANGELOG.md for history).

Install

pip install phynetpy

PhyNetPy's graph core and likelihood kernels are compiled with Cython. Standard installation uses a published wheel when one is available; installing from the source distribution requires a C compiler:

pip install .

See Guides/INSTALLATION_GUIDE.md for virtual environment and IDE setup.

Quick start

There are two things you can do with a phylogenetic network method -- find a network, or evaluate one -- so there are two verbs, infer and score. What they do is set by three independent arguments: the data you have, the model of the biology, and the criterion you are optimising.

from phynetpy.infer import infer, score
from phynetpy.data import GeneTrees
from phynetpy.models import MSC
from phynetpy.criteria import MDC, Likelihood, PseudoLikelihood, Bayesian

gts = GeneTrees.from_file("gene_trees.nex", {"A": ["A1", "A2"], "B": ["B1"]})

result = infer(gts, model=MSC(), criterion=PseudoLikelihood())
print(result.best, result.score)

log_lik = score(result.best, gts, model=MSC(), criterion=Likelihood())

Switching methods means changing one argument, not learning a new command. criterion=Bayesian() samples a posterior instead of maximising, and result.posterior is then populated; everything else about the call is the same. Strings work as shortcuts where an axis needs no parameters, so infer(gts, criterion="MPL") is the same call.

Whether a combination is legal depends on all three axes, so dispatch goes through a registry that doubles as a validity matrix. An impossible request fails as a TypeError and an unimplemented one as a NotImplementedError; the two are never confused. phynetpy.infer.validity_matrix() returns that table, built from the registry itself, and registered_cells() lists every implemented combination:

from phynetpy.infer import validity_matrix

for data, row in validity_matrix().items():
    print(data, row)
GeneTrees       {'MDC': '-', 'Likelihood': 'InferNetwork_ML', 'PseudoLikelihood': 'InferNetwork_MPL', 'Bayesian': 'MCMC_GT'}
Alignment       {'MDC': 'x', 'Likelihood': '-', 'PseudoLikelihood': 'x', 'Bayesian': 'MCMC_SEQ'}
BiallelicMarkers {'MDC': 'x', 'Likelihood': 'MLE_BiMarkers', 'PseudoLikelihood': '-', 'Bayesian': 'MCMC_BiMarkers'}

A method name means implemented, - means legal but not yet implemented, and x means the combination is not meaningful. The table above is for MSC; pass a model class to tabulate another, such as validity_matrix(Allopolyploid).

Data structures, I/O, and analysis helpers live at the top level. The comparison metrics take two networks on the same taxa:

from phynetpy import read_newick, joint_dissimilarity, hybrid_ancestry_error, mu_distance

estimate = read_newick("((A,(B)#H1),(#H1,C));")
truth = read_newick("(((A)#H1,B),(#H1,C));")

joint_dissimilarity(estimate, truth).D_joint_normalized   # in [0, 1]
hybrid_ancestry_error(estimate, truth)                    # estimate first
mu_distance(estimate, truth)

For the data structures and I/O, start with examples/quickstart.py. For inference, start with examples/mpl_demo.py (scoring) or examples/search_flags_demo.py, which runs the same data under two criteria side by side. Both finish in seconds. examples/mcmc_gt_demo.py shows Bayesian search but takes about nine minutes, since the full gene-tree likelihood is the expensive objective.

Layout

Path What it holds
src/ The phynetpy package.
src/infer.py The public inference API: infer, score, simulate, result types, diagnostics.
src/data/, src/models/, src/criteria/ The three axes those verbs dispatch on.
src/_registry.py, src/_engines.py The validity matrix and one adapter per implemented cell.
src/_*.py Method implementations. Private; reach them through phynetpy.infer.
src/cython/ Required compiled graph core and likelihood/scoring kernels.
examples/ Runnable end-to-end workflows.
tests/ Test suite (pytest; -m "not slow" skips long MCMC recovery runs).
docs/ Project site, plus the generated API reference in docs/api/.
Guides/ Installation, I/O, and validation guides.
scripts/ Benchmark and research tooling (not part of the library).

Inference methods

Under the multispecies network coalescent, MSC(), each data-and-criterion pair is one method. The PhyloNet command each corresponds to is named so the literature stays findable; - marks a combination that is meaningful but not implemented, and x one that is not defined at all.

MSC() MDC() Likelihood() PseudoLikelihood() Bayesian()
GeneTrees - InferNetwork_ML InferNetwork_MPL MCMC_GT
Alignment x - x MCMC_SEQ
BiallelicMarkers x MLE_BiMarkers - MCMC_BiMarkers

Allopolyploidy is a different model rather than a different command, so maximum-parsimony allopolyploid inference (Hejase et al., PhyloNet's MPAllopp) is infer(gts, model=Allopolyploid(), criterion=MDC()).

The references behind those cells: InferNetwork_ML (Yu et al., 2014), InferNetwork_MPL (Yu & Nakhleh, 2015), MCMC_GT and MCMC_SEQ (Wen & Nakhleh, 2018), MLE_BiMarkers and MCMC_BiMarkers (Bryant et al., 2012; Zhu et al., 2018).

Divide-and-conquer on a tree of blobs is a pipeline rather than a cell. infer_dimple(gts, tree_of_blobs, start_tree) (a port of DIMPLE) partitions the scaffold at its polytomies, infers each subset under MSC() with PseudoLikelihood(), merges the subset networks, and grafts the pieces back onto the scaffold. See RELEASE_NOTES_0.7.0.md for a worked call.

A third verb, simulate, runs the same axes backwards: it takes a model and a network and returns a data-axis object, so a recovery check composes directly.

from phynetpy.infer import simulate

sim = simulate(MSC(theta=0.02), taxa=6, n=200)      # draws its own species tree
recovered = infer(sim, criterion=PseudoLikelihood())

Development

python -m pytest -m "not slow"   # test suite
python generate_docs.py          # regenerate docs/api/
python deploy.py --dry-run --no-bump # test + build 0.7.0, no upload

The version lives in src/_version.py and is the single source of truth; pyproject.toml reads it and phynetpy.__version__ re-exports it.

A tutorial and further instructions will be made available on our website, https://phylogenomics.rice.edu.

Metadata

Release files for phynetpy 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phynetpy 0.7.0
File Size Uploaded Provenance Actions
phynetpy-0.7.0.tar.gz 535.2 kB Without provenance Details for phynetpy-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for phynetpy 0.7.0
File Interpreter ABI Platform Actions
phynetpy-0.7.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for phynetpy-0.7.0-cp314-cp314-win_amd64.whl

Total release size: 1.3 MB

Release files / phynetpy-0.7.0.tar.gz

Download URL phynetpy-0.7.0.tar.gz
Size 535.2 kB
Tags Source
SHA-256 checksum
How to use checksums
17594bc1ec02aa707bcfcb997e842f25999e5d23844fb15f5405760578ec403a
BLAKE2b-256 checksum
How to use checksums
8052b107aa3155baaca9fead17f61ef43776bf211dc5f4f291d19c9b8dc9ccbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / phynetpy-0.7.0-cp314-cp314-win_amd64.whl

Download URL phynetpy-0.7.0-cp314-cp314-win_amd64.whl
Size 740.7 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
02df66c23ffa3f34c27d97cb7c7047f06a92a39268004722a80063dcdd7e525c
BLAKE2b-256 checksum
How to use checksums
536fc839208a967835d199b998ade95c729c6e93126f026ef87603624da471bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for phynetpy 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page