bodkan / slendr

Population genetic simulations in R 🌍
https://bodkan.net/slendr
Other
54 stars 5 forks source link

Admixture in slendr vs msprime #99

Closed archgen closed 2 years ago

archgen commented 2 years ago

Hi Martin,

I just have a question regarding the simulation of admixture in slendr and how that translates to/relates to msprime (transferring my msprime model to slendr).

In msprime, admixture (the movement of proportion p lineages from one population to another) is handled by the add_mass_migration() parameter, where a proportion of lineages, p, will migrate from source to destination (backwards in time) in generation time, t. Because this parameter does not alter the migration rates between populations, the add_migration_rate_change() can be provided to ensure no migration continues after the simulated pulse(mass) migration.

Q: How does the slendr function gene_flow() simulate the rate parameter in relation to the start and end parameters? I.e. is this the proportion of lineages that migrate from source (from) to destination (to) "each generation" over the start and end periods (basically continuous migration of rate defined each generation)? Or is it the total proportion of lineages that will migrate over the start and end periods? As an example how do the following set-ups differ in the way slendr models admixture?

gene_flow(from=P1, to=P2, rate=0.5, start=10, end=5) VS gene_flow(from=P1, to=P2, rate=0.5, start=10, end=9).

Similarly, in msprime, the formation of an admixed population is performed through the function (example) = add_admixture(time=15, derived=P3, ancestral=[P2,P1], proportions=[0.5,0.5])

such that 50% of the lineages from P3 migrate to P2 and P1, respectively, (backwards in time). To carry-out the same behaviour in slendr, would you define the P3 population as follows: population(name=“P3”, time=15, parent=P2) and then simulate admixture at the time of P3's formation as follows: gene_flow(from=P1, to=P3, rate=0.5, start=15, end=16), # Note P3 parent population is modelled as P2?

I hope my questions are clear and please ask me to clarify if required!

Thanks very much for your help.

Best, Matthew

bodkan commented 2 years ago

Hello Matthew,

Thanks again for being interested in slendr.

If I understand your question # 1 correctly, the difference between (from your message)

gene_flow(from=P1, to=P2, rate=0.5, start=10, end=5)

and

gene_flow(from=P1, to=P2, rate=0.5, start=10, end=9)

is that in the former, slendr will "spread out" the migration between generation 10 and 5 so that the total P1 ancestry in P2 will be ~50%. In the latter case, the same will happen but the ~50% P1 ancestry in P2 will be simulated only over the course of a single generation.

Does this make sense?

Actually, now that I'm looking at that... maybe rate=? is not the right word? Should this be proportion= instead? Asking as a non-native speaker. :)

--

As for question 2, if I were to form an 50-50 mixture population in slendr (like your P3), I would do exactly what you propose.

--

I'm not much of an msprime person (I wrote exactly one msprime script in the last ~4 years and that's the msprime script that's built into slendr :)) so I honestly wasn't aware of all these options. The slendr interface is closely modelled by SLiM semantics because slendr was SLiM-only for about 70% of the time of its existence (msprime option was added only very late in its development), which is why the options are perhaps a bit more limited compared to the full msprime. Or maybe not limited in function, as you can definitely program these things, but perhaps needing one or two extra lines of code.

--

If you'd like to see how gene flow is implemented in the msprime backend, these couple of lines should clarify that. That block of code with the for loop essentially iterates of a data frame object with all gene-flow events specified by slendr in R using its gene_flow() function and schedules the msprime migration events appropriately.

bodkan commented 2 years ago

Closing because it seems that the questions have been answered. Please reopen in case an issue/bug comes up related to this.