Last active
February 12, 2016 13:30
-
-
Save Swarchal/13e89483cf2f35f4f6a2 to your computer and use it in GitHub Desktop.
Medelian inheritence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Mendelian inheritance\n", | |
"=======================\n", | |
"\n", | |
"- Given three integers $k$, $m$ and $n$, representing a population of $k + m + n$ individuals in which:\n", | |
" - $k$ are homozygous dominant (A,A)\n", | |
" - $m$ are heterozygous (A, a)\n", | |
" - $n$ are homozygous recessive (a, a)\n", | |
"- Return the probability that any two individual will produce an offspring containing a dominant allele\n", | |
"\n", | |
"\n", | |
"**Percent offspring containing dominant allele:**\n", | |
"\n", | |
"\\begin{align}\n", | |
"k + k &= 100\\% \\\\\n", | |
"k + m &= 100\\% \\\\\n", | |
"k + n &= 100\\% \\\\\n", | |
"m + m &= 75\\% \\\\\n", | |
"m + n &= 50\\% \\\\\n", | |
"n + n &= 0\\% \\\\\n", | |
"\\end{align}\n", | |
"\n", | |
"**Probability of selecting a pair at random:** \n", | |
"\\begin{align}\n", | |
"\\text{pop} &= k + m + n \\\\\n", | |
"P(k,m) &= \\frac{k}{\\text{pop}} \\times \\frac{m}{\\text{pop} -1} \\\\\n", | |
"P(m,m) &= \\frac{m}{\\text{pop}} \\times \\frac{m-1}{\\text{pop} -1} \\\\\n", | |
"\\end{align}\n", | |
"\n", | |
"If we multiply each of these by the probability of producing an offspring with a dominant allele, i.e:\n", | |
"\n", | |
"\\begin{align}\n", | |
"P &= \\frac{m}{\\text{pop}} \\times \\frac{n}{\\text{pop} -1} \\times 0.5\n", | |
"\\end{align}\n", | |
"\n", | |
"Then sum the probability of all outcomes" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"mendel <- function(k, m, n){\n", | |
" \n", | |
" pop <- k + m + n\n", | |
" \n", | |
" p1 <- k / pop\n", | |
" p2 <- (m / pop) * (k / (pop - 1))\n", | |
" p3 <- (m / pop) * ((m - 1)/ (pop - 1)) * 0.75\n", | |
" p4 <- (m / pop) * (n / (pop - 1)) * 0.5\n", | |
" p5 <- (n / pop) * (m / (pop - 1)) * 0.5\n", | |
" p6 <- (n / pop) * (k / (pop - 1))\n", | |
" # n + n will be zero, don't need to calculate\n", | |
"\n", | |
" out <- p1 + p2 + p3 + p4 + p5 + p6\n", | |
" return(out)\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"0.783333333333333" | |
], | |
"text/latex": [ | |
"0.783333333333333" | |
], | |
"text/markdown": [ | |
"0.783333333333333" | |
], | |
"text/plain": [ | |
"[1] 0.7833333" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mendel(2,2,2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"0.810457516339869" | |
], | |
"text/latex": [ | |
"0.810457516339869" | |
], | |
"text/markdown": [ | |
"0.810457516339869" | |
], | |
"text/plain": [ | |
"[1] 0.8104575" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mendel(6, 8, 4)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "R", | |
"language": "R", | |
"name": "ir" | |
}, | |
"language_info": { | |
"codemirror_mode": "r", | |
"file_extension": ".r", | |
"mimetype": "text/x-r-source", | |
"name": "R", | |
"pygments_lexer": "r", | |
"version": "3.2.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment