Skip to main content

phylim: a phylogenetic limit evaluation library built on cogent3

Coverage Status Release DOI

phylim evaluates the identifiability when estimating the phylogenetic tree using the Markov model. The identifiability is the key condition of the Markov model used in phylogenetics to fulfil consistency.

Establishing identifiability relies on the arrangement of specific types of transition probability matrices (e.g., DLC and sympathetic) while avoiding other types. A key concern arises when a tree does not meet the condition that, for each node, a path to a tip must exist where all matrices along the path are DLC. Such trees are not identifiable 🪚🎄! For instance, in the figure below, tree T' contains a node surrounded by a specific type of non-DLC matrix, rendering it non-identifiable. In contrast, compare T' with tree T.

phylim provides a quick, handy method to check the identifiability of a model fit, where we developed a main cogent3 app, phylim. phylim is compatible with piqtree, a python library that exposes features from iqtree2.

The following content will demonstrate how to set up phylim and give some tutorials on the main identifiability check app and other associated apps.

tree1

Installation

pip install phylim

Let's see if it has been done successfully. In the package directory:

pytest

Hope all tests passed! :white_check_mark: :blush:

Run the check of identifiability

If you fit a model to an alignment and get the model result:

>>> from cogent3 import get_app, make_aligned_seqs

>>> aln = make_aligned_seqs(
...    {
...        "Human": "ATGCGGCTCGCGGAGGCCGCGCTCGCGGAG",
...        "Gorilla": "ATGCGGCGCGCGGAGGCCGCGCTCGCGGAG",
...        "Mouse": "ATGCCCGGCGCCAAGGCAGCGCTGGCGGAG",
...    },
...    info={"moltype": "dna", "source": "foo"},
... )

>>> app_fit = get_app("model", "GTR")
>>> result = app_fit(aln)

You can easily check the identifiability by:

>>> checker = get_app("phylim")

>>> checked = checker(result)
>>> checked.is_identifiable

True

The phylim app wraps all information about phylogenetic limits.

>>> checked
Source Model Name Identifiable Has Boundary Values Version
brca1.fasta GTR True True 2025.1.12

You can also use features like classifying all matrices or checking boundary values in a model fit.

Label all transition probability matrices in a model fit

You can call classify_model_psubs to give the category of all the matrices:

>>> from phylim import classify_model_psubs

>>> labelled = classify_model_psubs(result)
>>> labelled
Substitution Matrices Categories
edge namematrix category
GorillaDLC
HumanDLC
MouseDLC
Check if all parameter fits are within the boundary
>>> from phylim import check_fit_boundary

>>> violations = check_fit_boundary(result)
>>> violations
BoundsViolation(source='foo', vio=[{'par_name': 'C/T', 'init': np.float64(1.0000000147345554e-06), 'lower': 1e-06, 'upper': 50}, {'par_name': 'A/T', 'init': np.float64(1.0000000625906854e-06), 'lower': 1e-06, 'upper': 50}])

❗For users who want to check identifiability on a model with multiple likelihood functions (e.g. split codon model), please check https://github.com/HuttleyLab/PhyLim/issues/23#issuecomment-3125670158

Check identifiability for piqtree

phylim provides an app, phylim_to_model_result, which allows you to build the likelihood function from a piqtree output tree.

>>> phylo = get_app("piq_build_tree", model="GTR")
>>> tree = phylo(aln)

>>> lf_from = get_app("phylim_to_model_result")
>>> result = lf_from(tree)

>>> checker = get_app("phylim")
>>> checked = checker(result)
>>> checked.is_identifiable

True

Colour the edges for a phylogenetic tree based on matrix categories

If you obtain a model fit, phylim can visualise the tree with labelled matrices.

phylim provides an app, phylim_style_tree, which takes an edge-matrix category map and colours the edges:

>>> from phylim import classify_model_psubs

>>> edge_to_cat = classify_model_psubs(result)
>>> tree = result.tree

>>> tree_styler = get_app("phylim_style_tree", edge_to_cat)
>>> tree_styler(tree)
tree1

You can also colour edges using a user-defined edge-matrix category map, applicable to any tree object!

>>> from cogent3 import make_tree
>>> from phylim import SYMPATHETIC, DLC

>>> tree = make_tree("(A, B, C);")
>>> edge_to_cat = {"A":SYMPATHETIC, "B":SYMPATHETIC, "C":DLC}

>>> tree_styler = get_app("phylim_style_tree", edge_to_cat)
>>> tree_styler(tree)
tree1

Metadata

Release files for phylim 2025.8.27

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

Source distribution (sdist)

Source distribution for phylim 2025.8.27
File Size Uploaded
phylim-2025.8.27.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phylim 2025.8.27
File Interpreter ABI Platform
phylim-2025.8.27-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / phylim-2025.8.27.tar.gz

Download URL phylim-2025.8.27.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e6a9d19aa8c018f397aeb82e1a7c99699248c496c61e81c78846e575388e76ae
BLAKE2b-256 checksum
How to use checksums
0b9470afe7a3ee9e3e2720edfa4cfd2b1ebc1832d77da4c0f68c491f089c6d31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2025.

Transparency log

Release files / phylim-2025.8.27-py3-none-any.whl

Download URL phylim-2025.8.27-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b26d14f66b0221bdec0e45095a7bd75b02d1dc5e46a1d9cdc6ef189eef56ca3
BLAKE2b-256 checksum
How to use checksums
b0181d56ae9dca2a3a588bde7c208515423cfb646c892f79e17e247cee286cb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2025.

Transparency log
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