Skip to content

Instantly share code, notes, and snippets.

@kbroman
Created February 22, 2018 16:38
Show Gist options
  • Save kbroman/a0573e83aa1eb6d626735e3cb5c8ce07 to your computer and use it in GitHub Desktop.
Save kbroman/a0573e83aa1eb6d626735e3cb5c8ce07 to your computer and use it in GitHub Desktop.
# Study genotype frequencies / haplotype reconstructions in Diversity Outbred mice
# Example with the DOex data (https://github.com/rqtl/qtl2data/tree/master/DOex)
# See R/qtl2 discussion: https://groups.google.com/d/msg/rqtl2-disc/cBJ0zSbvid8/pplbQ_zyAwAJ
library(qtl2)
file <- paste0("https://raw.githubusercontent.com/rqtl/",
"qtl2data/master/DOex/DOex.zip")
DOex <- read_cross2(file)
# genoprobs
pr <- calc_genoprob(DOex, error_prob=0.002)
# allele probs
apr <- genoprob_to_alleleprob(pr)
# histograms of allele frequencies across individuals
af_ind <- calc_geno_freq(apr, "individual")
par(mfrow=c(4,2))
for(i in 1:8) hist(af[,i], main=colnames(af)[i], breaks=30)
# plots of allele frequencies across the genome
af_mar <- calc_geno_freq(apr, "marker", omit_x=FALSE)
plot_coefCC(af_mar, DOex$pmap, ylim=c(0, max(af_mar)), ylab="Allele frequency")
# heatmap of genotype probabilities for a single individual on one chromosome
plot_genoprob(pr, DOex$pmap, chr="2", ind=1, threshold=1/8)
# plot of a single individual's inferred genotypes
### first infer genotypes
m <- maxmarg(pr)
### then guess phase (so we can look at the two haplotypes
v <- guess_phase(DOex, m)
### now the plot
plot_onegeno(v, DOex$pmap, ind=1) # a male
plot_onegeno(v, DOex$pmap, ind=53) # a female
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment