<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/mutation-selection-and-drift-with-shiny/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://martinsbioblogg.wordpress.com/2017/05/14/mutation-selection-and-drift-with-shiny/"> R – On unicorns and genes</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Imagine a gene that comes in two variants, where one of them is deleterious to the carrier. This is not so hard to imagine, and it is often the case. Most mutations don’t matter at all. Of those that matter, most are damaging.</p>
<p>Next, imagine that the mutation happens over and over again with some mutation rate. This is also not so hard. After all, given enough time, every possible DNA sequence should occur, as if by monkeys and typewriters. In this case, since we’re talking about the deleterious mutation rate, we don’t even need exactly the same DNA sequence to occur; rather, what is important is how often a class of mutations with the same consequences happen.</p>
<p>Let’s illustrate this with a Shiny app! I made this little thing that draws graphs like this:</p>
<p><a target="_blank" rel="nofollow" href="https://martinsbioblogg.files.wordpress.com/2017/04/drift.png"><img sizes="(max-width: 640px) 100vw, 640px" data-image-description="" data-orig-file="https://martinsbioblogg.files.wordpress.com/2017/04/drift.png" data-orig-size="765,400" data-image-title="drift" data-comments-opened="1" class="wp-image-5228" data-recalc-dims="1" data-attachment-id="5228" data-permalink="https://martinsbioblogg.wordpress.com/2017/05/14/mutation-selection-and-drift-with-shiny/drift/#main" alt="" data-medium-file="https://martinsbioblogg.files.wordpress.com/2017/04/drift.png?w=300" data-large-file="https://martinsbioblogg.files.wordpress.com/2017/04/drift.png?w=450&amp;h=335&amp;fit=640%2C335" data-image-meta="{" src="https://martinsbioblogg.files.wordpress.com/2017/04/drift.png?w=450&h=335&fit=640%2C335"></a></p>
<p>This is supposed to show the trajectory of a deleterious genetic variant, with sliders to decide the population size, mutation rate, selection, dominance, and starting frequency. The lines are ten replicate populations, followed for 200 generations. The red line is the estimated equilibrium frequency — where the population would end up if it was infinitely large and not subject to random chance.</p>
<p>The app runs here: <a target="_blank" rel="nofollow" href="https://mrtnj.shinyapps.io/mutation/">https://mrtnj.shinyapps.io/mutation/</a><br>
And the code is here: <a target="_blank" rel="nofollow" href="https://github.com/mrtnj/shiny_mutation">https://github.com/mrtnj/shiny_mutation</a></p>
<p>(Note: I don’t know how well this will work if every blog reader clicks on that link. Maybe it all crashes or the bandwidth runs out or whatnot. If so, you can always download the code and run in RStudio.)</p>
<p>We assume diploid genetics, random mating, and mutation only in one direction (broken genes never restore themselves). As in typical population genetics texts, we call the working variant ”A” and the working variant ”a”, and their frequencies <em>p</em> and <em>q</em>. The genotypes <em>AA</em>, <em>Aa</em> and <em>aa</em> will have frequencies <img title="p^2 " alt="p^2 " class="latex" src="https://s0.wp.com/latex.php?latex=p%5E2+&bg=ffffff&%23038;fg=666666&%23038;s=-2">, <img title="2 p q " alt="2 p q " class="latex" src="https://s0.wp.com/latex.php?latex=2+p+q+&bg=ffffff&%23038;fg=666666&%23038;s=-2"> and <img title="q^2 " alt="q^2 " class="latex" src="https://s0.wp.com/latex.php?latex=q%5E2+&bg=ffffff&%23038;fg=666666&%23038;s=-2"> before selection.</p>
<p>Damaging variants tend to be recessive, that is, they hurt only when you have two of them. Imagine an enzyme that makes some crucial biochemical product, that you need some but not a lot of. If you have one working copy of the enzyme, you may be perfectly fine, but if you are left without any working copy, you will have a deficit. We can describe this by a dominance coefficient called <em>h</em>. If the dominance coefficient is one, the variant is completely dominant, so that it damages you even if you only have one copy. If the dominance coefficient is zero, the variant is completely recessive, and having one copy of it does not affect you at all.</p>
<p>The average reproductive success (”<a target="_blank" rel="nofollow" href="https://www.youtube.com/watch?v=fRscYVvEFt8">fitness</a>”) of each genotype is described in terms of selection coefficients, which tells us how much selection there is against a genotype. Selection coefficients range from 0, which means that you’re winning, to 1 which means that you’ve been completely out-competed. For a recessive damaging variant, the <em>AA</em> homozygotes and Aa heterozygotes are unaffected, but the <em>aa</em> homozygotes suffers selection coefficient <em>s</em>.</p>
<p>In the general case, fitness values for each genotype are 1 for <em>AA</em>, <img title="1 - hs " alt="1 - hs " class="latex" src="https://s0.wp.com/latex.php?latex=1+-+hs+&bg=ffffff&%23038;fg=666666&%23038;s=-2"> for <em>Aa</em> and <img title="1 - s " alt="1 - s " class="latex" src="https://s0.wp.com/latex.php?latex=1+-+s+&bg=ffffff&%23038;fg=666666&%23038;s=-2"> for <em>aa</em>. We can think of this as the probability of contributing to the next generation.</p>
<p>What about the red line in the graphs? If natural selection keeps removing a mutation from the gene pool, and mutation keeps adding it back in again there may be some equilibrium frequency where they cancel out, and the frequency of the damaging variant is more or less constant. This is called mutation–selection balance.</p>
<p>Haldane (1937) came up with an expression for the equilibrium variant frequency:</p>
<p><img title="q_{eq} = frac {h s + mu - sqrt{ (hs - mu)^2 + 4 s mu } } {2 h s - 2 s}" alt="q_{eq} = frac {h s + mu - sqrt{ (hs - mu)^2 + 4 s mu } } {2 h s - 2 s}" class="latex" src="https://s0.wp.com/latex.php?latex=q_%7Beq%7D+%3D+%5Cfrac+%7Bh+s+%2B+%5Cmu+-+%5Csqrt%7B+%28hs+-+%5Cmu%29%5E2+%2B+4+s+%5Cmu+%7D+%7D+%7B2+h+s+-+2+s%7D&bg=ffffff&%23038;fg=666666&%23038;s=3"></p>
<p>I’ve changed his notation a bit to use <em>h</em> and <em>s</em> for dominance and selection coefficient. <img title="mu " alt="mu " class="latex" src="https://s0.wp.com/latex.php?latex=%5Cmu+&bg=ffffff&%23038;fg=666666&%23038;s=-2"> is the mutation rate. It’s not easy to see what is going on here, but we can draw it in the graph, and see that it’s usually very small. In these small populations, where drift is a major player, the variants are often completely lost, or drift to higher frequency by chance.</p>
<p>(I don’t know if I can recommend learning by playing with an app, but I definitely learned things while making it. For instance that C++11 won’t work on shinyapps.io unless you send the compiler a flag, and that it’s important to remember that both variants in a diploid organism can mutate. So I guess what I’m saying is: don’t use my app, but make your own. Or something.)</p>
<p><strong>Literature</strong></p>
<p>Haldane, J. B. S. ”<a target="_blank" rel="nofollow" href="http://www.journals.uchicago.edu/doi/abs/10.1086/280722">The effect of variation of fitness</a>.” The American Naturalist 71.735 (1937): 337-349.</p>
<p>Postat i:<a target="_blank" rel="nofollow" href="https://martinsbioblogg.wordpress.com/category/genetik/">genetik</a> Tagged: <a target="_blank" rel="nofollow" href="https://martinsbioblogg.wordpress.com/tag/mutation/">mutation</a>, <a target="_blank" rel="nofollow" href="https://martinsbioblogg.wordpress.com/tag/r/">R</a>, <a target="_blank" rel="nofollow" href="https://martinsbioblogg.wordpress.com/tag/selection/">selection</a>, <a target="_blank" rel="nofollow" href="https://martinsbioblogg.wordpress.com/tag/shiny/">Shiny</a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/martinsbioblogg.wordpress.com/5198/"><img alt="" src="http://feeds.wordpress.com/1.0/delicious/martinsbioblogg.wordpress.com/5198/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/martinsbioblogg.wordpress.com/5198/"><img alt="" src="http://feeds.wordpress.com/1.0/facebook/martinsbioblogg.wordpress.com/5198/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/martinsbioblogg.wordpress.com/5198/"><img alt="" src="http://feeds.wordpress.com/1.0/twitter/martinsbioblogg.wordpress.com/5198/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/martinsbioblogg.wordpress.com/5198/"><img alt="" src="http://feeds.wordpress.com/1.0/stumble/martinsbioblogg.wordpress.com/5198/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/martinsbioblogg.wordpress.com/5198/"><img alt="" src="http://feeds.wordpress.com/1.0/digg/martinsbioblogg.wordpress.com/5198/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/martinsbioblogg.wordpress.com/5198/"><img alt="" src="http://feeds.wordpress.com/1.0/reddit/martinsbioblogg.wordpress.com/5198/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://martinsbioblogg.wordpress.com/2017/05/14/mutation-selection-and-drift-with-shiny/"> R – On unicorns and genes</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/mNrlUhiVylI"></a></div>