Created
February 19, 2016 13:50
-
-
Save Swarchal/7f587a73f4a97c6c3156 to your computer and use it in GitHub Desktop.
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": [ | |
"Expected Offspring\n", | |
"====================\n", | |
"\n", | |
"Probability of having a dominant allele for each couple pairing:\n", | |
"\n", | |
"1. AA-AA = 1\n", | |
"2. AA-Aa = 1\n", | |
"3. AA-aa = 1\n", | |
"4. Aa-Aa = 0.75\n", | |
"5. Aa-aa = 0.5\n", | |
"6. aa-aa = 0\n", | |
"\n", | |
"--------------------\n", | |
"\n", | |
"1. Open data and transform into list of numbers\n", | |
"2. List of probabilities of dominant allele 1-6 ($P_\\text{dominant}$)\n", | |
"3. Multiply (element-wise) input numbers by $P_\\text{dominant}$\n", | |
"4. Sum and multiply by number of offspring" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Python" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"151574.5" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"def expected_pop(x):\n", | |
"\n", | |
" N_OFFSPRING = 2\n", | |
" dat = open(x).read()\n", | |
" numbers = map(int, dat.split())\n", | |
" multiplier = [1, 1, 1, 0.75, 0.5, 0]\n", | |
" out = [x*y for x,y in zip(numbers, multiplier)]\n", | |
" return sum(out) * N_OFFSPRING\n", | |
"\n", | |
"expected_pop(\"/home/scott/Dropbox/rosalind/rosalind_iev.txt\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## R" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"151574.5" | |
], | |
"text/latex": [ | |
"151574.5" | |
], | |
"text/markdown": [ | |
"151574.5" | |
], | |
"text/plain": [ | |
"[1] 151574.5" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"expected_pop <- function(x){\n", | |
" \n", | |
" N_OFFSPRING <- 2\n", | |
" data <- readLines(x)\n", | |
" intermediate <- strsplit(data, ' ')\n", | |
" numbers <- as.numeric(unlist(intermediate))\n", | |
" multiplier <- c(1, 1, 1, 0.75, 0.5, 0)\n", | |
" out <- numbers * multiplier\n", | |
" return(sum(out) * N_OFFSPRING)\n", | |
"}\n", | |
"\n", | |
"expected_pop(\"~/Dropbox/rosalind/rosalind_iev.txt\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment