写在前面:在执行本地数据进行分析的时候,均需要按照标准数据准备流程进行预处理,参考:MR标准格式 例如此处用到的本地暴露和本地结局,用以下代码完成标准准备:

# 1.数据下载
# IEU数据下载:https://gwas.mrcieu.ac.uk/files/ieu-a-300/ieu-a-300.vcf.gz
# IEU数据下载:https://gwas.mrcieu.ac.uk/files/ieu-a-301/ieu-a-301.vcf.gz
# IEU数据下载:https://gwas.mrcieu.ac.uk/files/ieu-a-302/ieu-a-302.vcf.gz
# IEU数据下载:https://gwas.mrcieu.ac.uk/files/ieu-a-7/ieu-a-7.vcf.gz
# IEU数据下载:https://gwas.mrcieu.ac.uk/files/ieu-a-8/ieu-a-8.vcf.gz
# bfile数据下载: http://fileserve.mrcieu.ac.uk/ld/1kg.v3.tgz

# 2.预处理本地数据
prepare_ieu(file_path = "ieu-a-300.vcf.gz",out_path="./")
prepare_ieu(file_path = "ieu-a-301.vcf.gz",out_path="./")
prepare_ieu(file_path = "ieu-a-302.vcf.gz",out_path="./")
prepare_ieu(file_path = "ieu-a-7.vcf.gz",out_path="./")
prepare_ieu(file_path = "ieu-a-8.vcf.gz",out_path="./")

1. 基础MR

1.1 在线暴露-在线结局

# 1. 提取IEU线上暴露数据
exposure_online <- mr_extract_exposure_online_mv(
  ieu_exp_id = c("ieu-a-300","ieu-a-301")
)

# 2. 提取ieu线上结局数据
outcome_online <- mr_extract_outcome_online(
  snps = exposure_online$SNP,
  ieu_out_id = c("ieu-a-7","ieu-a-8")
)

# 3. 线上暴露-线上结局MR分析
mr_analysis_mv(
    exposure = exposure_online,
    outcome = outcome_online
)

1.2 本地暴露-本地结局

# bfile数据下载: http://fileserve.mrcieu.ac.uk/ld/1kg.v3.tgz
# 1.提取本地暴露数据
exposure_local <- mr_extract_exposure_local_mv(
  local_exp_path = c("./ieu-a-300.txt","./ieu-a-301.txt"),
  bfile = "./1kg.v3/EUR"
)

# 2. 提取本地结局数据
outcome_local <- mr_extract_outcome_local(
  snps=exposure_local$SNP,
  local_out_path = c("./ieu-a-7.txt","./ieu-a-8.txt"),
  bfile = "./1kg.v3/EUR"
)

# 3. 本地暴露-本地结局MR分析
mr_analysis_mv(
    exposure = exposure_local,
    outcome = outcome_local
)

1.3 本地暴露-在线结局

# bfile数据下载: http://fileserve.mrcieu.ac.uk/ld/1kg.v3.tgz
# 1.提取本地暴露数据
exposure_local <- mr_extract_exposure_local_mv(
  local_exp_path = c("./ieu-a-300.txt","./ieu-a-301.txt"),
  bfile = "./1kg.v3/EUR"
)

# 2. 提取ieu线上结局数据
outcome_online <- mr_extract_outcome_online(
  snps =exposure_local$SNP,
  ieu_out_id = c("ieu-a-7","ieu-a-8")
)


# 3. 线上暴露-本地结局MR分析
mr_analysis_mv(
    exposure = exposure_local,
    outcome = outcome_online
)

1.4 在线暴露-本地结局

# 1. 提取IEU线上暴露数据
exposure_online <- mr_extract_exposure_online_mv(
  ieu_exp_id = c("ieu-a-300","ieu-a-301")
)

# 2. 提取本地结局数据
outcome_local <- mr_extract_outcome_local(
  snps=exposure_online$SNP,
  local_out_path = c("./ieu-a-7.txt","./ieu-a-8.txt"),
  bfile = "./1kg.v3/EUR"
)

# 3. 在线暴露-本地结局MR分析
mr_analysis_mv(
    exposure = exposure_online,
    outcome = outcome_local
)

2. 一键MR

2.1 在线暴露-在线结局

# 加载包
library(DrugTargetMR)

mr_online_multiple(
  ieu_exp_id =c("ieu-a-299","ieu-a-300", "ieu-a-302"),
    ieu_out_id = c("ieu-a-7")
)

2.2 本地暴露-本地结局

# 加载包
library(DrugTargetMR)

# 调用函数 
mr_local_multiple(
  local_exp_path=c("./data_prepare/ieu-a-299.txt",
                   "./data_prepare/ieu-a-300.txt",
                   "./data_prepare/ieu-a-302.txt"),
  local_out_path = "./data_prepare/ieu-a-7.txt",
  # 指定bfile文件,需要解压之后的文件
  bfile ="./data/1kg.v3/EUR",
  out_path = "./result"
)

3. 分析结果

mr分析过程中得到的三个文件,可直接作为投稿文章的附表。

  • table_s1_harmonise_data(多因素MR分析工具变量).csv
  • table_s2_mr_results(basical多因素MR分析).csv
  • table_s2_mr_results(ivw多因素MR分析).csv