Last active
December 14, 2015 19:29
-
-
Save Ram-N/5136711 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
#Given a parent individual, get one of their Alleles in the gamete | |
getGamete <- function(indiv) { | |
if (indiv == 1) return(1) #AA | |
if (indiv == 3) return(0) #aa | |
#if Parent is Aa, the gamete is one binomial trial with prob.big.A | |
if (indiv == 2) return(rbinom(1, size=1, prob.big.A)) #Aa | |
} | |
#Two parental Gametes combine to form a zygote | |
combineGametes <- function(mg,dg) { | |
if ((mg == 1) && (dg == 1)) return(1) #AA | |
else if ((mg == 0) && (dg == 0)) return(3) #aa | |
else return(2) #Aa | |
} | |
#Given two individuals, get an offspring for next generation | |
getOffspring <- function(mom, dad) { | |
momGam <- getGamete(mom) | |
dadGam <- getGamete(dad) | |
return(combineGametes(momGam, dadGam)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment