Created
April 2, 2021 07:58
-
-
Save explodecomputer/370997aaf0fb931f8bc693a9a69644b2 to your computer and use it in GitHub Desktop.
af_comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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