PATH<-"D:\\Mendelian Randomization"
setwd(PATH)
library(ggplot2)
library(plyr)
library(data.table)
library(devtools)
library(MendelianRandomization)
library(TwoSampleMR)
EXP<-data.table::fread("D:/Mendelian Randomization/alopecia/AGA/finngen_R9_L12_ALOPECANDRO.gz")
EXP1<-data.frame(EXP)
head(EXP1)
colnames(EXP1)[c(4,3,5,7,9,10,11)]<-c("effect_allele.exposure","other_allele.exposure","SNP","pval.exposure","beta.exposure","se.exposure","eaf.exposure")
EXP1$id.exposure<-"AGA"
EXP1$exposure<-"AGA"
EXP1$samplesize.exposure<-201214
head(EXP1,6)
EXP1_IV<-subset(EXP1,pval.exposure<5e-05)
EXP1_IV<-clump_data(EXP1_IV,clump_kb = 10000,clump_r2 = 0.001,pop = "EUR")
OUT1<-extract_outcome_data(snps=EXP1_IV$SNP,outcomes = "ukb-b-19732*",proxies = T,maf_threshold = 0.01,access_token = NULL)
OUT1<-OUT1[!duplicated(OUT1$SNP),]
OUT1$id.outcome<-"Hypothyroidism"
OUT1$outcome<-"Hypothyroidism"
head(OUT1)
data_h<-harmonise_data(exposure_dat = EXP1_IV,outcome_dat = OUT1,action = 2)
library(phenoscanner)
dim(data_h)[1]
PhenoScan=phenoscanner(snpquery = data_h$SNP[1:25],pvalue = 5e-08)
write.csv(PhenoScan$results,file="PhenoScan.csv")
write.table(data_h$SNP,"SNP.txt",quote = F,row.names = F)
SNP<-read.table("SNP.txt",header = T)
data_h_SNP<-merge(SNP,data_h,by="SNP",all=F)
data_h_SNP_steiger<-steiger_filtering(data_h_SNP)
data_h_SNP_steiger<-subset(data_h_SNP_steiger,steiger_dir==TRUE)
data_h_SNP_steiger<-data_h_SNP_steiger[!duplicated(data_h_SNP_steiger$SNP),]
这一步结束后应该是25个工具变量
mr<-mr(data_h_SNP_steiger)
但这一步实际进行的确是23个工具变量,这到底是什么原因呢?