Skip to main content
`Ctrl`+`K`

# Inferring Amino Acid frequencies with a nonstationary model

Section author: Peter Goodman, Andrew Wheeler

This example demonstrates how to apply a non-stationary, branch-heterogeneous maximum likelihood model to infer state frequency vectors across different branches or branch groups on a phylogenetic tree, highlighting a practical use case. The model used is a maximum likelihood, time-heterogeneous, and time-reversible model.

Non-stationarity means that amino acid frequencies are not fixed over time. This characteristic allows a non-stationary model to infer new frequencies along different branches or clades of a tree.

In this example, we infer an amino acid frequency vector for the primate and rodent clades in a mammal phylogeny, as well as a frequency vector for the root of these two clades. The purpose of this inference was to produce three amino acid frequency vectors for comparison. The rodent vector represented the amino acid frequencies associated with a clade reported to exhibit a higher effective population size (\(N_{e}\)), while the primate vector showed frequencies associated with a clade reported to exhibit a lower \(N_{e}\). These clade specific measures allow us to measure associations with other known properties of these clades, such as amino acid fitness metrics.

We first load the necessary functions.

Load in the fasta formatted alignment file and designate the molecule type, in this example we use protein.

Load in a substitution model (or select from models available in Cogent3). We use a single substitution model to start, and later apply branch heterogeneous frequencies.

Load in a phylogenetic tree file in Newick format.

Designate clades based in your tree for which you want to infer different frequency vectors. Use two ingroup species and the closest possible outgroup species to define each clade. All internal branches and nodes are included in the designated clade. `stem=True` sets the root of the clade as part of the clade.

We display the phylogenetic tree, using edge coloring to visualise the tree scopes represented by the model.

We now create a likelihood function.

Tell the model to infer `"mprobs"` (frequency vectors) for each set of edges you defined above. Setting `clade=True` will give a single amino acid frequency vector for all the edges within the clade, rather than a new vector for every branch. Single edges, such as the root, can be designated to be optimized separately. Any edge not included in an optimization function will retain the amino acid frequencies of the substitution model you used.

Optimize the likelihood function and look at the results.