Last active
July 2, 2020 13:49
-
-
Save explodecomputer/c7a29392e61bdae00f2adb1dc1130e97 to your computer and use it in GitHub Desktop.
mr-a-b
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(dplyr) | |
library(data.table) | |
library(TwoSampleMR) | |
bmi_id <- "ukb-b-19953" | |
chd_id <- "ukb-b-3983" | |
datadir <- "/mnt/storage/private/mrcieu/research/mr-eve/UKBB_replication/replication/results" | |
bmiA <- fread(file.path(datadir, bmi_id, "discovery.statsfile.txt.gz"), header=TRUE) | |
bmiB <- fread(file.path(datadir, bmi_id, "replication.statsfile.txt.gz"), header=TRUE) | |
chdA <- fread(file.path(datadir, chd_id, "discovery.statsfile.txt.gz"), header=TRUE) | |
chdB <- fread(file.path(datadir, chd_id, "replication.statsfile.txt.gz"), header=TRUE) | |
cor(bmiA$BP, bmiB$BP) | |
cor(bmiA$BETA, bmiB$BETA) | |
igddir <- "/mnt/storage/private/mrcieu/research/scratch/IGD" | |
bmi_clumped <- scan(file.path(igddir, "data", "public", bmi_id, "clump.txt"), what="character") | |
instrumentsA <- subset(bmiA, P_BOLT_LMM_INF < 5e-8 & SNP %in% bmi_clumped) | |
instrumentsB <- subset(bmiB, P_BOLT_LMM_INF < 5e-8 & SNP %in% bmi_clumped) | |
table(instrumentsA$SNP %in% instrumentsB$SNP) | |
table(instrumentsB$SNP %in% instrumentsA$SNP) | |
instrumentsA_rep <- subset(bmiB, SNP %in% instrumentsA$SNP) | |
instrumentsB_rep <- subset(bmiA, SNP %in% instrumentsB$SNP) | |
outcomeB_A <- subset(chdB, SNP %in% instrumentsA$SNP) | |
outcomeB_B <- subset(chdB, SNP %in% instrumentsB$SNP) | |
outcomeA_A <- subset(chdA, SNP %in% instrumentsA$SNP) | |
outcomeA_B <- subset(chdA, SNP %in% instrumentsB$SNP) | |
all(instrumentsA_rep$SNP == outcomeB_A$SNP) | |
all(instrumentsA_rep$ALLELE1 == outcomeB_A$ALLELE1) | |
all(instrumentsA_rep$SNP == outcomeB_A$SNP) | |
all(instrumentsA_rep$ALLELE1 == outcomeB_A$ALLELE1) | |
l <- list() | |
what="exposure_discovery A, exposure_replication B, outcome B" | |
dat <- merge(instrumentsA_rep, outcomeB_A, by="SNP") | |
l[[1]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
what <- "exposure_discovery A, outcome A" | |
dat <- merge(instrumentsA, outcomeB_A, by="SNP") | |
l[[2]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
what <- "exposure_discovery B, exposure_replication A, outcome A" | |
dat <- merge(instrumentsB_rep, outcomeA_B, by="SNP") | |
l[[3]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
what <- "exposure_discovery B, outcome B" | |
dat <- merge(instrumentsB, outcomeB_B, by="SNP") | |
l[[4]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
what <- "exposure_discovery B, outcome B" | |
dat <- merge(instrumentsB, outcomeA_B, by="SNP") | |
l[[5]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
what <- "bmi instrument replication B" | |
dat <- merge(instrumentsB, instrumentsB_rep, by="SNP") | |
l[[6]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
what <- "bmi instrument replication A" | |
dat <- merge(instrumentsA, instrumentsA_rep, by="SNP") | |
l[[7]] <- mr_ivw( | |
b_exp=dat$BETA.x, | |
b_out=dat$BETA.y, | |
se_exp=dat$SE.x, | |
se_out=dat$SE.y) %>% | |
as.data.frame %>% mutate(what=what) | |
res <- bind_rows(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment