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

setwd("D:/R/MR")
library(TwoSampleMR)
#-----导入菌群的数据
all_gut <- read.table('MBG.allHits.p1e4.txt',header = T)
all_gut <- subset(all_gut,P.weightedSumZ<1e-05) #过滤一
write.csv(all_gut,"exposure_all_gut.csv")
#-----读取exposure
exposure_data <- read_exposure_data(filename = "exposure_all_gut.csv", sep = ",", snp_col = "rsID",
                                    beta_col = "beta", se_col = "SE", phenotype_col = "bac",
                                    effect_allele_col = "eff.allele", other_allele_col = "ref.allele",
                                    chr_col = "chr", pos_col = "bp", clump = FALSE)
#clump这一步需要联网
exposure_data <- clump_data(exposure_data, clump_r2 = 0.001, pop = "EUR", clump_kb = 10000) #过滤二
write.csv(exposure_data,"exposure_all_gut_clumped.csv")
#-----读取outcome_data
outcome_data <- read_outcome_data(filename = "outcome_eur_rsid_reformatted_new.csv",
                                  snps = exposure_data$SNP, snp_col = "SNP",sep = ",",beta_col = "BETA",
                                  se_col = "SE",effect_allele_col = "A1",other_allele_col = "A2",
                                  pval_col = "p",eaf_col = "FRQ",chr_col = "CHR",pos_col = "BP")
#-----预处理数据
dat <- harmonise_data(exposure_data,outcome_data)
write.csv(dat,"dat_harmonised_gut_NC.csv")
#-----自选方法进行MR分析
res <- mr(dat,method_list = c("mr_ivw","mr_two_sample_ml","mr_egger_regression","mr_weighted_median","mr_weighted_mode"))
head(res)

不需要使用for循环,

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

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

  • 15
    点赞
  • 60
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值