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),
],
);
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,
);
Confirm admixture with ABBA-BABA calculations¶
[ ]:
ipcoal.utils.baba()