Population genetics course resources: Hardy-Weinberg Eq.

Using data from the Hapmap to illustrate Hardy Weinberg equilibrium. The code and the data are below.

The original inspiration for these comes from John Novembre, who made a similar plot for one of his classes. I took 10,000 SNPs from the HapMap CEU European and YRI African populations (the 1st 10k from chromosome 1 on the Affy chip as that was what I had handy). Within each of these populations I plot the allele frequency against the frequency of the 3 genotypes. Each SNP is represented by 3 different coloured points. The solid lines show the mean genotype frequency calculated using a loess smoothing. The dashed line shows the predicted genotype frequency from Hardy Weinberg equilibrium. I find it really pretty that the analytical predictions work as well as they do (I’m not sure whether the slight deviation is finite sample effects, should check into that). Obviously these (and most SNPs) pass HW QC metrics, so it isn’t very surprising still I find it nice to know that popgen makes sense.

The data are from the PHASE2 HapMap and the genotypes were processed into genotype counts using PLINK‘s HWE option (the files are in that format).

This slideshow requires JavaScript.

If you do use these scripts and figures, please acknowledge that fact (mainly so that others can find this resource). Also if you do use them it would be great if you could add a comment to the post, so I can see how widely used they are, to get a sense of how worthwhile this is. If you find a bug or make an improved version do let me know. Thanks again to John for the original inspiration for these plots.

The SNP files:
CEU file

YRI file

	#read in the HW file from plink



	plot(ss.allele,ss.geno[,1],xlim=c(0,1),ylim=c(0,1),col=adjustcolor("red",0.1),xlab="allele frequency",ylab="genotype frequency",main=title)
	lines(lowess(ss.geno[,1]~ss.allele,f = smooth),col="black")
	lines(lowess(ss.geno[,3]~ss.allele,f = smooth),col="black")
	lines(lowess(ss.geno[,2]~ss.allele,f = smooth),col="black")

	legend(x=0.3,y=1,col=c("red","blue","green",rep("black",2)),legend=c("Homozygote AA","Homozygote aa","Heterozygote Aa","Mean","Hardy Weinberg Expectation"),pch=c(rep(1,3),rep(NA,2)),lty=c(rep(NA,3),1,2))
plot.geno.vs.HW(file="YRI_10000.hw.gz",title="HapMap YRI (Africans)")

plot.geno.vs.HW(file="CEU_10000.hw.gz",title="HapMap CEU (Europeans)")

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

This entry was posted in popgen teaching, Programming exercises, teaching. Bookmark the permalink.

14 Responses to Population genetics course resources: Hardy-Weinberg Eq.

  1. cooplab says:

    Thanks to Nathan Pearson for spotting the mis-lengended plot. Corrected.

  2. Don C says:

    Thanks graham – these are going into my class slides for tomorrow!

  3. Pingback: Population genetics course resources: F statistics | gcbias

  4. Bob says:

    This is great, Graham. I’m putting it in tomorrow’s lecture.

  5. Jeremy B says:

    Got a chance to use these on AskScience:


    not sure if I helped all that much, but I tried.

  6. cooplab says:

    Jeremy answers another question about HWE at “ask science” using in part this material: http://www.reddit.com/r/askscience/comments/194y1f/why_do_we_use_the_hardy_weinberg_equilibrium_if/

  7. Pingback: Hardy-Weinberg and Ask Science | gcbias

  8. Nadia S. says:

    This is terrific, Graham! I used these HWE figures in my lecture on human population genetics a few weeks ago. So helpful! Also, my students just took their final exam and one of the extra credit questions was ‘what is the most interesting thing you’ve learned in the course?” A solid 1/3 of the class said that these plots were their favorite thing. One student even said it blew her mind!! I guess I’ll be using them every year!!

  9. Justin Blumenstiel says:

    Hi Graham, using this in Genetics this semester! Really psyched to provide a cool intro to R this way!

  10. Pauline Garnier-Géré says:

    Thank you very much for the great resources and examples, using it for a populations genetics course and practical for students this fall!

  11. Paul Jenkins says:

    Just found these. I will be using them – thanks!

  12. Graham, I’m using the PDF version you emailed me after your KU visit, but wanted to let you know that I’ve added them to my pop gen handout, with a link to this page so the students can go explore on their own if they like. Thanks!

Leave a Reply to Paul Jenkins Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s