|
192 | 192 | "id": "170c2156-aab9-4b0c-a124-21a71bc46275", |
193 | 193 | "metadata": {}, |
194 | 194 | "source": [ |
195 | | - "You can see that the ancestry of the 150 magenta \"sample nodes\" does not extend back past 100 generations (\"ticks\"). At 100 generations ago, there are still 3 separate ancestral lineages present (the local tree has \"multiple roots\"), meaning that the simulation has not fully coalesced. This means we are missing important posts of the ancestry, needed to fully understand the relationships between the sample nodes.\n", |
| 195 | + "You can see that the ancestry of the 150 magenta \"sample nodes\" does not extend back past 100 generations (\"ticks\"). At 100 generations ago, there are still 5 separate ancestral lineages present (the local tree has \"[multiple roots](https://tskit.dev/tskit/docs/stable/data-model.html#roots)\"), meaning that the simulation has not fully coalesced. This means we are missing important posts of the ancestry, needed to fully understand the relationships between the sample nodes.\n", |
196 | 196 | "\n", |
197 | 197 | "## Recapitation\n", |
198 | 198 | "\n", |
|
249 | 249 | "id": "667ec091-4246-4513-a85f-aa61d19e9097", |
250 | 250 | "metadata": {}, |
251 | 251 | "source": [ |
252 | | - "Because by definition, neutral mutations don't affect the genealogy, we can add them after the tree sequence (note that by default, `sim_mutations()` removes the mutations generated by the SLiM simulation):" |
| 252 | + "Because by definition, neutral mutations don't affect the genealogy, we can add them after recapitating the tree sequence (note that by default, `sim_mutations()` removes the mutations generated by the SLiM simulation):" |
253 | 253 | ] |
254 | 254 | }, |
255 | 255 | { |
|
270 | 270 | "source": [ |
271 | 271 | "## Natural selection\n", |
272 | 272 | "\n", |
273 | | - "Incorporating natural selection into simulations is much easier in forward-time rather than backward-time simulation. There is extensive documentation for doing this in SLiM (chapters 9 and 10 of the SLiM manual). However, there is very limited support for approximating the effect of selective sweeps in backward-time in _msprime_ (see [here](https://tskit.dev/msprime/docs/stable/ancestry.html#sec-ancestry-models-selective-sweeps)), which is demonstrated below:" |
| 273 | + "Incorporating natural selection into simulations is much easier in forward-time rather than backward-time simulation. There is extensive documentation for doing this in SLiM (chapters 9 and 10 of the SLiM manual). However, there is also limited support for approximating the effect of selective sweeps in backward-time in _msprime_ (see [here](https://tskit.dev/msprime/docs/stable/ancestry.html#sec-ancestry-models-selective-sweeps)), which is demonstrated below:" |
274 | 274 | ] |
275 | 275 | }, |
276 | 276 | { |
|
285 | 285 | "# define hard sweep model\n", |
286 | 286 | "start_freq = 1.0 / (2 * params[\"population_size\"])\n", |
287 | 287 | "end_freq = 1 - start_freq\n", |
| 288 | + "sweep_position = params[\"sequence_length\"]/2\n", |
288 | 289 | "sweep_model = msprime.SweepGenicSelection(\n", |
289 | | - " position=params[\"sequence_length\"]/2, start_frequency=start_freq, end_frequency=end_freq, s=0.25, dt=1e-6,\n", |
| 290 | + " position=sweep_position, start_frequency=start_freq, end_frequency=end_freq, s=0.25, dt=1e-6,\n", |
290 | 291 | ")\n", |
291 | 292 | "ts = msprime.sim_ancestry(10, model=[sweep_model, \"hudson\"], recombination_rate=1e-7, **params)\n", |
292 | 293 | "mutated_ts = msprime.sim_mutations(ts, rate=1e-7)" |
|
311 | 312 | "import numpy as np\n", |
312 | 313 | "\n", |
313 | 314 | "windows = np.linspace(0, mutated_ts.sequence_length, 50)\n", |
314 | | - "plt.stairs(mutated_ts.diversity(windows=windows), windows, baseline=None);" |
| 315 | + "plt.stairs(mutated_ts.diversity(windows=windows), windows, baseline=None)\n", |
| 316 | + "plt.axvline(x=sweep_position, ls=\":\", label=\"Genome location\\nof selective sweep\")\n", |
| 317 | + "plt.legend()" |
315 | 318 | ] |
316 | 319 | }, |
317 | 320 | { |
|
0 commit comments