Skip to content

Commit

Permalink
add moments interactions (#19)
Browse files Browse the repository at this point in the history
* Add moments to requirements.txt

* Add SFS under selection using moments applet.
  • Loading branch information
molpopgen authored Dec 1, 2021
1 parent be02213 commit dbc104f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ parts:
- file: markdown/kingman_coalsecent/mutation_frequencies
- file: markdown/kingman_coalsecent/expectations
- file: markdown/kingman_coalsecent/distributions
- caption: Diffusion models
chapters:
- file: markdown/diffusion/sfs_selection
- caption: Linked selection
chapters:
- file: markdown/classic_selection_drift/sweep_from_new_mutation
Expand Down
39 changes: 39 additions & 0 deletions book/markdown/diffusion/sfs_selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---

# Mutation frequencies under selection (interactive Python)

This notebook requires Binder for the interactive features to function.
See {ref}`here <interactive_python_notebooks>` for more information.

This applet uses [moments](https://moments.readthedocs.io) {cite:p}`Jouganous2017-tg` to calculate the site-frequency spectrum in a sample of size 20 as a function of $\gamma = 2N_es$, the scaled strength of selection.

```{code-cell} python
import holoviews as hv
import moments
hv.extension('bokeh')
def fs_negative_selection(gamma):
fs_neg = moments.Spectrum(
moments.LinearSystem_1D.steady_state_1D(20, gamma=gamma)
)[1:-1]
b = hv.Histogram(([int(i)+1 for i in range(20)], fs_neg))
b = b.redim(y=hv.Dimension('y',range=(0, 1.1*fs_neg.max())))
b = b.opts(xlabel="Sample frequency", ylabel="Density")
return b
kdims = [hv.Dimension('gamma',range=(-10, 10), step=1, default=0)]
fsplot = hv.DynamicMap(fs_negative_selection,
kdims=kdims).opts(framewise=True, width=500)
fsplot
```
5 changes: 4 additions & 1 deletion book/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ @ARTICLE{Jouganous2017-tg
keywords = "demographic inference; diffusion approximation; joint allele
frequency spectrum; moments
equations;polygenic\_inference\_R01;fwdpy11\_manual;popgen-course-material;Stehany",
language = "en"
language = "en",
issn = "0016-6731, 1943-2631",
pmid = "28495960",
pmc = "PMC5500150"
}

@ARTICLE{Kreitman1983-xr,
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ matplotlib
numpy
msprime==1.0.1
pandas
git+https://bitbucket.com/simongravel/moments

0 comments on commit dbc104f

Please sign in to comment.