import sys
from cogent3 import make_tree
from cogent3.evolve.models import get_modelSimulate an alignment
For this example we just create a simple model using a four taxon tree with different branch lengths and a Felsenstein 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))
lfF81
number of free parameters = 0
| edge | parent | length |
|---|---|---|
| a | root | 0.40 |
| b | root | 0.30 |
| c | edge.0 | 0.15 |
| d | edge.0 | 0.20 |
| edge.0 | root | 0.10 |
| A | C | G | T |
|---|---|---|---|
| 0.10 | 0.20 | 0.30 | 0.40 |
We’ll now create a simulated alignment of length 1000 nucleotides.
simulated = lf.simulate_alignment(sequence_length=1000)
simulated| 0 | |
| a | GTTAGACGTCTGTTCGTGTGCCTAATTCATGTCTTACTTGTACACGCTTTACATACGGTC |
| b | AC.TT..........T......AG.AG........TT.G..GTG.C.G.GT.T.G..A.A |
| c | A..TTG....C....TG..T...C..GT..T.T..TT....T.G..AG..G.T.GGCAGA |
| d | A..CT..T..C....TG..C...C..GTCGT.G..TTG...C.C.T.G.GG.T.GG.AGA |
4 x 1000 (truncated to 4 x 60) dna alignment