Skip to content

Commit 7c9b32f

Browse files
authored
Merge pull request #28 from hyanwong/minor-tskit-tweak
Slight tidying of simulation notebook
2 parents 69cff8b + 1804567 commit 7c9b32f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ Individual notebooks can be linked using their name, e.g.
88

99
https://tskit.dev/explore/lab/?path=tskit.ipynb
1010

11-
These notebooks run JupyterLite as a static site, with compiled versions of the lastest versions of tskit and msprime. They therefore provide pyodide access to the most recent released versions of these libraries. Notebooks can be used in any modern browser:
11+
These notebooks run JupyterLite as a static site, with compiled versions of the latest
12+
versions of tskit and msprime as listed on the
13+
[pyodide recipes repository](https://github.com/pyodide/pyodide-recipes/).
14+
They therefore provide pyodide access to recent tskit-ecosystem packages, which
15+
can be loaded simply using e.g. `import tskit`.
16+
This only applies to python packages that have C components. Pure python packages
17+
(such as pyslim) can be loaded in pyodide using _micropip_, e.g. via
18+
`await micropip.install("pyslim")` (which will load the most recent version on PyPI).
19+
Note, however, that packages relying on [numba](https://numba.pydata.org) will not yet run on pyodide.
20+
21+
Notebooks can be used in any modern browser:
1222

1323
- How-to Guides: https://jupyterlite.readthedocs.io/en/latest/howto/index.html
1424
- Reference: https://jupyterlite.readthedocs.io/en/latest/reference/index.html

content/simulation.ipynb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"id": "170c2156-aab9-4b0c-a124-21a71bc46275",
193193
"metadata": {},
194194
"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",
196196
"\n",
197197
"## Recapitation\n",
198198
"\n",
@@ -249,7 +249,7 @@
249249
"id": "667ec091-4246-4513-a85f-aa61d19e9097",
250250
"metadata": {},
251251
"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):"
253253
]
254254
},
255255
{
@@ -270,7 +270,7 @@
270270
"source": [
271271
"## Natural selection\n",
272272
"\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:"
274274
]
275275
},
276276
{
@@ -285,8 +285,9 @@
285285
"# define hard sweep model\n",
286286
"start_freq = 1.0 / (2 * params[\"population_size\"])\n",
287287
"end_freq = 1 - start_freq\n",
288+
"sweep_position = params[\"sequence_length\"]/2\n",
288289
"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",
290291
")\n",
291292
"ts = msprime.sim_ancestry(10, model=[sweep_model, \"hudson\"], recombination_rate=1e-7, **params)\n",
292293
"mutated_ts = msprime.sim_mutations(ts, rate=1e-7)"
@@ -311,7 +312,9 @@
311312
"import numpy as np\n",
312313
"\n",
313314
"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()"
315318
]
316319
},
317320
{

0 commit comments

Comments
 (0)