MR分析——剔除与混淆因素相关的SNP

library(TwoSampleMR)

i = “ieu-b-4836”
trait = ‘Years_of_schooling’
remove_snp <- read.table(‘C:/Users/DELL/Desktop/要剔除的SNP.txt’, sep = ‘\t’, header = T)

exposure = extract_instruments(outcomes = i)

outcome <- read_outcome_data(snps = exposureKaTeX parse error: Undefined control sequence: \t at position 84: …8.tsv', sep = '\̲t̲', snp_col = 'S…SNP %in% remove_snp B B [ r e m o v e s n p BB[remove_snp BB[removesnpAAtrait]),] # 剔除SNP
sum(dat$mr_keep
’TRUE’)
a <- generate_odds_ratios(mr_res = mr(dat))
b <- mr_heterogeneity(dat)
c <- mr_pleiotropy_test(dat)
filenamea <- paste0(‘mr_’, i, ‘.txt’)
filenameb <- paste0(‘heter_’, i, ‘.txt’)
filenamec <- paste0(‘pleio_’, i, ‘.txt’)
write.table(a, file = filenamea, quote = F, sep = ‘\t’)
write.table(b, file = filenameb, quote = F, sep = ‘\t’)
write.table(c, file = filenamec, quote = F, sep = ‘\t’)

filename <- paste0(“outfig_”, i, ‘.pdf’)
pdf(file = filename)
a <- mr_scatter_plot(mr_results = mr(dat, method_list = c(“mr_ivw”, “mr_egger_regression”, “mr_weighted_median”)), dat)
b <- mr_funnel_plot(singlesnp_results = mr_singlesnp(dat))
c <- mr_leaveoneout_plot(leaveoneout_results = mr_leaveoneout(dat))
print(a)
print(b)
print©
dev.off()

要剔除的SNP.txt:

AA	BB	CC
Alcoholic_drinks_per_week	rs1260326	3
Alcoholic_drinks_per_week	rs13107325	3
Cholesterol_total	rs112552009	2
Cholesterol_total	rs7412	2
Cigarettes_smoked_per_day	rs56113850	2
Cigarettes_smoked_per_day	rs73229090	2
Fluid_intelligence_score	rs13107325	3
Fluid_intelligence_score	rs7963801	2
Granulocyte_percentage_of_myeloid_white_cells	rs1260326	3
Granulocyte_percentage_of_myeloid_white_cells	rs10732976	2

你可能感兴趣的:(MR,mr)