Skip to main content

A library for checking the limits of phylogenetic tree estimation.

Project description

phylim: a phylogenetic limit evaluation library built on cogent3

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 piqtree2, 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! :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

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

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

You can easily check the identifiability by:

>>> app_ident_check = get_app("phylim")

>>> record = app_ident_check(result)
>>> record.is_identifiable

True

The phylim app wraps all information about phylogenetic limits.

>>> record
Source Model Name Identifiable Has Boundary Values Version
brca1.fasta GTR True True 2024.9.20

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}])

Check identifiability for piqtree2

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

>>> from piqtree2 import build_tree

>>> tree = build_tree(algn, model="GTR")
>>> app_inverter = get_app("phylim_tree_to_likelihoodfunction")

>>> result = app_inverter(tree)
>>> record = app_ident_check(result)
>>> record.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_colour_edges, 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

>>> app_colour_edge = get_app("phylim_colour_edges", edge_to_cat)
>>> app_colour_edge(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.classify_matrix import SYMPATHETIC, DLC

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

>>> app_colour_edge = get_app("phylim_colour_edges", edge_to_cat)
>>> app_colour_edge(tree)
tree1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phylim-2024.12.3.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

phylim-2024.12.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file phylim-2024.12.3.tar.gz.

File metadata

  • Download URL: phylim-2024.12.3.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for phylim-2024.12.3.tar.gz
Algorithm Hash digest
SHA256 339e090ee16ddcc687e12cf179c8ed5d7c6b1f1401ac583cd438135919cd06a4
MD5 536c0a43ca0f74b329b3d55af6bc482a
BLAKE2b-256 071599c4e970fea95f7d120bbe413afd9d961a097f659144c2d117e6ef2c3d6d

See more details on using hashes here.

File details

Details for the file phylim-2024.12.3-py3-none-any.whl.

File metadata

  • Download URL: phylim-2024.12.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for phylim-2024.12.3-py3-none-any.whl
Algorithm Hash digest
SHA256 65e958a2d64774e2ebbbea78e5ab6e4cfd8f93751d1b2a3765edadcf78388c9d
MD5 b3386d3fcde17578bde5974aa24dd142
BLAKE2b-256 54dea48d6a243b51bca34688449bf20a22b31bbe7e498c692dc3d9cbf374a5c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page