Genetic Drift Simulator For R

I was on a train this weekend for a couple of hours so decided to fill my time making a program to simulate genetic drift in R (code pasted below), specifically one capable of handling unequal sex ratio. Sex ratio directly affects the effective population size, and this simulation can be used to show that it is the effective population size (NE), rather than the census population size (NA), that determines the population genetic behaviour of a population.

Here are some demonstration results, where 10 replicate populations are simulated with NE = 360, and an initial allele frequency of 0.5. The left hand simulations have unequal sex ratios, while the sex ratio is equal in the right hand simulations. Both sets of simulations behave similarly, showing that effective population size is the important determinant of population genetic behaviour.


#####~ Genetic Drift Simulator ~#####
#######~  Robert M. Griffin  ~#######
#####~ Updated March 22nd 2016 ~#####
# Pop   = Replicate populations
# Gen   = Generations
# NM    = Male population size
# NF    = Female population size
# P     = Frequency of focal allele
# histo = Optional histogram
GenDriftSim = function(Pop = Pop, Gen = Gen, NM, NF, P, histo = "yes"){
 P = (2*(NM+NF))*P
 NE = round((4*NM*NF)/(NM+NF),0)
 SR = round(NM/NF,2)
 Na = NM+NF
 plot(c(0,0),type = "n", main = bquote('N'[M]~'/ N'[F]~'='~.(SR)*', N'[A]~'='~.(Na)*', N'[E]~'='~.(NE)), cex.main = 1, 
 xlim = c(1,Gen), ylim=c(0,1), xlab = "Generations", ylab = "Fequency of focal allele")
 for (i in 1:Pop){
 N = NM+NF
 startA = as.vector(c(rep(1, times = P),rep(0, times = (2*N)-P)))
 Population = matrix(c(
 c(sample(startA, size = 2*N, replace = FALSE)),
 c(rep("M", times = NM), rep("F", times = NF))),
 ncol = 3)
 SimResults[(Gen*i)+1-Gen, 3] <<- sum(as.numeric(Population[,1:2]))/(N*2)
 for(j in 1:(Gen-1)){
 Population = matrix(c(
 c(sample(sample(Population[(1:NM),1:2], replace = TRUE),N, replace = TRUE)),
 c(sample(sample(Population[(1+NM):N,1:2], replace = TRUE),N, replace = TRUE)),
 c(rep("M", times = NM), rep("F", times = NF))), ncol = 3)
 SimResults[(Gen*i)+1+j-Gen, 3] <<- sum(as.numeric(Population[,1:2]))/(N*2)
 s = (i*Gen)-Gen+1; e = i*Gen
 r = as.vector(SimResults[s:e, 3])
 points(r~c(1:Gen), type = "l")
 if(histo == "yes"){SimResults[,1] = rep(1:Pop, each = Gen)
 SimResults[,2] = rep(1:Gen, times = Pop)
 hist(SimResults[,3][SimResults[,2]==Gen], xlim = c(0,1), cex.main = 1, main = bquote('N'[M]~'/ N'[F]~'='~.(SR)*', N'[A]~'='~.(Na)*', N'[E]~'='~.(NE)), xlab = paste0("Frequency of focal allele after ",Gen," Generations"))

Pop = 10
Gen = 25
P = 0.5
histo = "no"

SimResults = matrix(data = NA, ncol = 3, nrow = Gen*Pop)
GenDriftSim(Pop = Pop, Gen = Gen, NM = 100, NF = 900, P = P, histo = histo)
GenDriftSim(Pop = Pop, Gen = Gen, NM = 180, NF = 180, P = P, histo = "histo")

Postdoctoral Position

I am now a postdoctoral researcher on natural selection in contemporary human populations at Turku University in Virpi Lummaa’s research group! Virpi’s group studies life history evolution in Humans and Elephants using demographic data. I am really excited to be joining the group as they move from Sheffield to Turku, and look forward to trying my hand at quantitative genetics with pedigree data! News on projects will come soon.



Göteborg University Talk

I gave a presentation at Göteborg University Department of Zoology today, titled The Evolution of Sexual Dimorphism: Quantitative Genetic Explorations of the Drosophila Genome, which was based on my PhD work at Uppsala University. It was really good to try presenting the complex elements of my work to a diverse research department, explaining the concept of adaptation and constraint in multivariate space over just 45 minutes is quite a challenge!

I will be back to the department on Monday to discuss collaboration. Thanks to Lotta Kvarnemo and the Department of Zoology for inviting me to speak today and the good discussion that followed.


PhD Defence

On September 18th 2015 I successfully defended my PhD thesis, The Genetic Architecture of Sexual Dimorphism, at Uppsala University. This brings an end to just over 4 years of work, in which I have shown that the shared genome constrains the evolution of sexual dimorphism and that the sex chromosomes appear to play a special role in resolving intralocus sexual conflict, by being enriched for sex-specific genetic variance. Thanks to my opponent, Russell Bonduriansky (University of New South Wales), and my committee, Jenny Hagenblad (Linköping University), Bengt Hansson (Lund University), and Dirk Jan De Koning (SLU Uppsala), for their excellent contributions to the defence. The thesis resulted in two publications, while two further manuscripts are in preparation. Urban, Holger, and I hope to publish these soon.


ESEB 2015 Presentation

I presented a talk on the evolution of sexual dimorphism: G-matrices across the genome, at the 15th Meeting for the European Society of Evolutionary Biology in Lausanne earlier this week. The research presented was from paper IV of my PhD thesis in collaboration with Holger Schielzeth and Urban Friberg. The presentation was well received and led to several interesting discussions. We hope to submit the related paper to a journal within the next few weeks.


The work uses chromosome insertion lines to estimate the genetic (co)variance on the X and autosomes separately for lifespan, body size, and negative geotaxis (climbing ability) in males and females. These estimates are then constructed in to G-matrices and examined using a number of methods. We show that the X is not depleted for genetic variance, accounting for its size relative to the autosomes, and could allow more rapid evolution of sexual dimorphism despite containing a lesser volume of genetic variance than the autosomes, because of lower covariance between the sexes.

The conference was generally very interesting and there was a number of excellent talks within sexual selection, conflict, and quantitative genetics.

New Paper: Y-linked genetic variation for lifespan

Today we published a new paper in the Journal of Evolutionary Biology which shows that the Y chromosome harbours a small amount of within-population genetic variance for lifespan. We found these results in the DGRP lines of Drosophila melanogaster, taking 34 Y-chromosomes and amplifying them in to a single genetic background. We were able to detect the tiny signal of genetic variance, explaining less than 1% of the variance in lifespan, thanks to a large and powerful experiment. One interesting point was in the statistical approach: we used MCMCGLMM in R to generate a posterior distribution of the genetic variance estimate. We then performed 100 randomisations which maintained experimental structure but randomised the genotype effect, and all estimates of the genetic variance were lower in the randomised data which helps to validate our results! The paper is available on the JEB website.