Simulate an alignment#

Section author: Gavin Huttley

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.4000
broot0.3000
cedge.00.1500
dedge.00.2000
edge.0root0.1000
Motif params
ACGT
0.10000.20000.30000.4000

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

simulated = lf.simulate_alignment(sequence_length=1000)
simulated
0
aAGTTTTTCTGGTTCCGTGTTTCATTGGTCTAATGCTTGCGCCGGACTGGCCGGCTGGTTG
bG....G..G.T..GT....G.T..CT...CC..T.C.T..G..A..G.CT.TATG.C...
cTC..AA..GT...GTC..CG.T.A.TC..C...C.G.T..G..A..G..TT.AA.T.G.T
dTC.G.A..GT..GGTC...G.T.A.T...C...T.C.T..T..AG.G..TTTTAC..G.T

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