Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Created April 2, 2021 07:58
Show Gist options
  • Save explodecomputer/370997aaf0fb931f8bc693a9a69644b2 to your computer and use it in GitHub Desktop.
Save explodecomputer/370997aaf0fb931f8bc693a9a69644b2 to your computer and use it in GitHub Desktop.
af_comparison
library(TwoSampleMR)
library(ieugwasr)
library(tidyverse)
# Get harmonised data for exposure and outcome
# e.g. BMI vs CHD
dat <- make_dat(exposures="ieu-a-2", outcomes="ieu-a-7")
# infer the AF for controls only for CHD
# first get case control sizes
dat <- add_metadata(dat)
dat$eaf.outcome.controls <- get_population_allele_frequency(
af = dat$eaf.outcome,
prop = dat$ncase.outcome / (dat$ncase.outcome + dat$ncontrol.outcome),
odds_ratio = exp(dat$beta.outcome),
prevalence = 0.2
)
# This includes the effect allele frequencies
# e.g. we can plot them
plot(dat$eaf.exposure ~ dat$eaf.outcome)
# Look up the allele frequencies for these SNPs in 1000 genomes
ref <- afl2_rsid(dat$SNP)
# Compare allele frequencies of exposure, outcome, and reference populations
dat %>%
select(SNP, eaf.exposure, eaf.outcome.controls) %>%
inner_join(., ref, by=c("SNP"="rsid")) %>%
select(eaf.exposure, eaf.outcome.controls, starts_with("AF.")) %>%
pairs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment