Admixture

Defining admixture scenarios is easy in ipcoal.

[1]:
import toytree
import ipcoal

Initialize a tree

[2]:
# init a random tree
tre = toytree.rtree.unittree(8, treeheight=1e6, seed=123)

Define and draw admixture events

You can use toytree to visualize admixture on the tree. The directionality indicated by the arrow in the figure is forward in time migration. The tuple used to define the migration scenario (source, dest, time, rate) uses terminology backwards in time (source is where the introgressed alleles will end up).

[3]:
# draw with one admixture edge
tre.draw(
    ts='c',
    admixture_edges=(4, 3, 0.5, 0.1),
);

# draw with two admixture edges
tre.draw(
    ts='c',
    admixture_edges=[
        (4, 3, 0.5, 0.1),
        (3, 8, 0.5, 0.2),
    ],
);
idx: 0 name: r6 dist: 500000 support: 100 height: 00idx: 1 name: r4 dist: 500000 support: 100 height: 01idx: 2 name: r7 dist: 500000 support: 100 height: 02idx: 3 name: r2 dist: 500000 support: 100 height: 03idx: 4 name: r5 dist: 250000 support: 100 height: 04idx: 5 name: r0 dist: 250000 support: 100 height: 05idx: 6 name: r3 dist: 500000 support: 100 height: 06idx: 7 name: r1 dist: 750000 support: 100 height: 07idx: 8 name: 8 dist: 250000 support: 100 height: 2500008idx: 9 name: 9 dist: 250000 support: 100 height: 5000009idx: 10 name: 10 dist: 250000 support: 100 height: 50000010idx: 11 name: 11 dist: 250000 support: 100 height: 50000011idx: 12 name: 12 dist: 250000 support: 100 height: 75000012idx: 13 name: 13 dist: 250000 support: 100 height: 75000013idx: 14 name: 14 dist: 250000 support: 100 height: 10000001405000001000000
idx: 0 name: r6 dist: 500000 support: 100 height: 00idx: 1 name: r4 dist: 500000 support: 100 height: 01idx: 2 name: r7 dist: 500000 support: 100 height: 02idx: 3 name: r2 dist: 500000 support: 100 height: 03idx: 4 name: r5 dist: 250000 support: 100 height: 04idx: 5 name: r0 dist: 250000 support: 100 height: 05idx: 6 name: r3 dist: 500000 support: 100 height: 06idx: 7 name: r1 dist: 750000 support: 100 height: 07idx: 8 name: 8 dist: 250000 support: 100 height: 2500008idx: 9 name: 9 dist: 250000 support: 100 height: 5000009idx: 10 name: 10 dist: 250000 support: 100 height: 50000010idx: 11 name: 11 dist: 250000 support: 100 height: 50000011idx: 12 name: 12 dist: 250000 support: 100 height: 75000012idx: 13 name: 13 dist: 250000 support: 100 height: 75000013idx: 14 name: 14 dist: 250000 support: 100 height: 10000001405000001000000

Simulate on the tree with admixture

[71]:
# init a model Class object for simulations
model = ipcoal.Model(
    tree=tre,
    Ne=90000,
    admixture_edges=[
        (3, 4, 0.5, 0.2),
        (9, 10, 0.5, 0.2),
    ],
    seed=999,
)
[72]:
# simulate N loci
model.sim_loci(10, 1000)
[73]:
# show first 10 genealogies
model.df.head(10)
[73]:
locus start end nbps nsnps genealogy
0 0 0 448 448 28 (((r7:636531,r2:636531):...
1 0 448 746 298 20 (((r7:636531,r2:636531):...
2 0 746 1000 254 21 ((r3:506456,(r5:263784,r...
3 1 0 219 219 9 (((r7:555395,r2:555395):...
4 1 219 650 431 19 (((r7:555395,r2:555395):...
5 1 650 891 241 9 ((r1:885204,(r3:582677,(...
6 1 891 997 106 6 ((r4:879841,(r6:793892,(...
7 1 997 1000 3 0 ((r4:879841,(r6:793892,(...
8 2 0 3 3 0 ((r6:648195,r4:648195):4...
9 2 3 195 192 14 ((r6:648195,r4:648195):4...
[74]:
# load a multitree object from first 5 genealogies
mtre = toytree.mtree(model.df.genealogy)

# draw trees from the first locus
#  with 'shared_axis' to show diff in heights
#  with 'fixed_order' to show diff in topology (relative to first tree)
mtre.draw_tree_grid(
    start=0,
    ncols=3,
    nrows=1,
    shared_axis=True,
    fixed_order=True,
    tree_style='c',
    node_labels=False,
    node_sizes=8,
    tip_labels=True,
);

# draw trees from the second locus
mtre.draw_tree_grid(
    start=3,
    ncols=3,
    nrows=1,
    shared_axis=True,
    fixed_order=True,
    tree_style='c',
    node_labels=False,
    node_sizes=8,
    tip_labels=True,
);
r0r5r3r1r4r6r2r7 r0r5r3r1r4r6r2r7 r0r5r3r1r4r6r2r7 05502911100583
r0r5r3r1r4r6r2r7 r0r5r3r1r4r6r2r7 r0r5r3r1r4r6r2r7 05375241075049

Confirm admixture with ABBA-BABA calculations

[ ]:
ipcoal.utils.baba()