Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Last active December 14, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/5136711 to your computer and use it in GitHub Desktop.
Save Ram-N/5136711 to your computer and use it in GitHub Desktop.
#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