library(httr)
library(jsonlite)
library(xml2)
library(TwoSampleMR)
exposure <- extract_instruments(outcomes = 'ebi-a-GCST90007527')
write.table(exposure,'/Users/zhangzhishuai/Desktop/路易性痴呆/RRandF/ebi-a-GCST90007527.txt', sep = "\t", quote = FALSE)
# 读取输入文件
data <- read.table("/Users/zhangzhishuai/Desktop/路易性痴呆/RRandF/ebi-a-GCST90007527.txt", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
# 提取SNP信息
for (snp_id in unique(data$SNP)){
ext <- paste0("/variation/human/", snp_id, "?pops=1")
res <- GET(paste(server, ext, sep = ""), content_type("application/json"))
stop_for_status(res)
res <- httr::content(res)
res <- jsonlite::fromJSON(toJSON(res))$populations
# 提取带有effect_allele.exposure的行
res_eur <- subset(res, grepl(data$effect_allele.exposure[data$SNP == snp_id], allele))
# 添加SNP ID到输出结果
cat("SNP ID: ", snp_id, "\n")
res_eur <- subset(res, grepl("EUR", population))
print(res_eur)
}
基于gwas数据提取maf
最新推荐文章于 2024-06-13 14:34:19 发布