当前位置:   article > 正文

孟德尔随机化丨使用Twosample自带循环处理肠道菌群_肠道菌群孟德尔随机化代码

肠道菌群孟德尔随机化代码
  1. setwd("D:/R/MR")
  2. library(TwoSampleMR)
  3. #-----导入菌群的数据
  4. all_gut <- read.table('MBG.allHits.p1e4.txt',header = T)
  5. all_gut <- subset(all_gut,P.weightedSumZ<1e-05) #过滤一
  6. write.csv(all_gut,"exposure_all_gut.csv")
  7. #-----读取exposure
  8. exposure_data <- read_exposure_data(filename = "exposure_all_gut.csv", sep = ",", snp_col = "rsID",
  9. beta_col = "beta", se_col = "SE", phenotype_col = "bac",
  10. effect_allele_col = "eff.allele", other_allele_col = "ref.allele",
  11. chr_col = "chr", pos_col = "bp", clump = FALSE)
  12. #clump这一步需要联网
  13. exposure_data <- clump_data(exposure_data, clump_r2 = 0.001, pop = "EUR", clump_kb = 10000) #过滤二
  14. write.csv(exposure_data,"exposure_all_gut_clumped.csv")
  15. #-----读取outcome_data
  16. outcome_data <- read_outcome_data(filename = "outcome_eur_rsid_reformatted_new.csv",
  17. snps = exposure_data$SNP, snp_col = "SNP",sep = ",",beta_col = "BETA",
  18. se_col = "SE",effect_allele_col = "A1",other_allele_col = "A2",
  19. pval_col = "p",eaf_col = "FRQ",chr_col = "CHR",pos_col = "BP")
  20. #-----预处理数据
  21. dat <- harmonise_data(exposure_data,outcome_data)
  22. write.csv(dat,"dat_harmonised_gut_NC.csv")
  23. #-----自选方法进行MR分析
  24. res <- mr(dat,method_list = c("mr_ivw","mr_two_sample_ml","mr_egger_regression","mr_weighted_median","mr_weighted_mode"))
  25. head(res)

不需要使用for循环,

TwosampleMR会根据“phenotype_col=”转化而成的“id.exposure"进行循环.

这里使用的outcome是本地导入,当然也可以用ieu在线数据,根据个人需要更改即可

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/573991
推荐阅读
相关标签
  

闽ICP备14008679号