Recapitation using specified demography

127 views
Skip to first unread message

Guillaume Lan-Fong

unread,
Apr 8, 2022, 9:21:03 AM4/8/22
to slim-discuss
Hello everyone,

I’m currently trying to get a better grasp of the recapitation aspect of SliM/pyslim and I’d like to get some inputs on wether or not I’m using it correctly.

Here’s the intended scenario :

  • A single population pop_0 splits into 2 populations, A and B.
  • After some time, migration starts from population B to population A.
  • After some time, population A then goes through a demographic change (let’s say a bottleneck).
  • After some time, a (highly) beneficial mutation appears in population A and sweeps.
  • We sample some individuals of population A and compute some statistics on them.

Here’s a quick breakdown of my simulations.
First, the SLiM part, with tree-seq recording on :

  • Starting with 2 populations, A and B, of equal size.
  • Migration starts.
  • Demographic change occurs.
  • Mutation appears.
  • Output trees.

Then, the recapitation part :

  • Load the trees.
  • Specify the demography.
  • Recapitation of the trees using the specified demography.
  • Add neutral mutations on the trees.
  • Sample individuals from population A
  • Simplify the trees to retain only the sampled individuals
  • Compute statistics (or anything else)

I’m pretty confident about the general breakdown and the SLiM part, but I’m not quite sure that I’ve got each step correct through the ‘run’, especially the parts concerning the recapitation using a specific demography, as I’ve never used this before, and have to go from ‘forward time’ to ‘backward time’ and alternate between them.

One of the biggest question I have is to know what does recapitation does to the ‘already existing demographic events’. Does the process just ‘goes backward in time without doing anything up to the point where trees were ‘created’ aka the first generation in SLiM and THEN proceed to use coalescent simulations ? Or does it actually ‘use’ the specified demography to ‘change’ the already existing trees, thus altering the already existing parts of the trees to ‘fit’ the specified demography ?

From my understanding, it should be the first explaination but better safe than sorry, especially as I’m not quite sure that my demography is correctly specified in my script and don't want it to mess with the forward part of my simulations.

I’ve added both my scripts to this post (with some comments on the ‘recapitation’ jupyter notebook), if anyone would be kind enough to have a look at them and tell me if I’ve made any mistakes or have any tips or advices to share, that would be very kind !

Cheers,
Guillaume

MGD_split-SIM.slim
trees2ms.ipynb

Peter Ralph

unread,
Apr 8, 2022, 9:49:39 AM4/8/22
to Guillaume Lan-Fong, slim-discuss
Hi, Guillaume! That workflow sounds good. A small note is that you
might not need to use SLiM until the beneficial mutation actually
occurs, but there's no harm in it either.

> One of the biggest question I have is to know what does recapitation does to the ‘already existing demographic events’. Does the process just ‘goes backward in time without doing anything up to the point where trees were ‘created’ aka the first generation in SLiM and THEN proceed to use coalescent simulations ? Or does it actually ‘use’ the specified demography to ‘change’ the already existing trees, thus altering the already existing parts of the trees to ‘fit’ the specified demography ?
>
> From my understanding, it should be the first explaination but better safe than sorry, especially as I’m not quite sure that my demography is correctly specified in my script and don't want it to mess with the forward part of my simulations.

That's right - recapitation does not modify the trees at all, it only
adds to them. What recapitation does is it extends any uncoalesced
lineages further back in time, until they coalesce. In your python
script, all of these uncoalesced lineages should be at SLiM_time
time-ago, since in the tree sequence "time" is "time ago", i.e., "time
before then end of the simulation". So, you've done the right thing by
making sure that the population split is longer ago than SLiM_time.
(If you didn't, you'd get an error about linages being sampled from
populations that don't exist at the time.)

> I’ve added both my scripts to this post (with some comments on the ‘recapitation’ jupyter notebook), if anyone would be kind enough to have a look at them and tell me if I’ve made any mistakes or have any tips or advices to share, that would be very kind !

I've looked at the python script and didn't see any issues - the only
thing I thought of to add is `print(demography)` to make sure it's
doing what you want.

Happy SLiMulating!
* peter

Guillaume Lan-Fong

unread,
Apr 8, 2022, 11:15:56 AM4/8/22
to slim-discuss
Hi Peter,
Thanks for your nice and quick answer !

I might give your advice a try and keep the use of SLiM to the bare minimum for the simulations - it might same me some time in the long run to only simulate as little as needed in forward time.

Just to be sure that I've got everything correctly, I've tried to add to my previous script to do exactly this : handle everything but the actual beneficial mutation with recapitation.

So here, I set things as before but add some migration from p2 to p1 (in backward time) and a change in p1 size.
As a side question : I wasn't really sure about what was actually the 'initial_size' of a population when specified in the demography. I've understand it as the 'size at the current time' so the size of the population 'at the end of the SLiM simulations' - it shouldn't be a problem with this 'new version' as the actual size of populations stay the same during the SLiM part, but I'm curious to know if I got it correctly ?

Using this 'new version' of this script (please see script attached - interresting changes are in the 'Set demography event' part), if I've understand everything, I could then reduce my SLiM script to something as small as :
  • Initialize()
  • Add subpopulations p1 and p2
  • Add beneficial mutation
  • Output tree-seq
Am I right ?

Thanks once again,
Guillaume
trees2ms-Copy1.ipynb

Peter Ralph

unread,
Apr 8, 2022, 2:51:22 PM4/8/22
to Guillaume Lan-Fong, slim-discuss
Hi, Guillaume! We should probably move further discussion off-list,
but quick answers:

> So here, I set things as before but add some migration from p2 to p1 (in backward time) and a change in p1 size.
> As a side question : I wasn't really sure about what was actually the 'initial_size' of a population when specified in the demography. I've understand it as the 'size at the current time' so the size of the population 'at the end of the SLiM simulations' - it shouldn't be a problem with this 'new version' as the actual size of populations stay the same during the SLiM part, but I'm curious to know if I got it correctly ?

This sounds right; have a look at
https://tskit.dev/msprime/docs/stable/demography.html#sec-demography-populations-initial-size
for a detailed description.

> Using this 'new version' of this script (please see script attached - interresting changes are in the 'Set demography event' part), if I've understand everything, I could then reduce my SLiM script to something as small as :
>
> Initialize()
> Add subpopulations p1 and p2
> Add beneficial mutation
> Output tree-seq
>
> Am I right ?

Yes - any portion of time where everything is neutral and you've only
got discrete populations and you don't need to worry about the
demographic details (eg age structure or sex ratio) it's very safe to
use a coalescent simulation for. Your updated script looks right, but
again, I haven't cross-checked things about what exactly you said you
want to do.

** peter
Reply all
Reply to author
Forward
0 new messages