Apply a non-stationary nucleotide model to an alignment with a tree#

Note

These docs now use the new_type core objects via the following setting.

import os

# using new types without requiring an explicit argument
os.environ["COGENT3_NEW_TYPE"] = "1"

We analyse an alignment with sequences from 6 primates.

from cogent3 import get_app

loader = get_app("load_aligned", format="fasta", moltype="dna")
aln = loader("data/primate_brca1.fasta")
aln.names
('Galago',
 'HowlerMon',
 'Rhesus',
 'Orangutan',
 'Gorilla',
 'Human',
 'Chimpanzee')

Specify the tree via a tree instance#

from cogent3 import load_tree
from cogent3 import get_app

tree = load_tree("data/primate_brca1.tree")
gn = get_app("model", "GN", tree=tree)
gn
model(sm='GN',
tree=Tree("(Galago,HowlerMon,(Rhesus,(Orangutan,(Gorilla,(Human,Chimpanzee)))));"),
unique_trees=False, tree_func=None, name=None, optimise_motif_probs=False,
sm_args=None, lf_args=None, time_het=None, param_rules=None, opt_args=None,
lower=1e-06, upper=50, split_codons=False, show_progress=False, verbose=False)

Specify the tree via a path.#

gn = get_app("model", "GN", tree="data/primate_brca1.tree")
gn
model(sm='GN', tree='data/primate_brca1.tree', unique_trees=False,
tree_func=None, name=None, optimise_motif_probs=False, sm_args=None,
lf_args=None, time_het=None, param_rules=None, opt_args=None, lower=1e-06,
upper=50, split_codons=False, show_progress=False, verbose=False)

Apply the model to an alignment#

fitted = gn(aln)
fitted
GN
keylnLnfpDLCunique_Q
'GN'-6987.963222TrueTrue

In the above, no value is shown for unique_Q. This can happen because of numerical precision issues.

Note

in the display of the lf below, the “length” parameter is not the ENS. It is, instead, just a scalar.

fitted.lf

GN

log-likelihood = -6987.9632

number of free parameters = 22

Global params
A>CA>GA>TC>AC>GC>TG>AG>CG>TT>AT>C
0.873.660.911.592.126.028.221.230.631.253.42
Edge params
edgeparentlength
Galagoroot0.17
HowlerMonroot0.04
Rhesusedge.30.02
Orangutanedge.20.01
Gorillaedge.10.00
Humanedge.00.01
Chimpanzeeedge.00.00
edge.0edge.10.00
edge.1edge.20.00
edge.2edge.30.01
edge.3root0.01
Motif params
ACGT
0.380.170.210.24