R语言实现快速去除孟德尔随机化研究中的混杂因素(1)

发布时间:2023年12月25日
# Remove confounding factors
# Basic analysis for MR
library(TwoSampleMR)
library(phenoscanner)
# Exposure data:aspirin----ukb-b-8755
aaa<- extract_instruments(outcomes='ukb-b-8755',
                          clump=TRUE, 
                          r2=0.001,kb=10000,access_token=NULL)
# Using Phenoscanner to retrieve other traits related to IV
pcf<-function(ex,cf){
  ot<-ex$SNP
  outTab=data.frame()
  for(i in 1:length(ot)){
    #Extract confounders
    confounder=phenoscanner(
      snpquery = ot[i],
      catalogue = "GWAS",
      pvalue = 1e-05, #p-value for screening
      proxies = "None",
      r2 = 0.8, #r2 for screening
      build = 37)#the genome build (options: 37, 38).
    outTab=rbind(outTab, confounder$results)
  }
  # Load the important confounding factors
  patterns <- paste(cf, collapse = "|") 
  pp<-grep(patterns,outTab$trait, ignore.case = TRUE)
  cfs<-outTab[outTab$trait %in% outTab$trait[pp],]
  abc<-ex[!(ex$SNP %in% cfs$snp),]
  return(abc)
}
asd<-pcf(ex=aaa,cf=c("alcohol","Whole body fat mass"))

直接调用pcf函数即可快速去除混杂因素。ex为提取的暴露信息,cf为混杂因素名称。

文章来源:https://blog.csdn.net/weixin_49320263/article/details/135209154
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。