1. 安装孟德尔随机化分析相应的R包
# 方法一 ---------------------------------------------------------------------
if (!requireNamespace("remotes", quietly = TRUE))install.packages("remotes")
if (!requireNamespace("TwoSampleMR", quietly = TRUE))remotes::install_github("MRCIEU/TwoSampleMR")
library(TwoSampleMR)
# 方法二 ---------------------------------------------------------------------
if (!requireNamespace("devtools", quietly = TRUE))install.packages("devtools")
if (!requireNamespace("TwoSampleMR", quietly = TRUE))devtools::install_github("MRCIEU/TwoSampleMR")
library(TwoSampleMR)
2. 概述:
孟德尔随机化流程如下:
- 选择暴露的工具变量(筛选显著的SNP[P < 5e-8],并进行LD clumping分析,【计算F统计值】)
- 从IEU GWAS数据库或本地结局GWAS数据中提取相应的工具变量
- 校正Exposure-SNP及Outcome-SNP等位基因方向
- 进行MR分析,敏感性分析,绘制图表,汇编报告。
3. 示例:
一个以BMI为暴露,冠心病为结局的基本孟德尔随机化分析:
#设置路径
setwd("D:/mylesson/孟德尔随机化/3.孟德尔随机化之Introduction/result")
#加载包
library(TwoSampleMR)
# List available GWASs
ao <- available_outcomes()
# Get instruments
exposure_dat <- extract_instruments("ieu-a-2")
# Get effects of instruments on outcome
outcome_dat <- extract_outcome_data(snps=exposure_dat$SNP, outcomes = "ieu-a-7")
# Harmonise the exposure and outcome data
dat <- harmonise_data(exposure_dat, outcome_dat)
# Perform MR
res <- mr(dat)
#生成汇总结果
mr_report(
dat,
output_path = ".",
output_type = "html",
author = "Analyst",
study = "Two Sample MR",
path = system.file("reports", package = "TwoSampleMR")
)