Simulate an alignment#

Section author: Gavin Huttley

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"

For this example we just create a simple model using a four taxon tree with different branch lengths and a Felsenstein model.

import sys

from cogent3 import make_tree
from cogent3.evolve.models import get_model

Specify the 4 taxon tree,

t = make_tree("(a:0.4,b:0.3,(c:0.15,d:0.2)edge.0:0.1);")

Define our Felsenstein 1981 substitution model.

sm = get_model("F81")
lf = sm.make_likelihood_function(t)
lf.set_constant_lengths()
lf.set_motif_probs(dict(A=0.1, C=0.2, G=0.3, T=0.4))
lf

F81

number of free parameters = 0

Edge params
edgeparentlength
aroot0.40
broot0.30
cedge.00.15
dedge.00.20
edge.0root0.10
Motif params
ACGT
0.100.200.300.40

We’ll now create a simulated alignment of length 1000 nucleotides.

simulated = lf.simulate_alignment(sequence_length=1000)
simulated
0
aGGTTCTGTAAGGGCCTCTTGCTGGTTCGCGTGTGCGTCGGGGTGGGGTGCGGTGTACGAA
bCC.GT..GT..CT.T......G..A.T.TTG..AAC.TTT.C....TCAT...TG..T.T
cC..G....CT.CC....C.CTGT.A...TTG..A.T.G..CC....T.A..T.TG.A..T
dCT..T...CT.CT...GC.T.AT.AC..TTG..A.C.G...CG..TTCA..T..G.G..C

4 x 1000 (truncated to 4 x 60) dna alignment