dxy logo
首页丁香园病例库全部版块
搜索
登录

肠道菌群孟德尔随机化代码

发布于 2023-09-04 · 浏览 2595 · IP 甘肃甘肃
这个帖子发布于 1 年零 249 天前,其中的信息可能已发生改变或有所发展。


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在线数据,根据个人需要更改即可

————————————————

版权声明:本文为CSDN博主「tuntun16」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/tuntun16/article/details/130547267

最后编辑于 2023-09-04 · 浏览 2595

2 3 1

全部讨论0

默认最新
avatar
2
分享帖子
share-weibo分享到微博
share-weibo分享到微信
认证
返回顶部