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.

[1]:
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.

[2]:
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.

[3]:
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.

[4]:
result.lf
[4]:

GN

log-likelihood = -6982.2248

number of free parameters = 36

Edge params
edge parent length A>C A>G A>T C>A C>G C>T
Galago root 0.1730 1.0064 3.7857 1.0385 1.7266 2.3267 6.3442
HowlerMon root 0.0451 1.0064 3.7857 1.0385 1.7266 2.3267 6.3442
Rhesus edge.3 0.0215 1.0064 3.7857 1.0385 1.7266 2.3267 6.3442
Orangutan edge.2 0.0077 0.2103 3.5008 0.2093 0.9013 1.3534 4.9566
Gorilla edge.1 0.0025 0.2103 3.5008 0.2093 0.9013 1.3534 4.9566
Human edge.0 0.0061 0.2103 3.5008 0.2093 0.9013 1.3534 4.9566
Chimpanzee edge.0 0.0028 0.2103 3.5008 0.2093 0.9013 1.3534 4.9566
edge.0 edge.1 0.0000 0.2103 3.5008 0.2093 0.9013 1.3534 4.9566
edge.1 edge.2 0.0034 0.2103 3.5008 0.2093 0.9013 1.3534 4.9566
edge.2 edge.3 0.0121 1.0064 3.7857 1.0385 1.7266 2.3267 6.3442
edge.3 root 0.0076 1.0064 3.7857 1.0385 1.7266 2.3267 6.3442
edge G>A G>C G>T T>A T>C
Galago 9.0145 1.2462 0.7647 1.4577 3.5709
HowlerMon 9.0145 1.2462 0.7647 1.4577 3.5709
Rhesus 9.0145 1.2462 0.7647 1.4577 3.5709
Orangutan 4.6227 1.1149 0.0000 0.3394 2.9912
Gorilla 4.6227 1.1149 0.0000 0.3394 2.9912
Human 4.6227 1.1149 0.0000 0.3394 2.9912
Chimpanzee 4.6227 1.1149 0.0000 0.3394 2.9912
edge.0 4.6227 1.1149 0.0000 0.3394 2.9912
edge.1 4.6227 1.1149 0.0000 0.3394 2.9912
edge.2 9.0145 1.2462 0.7647 1.4577 3.5709
edge.3 9.0145 1.2462 0.7647 1.4577 3.5709
Motif params
A C G T
0.3754 0.1768 0.2080 0.2398