孟德尔随机化结果不一致,编辑要求使用 LCV, cause, MR-presso这些方法来验证,有没有IEU常规在线分析代码加上这三种分析的代码
我的代码如下,能不能帮忙改一下
#多暴露因素对应一个结局
# 安装所需的包(如果尚未安装)
# install.packages("remotes")
# remotes::install_github("MRCIEU/TwoSampleMR")
# 载入 TwoSampleMR 包
library(TwoSampleMR)
# 设置多个暴露因子和结果的数据ID
exposureIDs <- c("ieu-a-1185") # 暴露因子数据ID
outcomeID <- "ieu-a-1185" # 结果数据ID
# 设置工作目录
setwd("E:\\zhuomian\\Nitrogen dioxide air pollution\\多暴露因素对1疾病\\01多暴露因素对一个疾病(结果)联系")
# 创建一个空的数据框,用于存储所有结果
finalResults <- data.frame()
# 循环处理每个暴露因子
for (exposureID in exposureIDs) {
# 提取暴露因子数据 p1数值可调整
exposure_dat <- extract_instruments(exposureID, p1 = 1e-6, clump = TRUE)
# 提取结果数据
outcome_dat <- extract_outcome_data(snps = exposure_dat$SNP, outcomes = outcomeID)
# 将暴露因子数据和结果数据进行协调
dat <- harmonise_data(exposure_dat, outcome_dat)
# 提取需要保留的数据用于后续分析
outTab <- dat[dat$mr_keep == "TRUE", ]
write.csv(outTab, file = paste0("table.SNP_", exposureID, ".csv"), row.names = FALSE)
# 进行 MR 分析
mrResult <- mr(dat)
# 选择特定的 MR 方法进行分析
# 可以根据需要进行选择,以下为几种可选方法
# mr_method_list()$obj
mrResult <- mr(dat, method_list = c("mr_ivw", "mr_egger_regression", "mr_weighted_median", "mr_simple_mode", "mr_weighted_mode"))
# 生成 Odds Ratios(OR)的表格
mrTab <- generate_odds_ratios(mrResult)
write.csv(mrTab, file = paste0("table.MRresult_", exposureID, ".csv"), row.names = FALSE)
# 进行异质性检验
heterTab <- mr_heterogeneity(dat)
write.csv(heterTab, file = paste0("table.heterogeneity_", exposureID, ".csv"), row.names = FALSE)
# 进行多重性检验
pleioTab <- mr_pleiotropy_test(dat)
write.csv(pleioTab, file = paste0("table.pleiotropy_", exposureID, ".csv"), row.names = FALSE)
# 将每次循环中生成的结果追加到总的结果数据框
finalResults <- rbind(finalResults, cbind(exposureID = exposureID, mrTab))
}
# 将 dev.off() 移到循环外部
dev.off()
# 将最终的结果写入一个总的CSV文件
write.csv(finalResults, file = "finalResults.csv", row.names = FALSE)
和这个
# 安装所需的包(如果尚未安装)
# install.packages("remotes")
# remotes::install_github("MRCIEU/TwoSampleMR")
# 载入 TwoSampleMR 包
library(TwoSampleMR)
# 设置暴露因子和结果的数据ID
exposureID = "ieu-a-1185" # 暴露因子数据ID
outcomeID = "ieu-a-1185" # 结果数据ID
# 设置工作目录
setwd("E:\\zhuomian\\Nitrogen dioxide air pollution\\多暴露因素对1疾病\\02对有意义的进行可视化")
# 提取暴露因子数据 p1数值可调整
exposure_dat <- extract_instruments(exposureID, p1 = 1e-6, clump = TRUE)
# 提取结果数据
outcome_dat <- extract_outcome_data(snps = exposure_dat$SNP, outcomes = outcomeID)
# 将暴露因子数据和结果数据进行协调
dat <- harmonise_data(exposure_dat, outcome_dat)
# 提取需要保留的数据用于后续分析
outTab = dat[dat$mr_keep == "TRUE", ]
write.csv(outTab, file = "table.SNP.csv", row.names = FALSE)
# 进行 MR 分析
mrResult = mr(dat)
# 选择特定的 MR 方法进行分析
# 可以根据需要进行选择,以下为几种可选方法
# mr_method_list()$obj
mrResult = mr(dat, method_list = c("mr_ivw", "mr_egger_regression", "mr_weighted_median", "mr_simple_mode", "mr_weighted_mode"))
# 生成 Odds Ratios(OR)的表格
mrTab = generate_odds_ratios(mrResult)
write.csv(mrTab, file = "table.MRresult.csv", row.names = FALSE)
# 进行异质性检验
heterTab = mr_heterogeneity(dat)
write.csv(heterTab, file = "table.heterogeneity.csv", row.names = FALSE)
# 进行多重性检验
pleioTab = mr_pleiotropy_test(dat)
write.csv(pleioTab, file = "table.pleiotropy.csv", row.names = FALSE)
# 生成散点图
pdf(file = "pic.scatter_plot.pdf", width = 7.5, height = 7)
mr_scatter_plot(mrResult, dat)
dev.off()
# 生成森林图
res_single = mr_singlesnp(dat)
pdf(file = "pic.forest.pdf", width = 7, height = 9)
mr_forest_plot(res_single)
dev.off()
# 生成漏斗图
pdf(file = "pic.funnel_plot.pdf", width = 7, height = 9)
mr_funnel_plot(singlesnp_results = res_single)
dev.off()
# 生成留一图
pdf(file = "pic.leaveoneout.pdf", width = 7, height = 9)
mr_leaveoneout_plot(leaveoneout_results = mr_leaveoneout(dat))
dev.off()