Specifying a non-stationary model with time-heterogeneous parameters

A model is considered time-heterogeneous if rate matrix terms differ between edges on a tree.

In this example, we load the and display our sample primate tree, highlighting the edge sets that will be assigned different rate matrices.

from cogent3 import load_tree
from cogent3.app import io, evo

tree = load_tree("data/primate_brca1.tree")
fig = tree.get_figure(contemporaneous=True)
fig.style_edges(
    "Human", tip2="Orangutan", outgroup="Galago", line=dict(color="red")
)
fig.show(width=500, height=500)

Specify a distinct rate matrix for the great apes

As illustrated above, this is done by specifying the names of two “ingroup” tips (their last common ancestor is the ancestor of all edges of interest) and an “outgroup” tip. We can define the clade by Orangutan and one of Human, Chimpanzee or Gorilla. Any tip not a member of the clade outside suffices as an outgroup.

To construct a model with this information, we create a dictionary that we assign to the time_het argument as follows.

time_het = evo.model(
    "GN",
    tree=tree,
    time_het=[dict(tip_names=["Human", "Orangutan"], outgroup_name="Galago")],
)

The outcome of this setting to model is that the black edges will share one rate matrix, the red edges another. We fit the model to the sample data set.

reader = io.load_aligned(format="fasta")
aln = reader("data/primate_brca1.fasta")
result = time_het(aln)

Examining the fitted likelihood function, the rate parameters differ between the edge sets.

result.lf

GN

log-likelihood = -6982.2248

number of free parameters = 36

Edge params
edgeparentlengthA>CA>GA>TC>AC>GC>T
Galagoroot0.17301.00643.78581.03851.72662.32676.3443
HowlerMonroot0.04511.00643.78581.03851.72662.32676.3443
Rhesusedge.30.02151.00643.78581.03851.72662.32676.3443
Orangutanedge.20.00770.21033.50010.20930.90111.35314.9554
Gorillaedge.10.00250.21033.50010.20930.90111.35314.9554
Humanedge.00.00610.21033.50010.20930.90111.35314.9554
Chimpanzeeedge.00.00280.21033.50010.20930.90111.35314.9554
edge.0edge.10.00000.21033.50010.20930.90111.35314.9554
edge.1edge.20.00340.21033.50010.20930.90111.35314.9554
edge.2edge.30.01211.00643.78581.03851.72662.32676.3443
edge.3root0.00761.00643.78581.03851.72662.32676.3443
continuation
G>AG>CG>TT>AT>C
9.01451.24620.76471.45773.5709
9.01451.24620.76471.45773.5709
9.01451.24620.76471.45773.5709
4.62181.11470.00000.33942.9905
4.62181.11470.00000.33942.9905
4.62181.11470.00000.33942.9905
4.62181.11470.00000.33942.9905
4.62181.11470.00000.33942.9905
4.62181.11470.00000.33942.9905
9.01451.24620.76471.45773.5709
9.01451.24620.76471.45773.5709
Motif params
ACGT
0.37540.17680.20800.2398