Skip to content

Commit

Permalink
KEGG API download of pathways and 'Offline' MR BACOn CAD-serum analyses
Browse files Browse the repository at this point in the history
  • Loading branch information
CavinWard committed Dec 7, 2018
1 parent ac4a9c0 commit 503ec62
Show file tree
Hide file tree
Showing 6 changed files with 33,400 additions and 0 deletions.
Binary file added MR BACOn Output 12-5-2018.pptx
Binary file not shown.
2,347 changes: 2,347 additions & 0 deletions Offline/Offline Results/CAD serum metablites MR results single SNP.csv

Large diffs are not rendered by default.

1,037 changes: 1,037 additions & 0 deletions Offline/Offline Results/CAD serum metablites MR results.csv

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Offline/R code/MR serum data offline processing functions v1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#### functions for offline processing

serum_metabolite <- function(metabolite) {
path <- "data/metab_info/"
tissue <- "serum"
path <- paste(path, tissue, "_map.txt", sep = "")
f <- read.delim(path, header = T, stringsAsFactors = F)
met <- f$metid[f$metabolite == metabolite]
return(met)
}
68 changes: 68 additions & 0 deletions Offline/R code/MR serum data offline processing v1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
### offline MR processing for serum

rm(list=ls())

library(devtools)
install_github("MRCIEU/TwoSampleMR")
library(TwoSampleMR)

setwd("C:/Users/cavin/Desktop/MR_BACOn/Offline/R code/")

source("MR serum data offline processing functions v1.R")

path <- "../../ShinyApp/data/mr_data/pre-clumped/serum/"

metab_info <- read.delim("../../ShinyApp/data/metab_info/serum_map.txt", header = T, stringsAsFactors = F)

#### get all the files and names in metab info
mfiles <- list.files("../../ShinyApp/data/mr_data/pre-clumped/serum/")
mnames <- gsub("serum_","",mfiles)
mnames <- gsub("\\.txt","",mnames)

metab_info <- subset(metab_info, metid%in%mnames)

pvalue <- 0.05

out.matrix <- c()
out.single <- c()
for(i in c(1:nrow(metab_info)))
{
print(paste("Doing metab",i,"out of",nrow(metab_info)))
metab <- metab_info$metabolite[i]
mid <- metab_info$metid[i]
f <- mfiles[grep(mid,mfiles)]

expos_data <- read.delim(paste0(path,f), header = T, stringsAsFactors = F)
outcome_read <- tryCatch(read_outcome_data(filename = "../../ShinyApp/data/mr_data/cad_p05.txt", snps = expos_data$SNP, sep = "\t"),error=function(e){return(1)})

if(!is.null(dim(outcome_read)))
{
harmed_data <- harmonise_data(exposure_dat = expos_data, outcome_dat = outcome_read)
### forcing mr_keep to TRUE forces keeping in all SNPs even those which are ambiguous;
### use only if sure about strand alignment, otherwise comment out
harmed_data$mr_keep <- TRUE

mr.result <- mr(harmed_data)
mr.result$outcome <- "CAD"
mr.result$exposure <- metab
mr.result$lci <- mr.result$b - qnorm(0.975,0,1)*mr.result$se
mr.result$uci <- mr.result$b + qnorm(0.975,0,1)*mr.result$se
mr.result <- mr.result[,-which(names(mr.result)%in%c("id.exposure","id.outcome"))]

out.matrix <- rbind(out.matrix, mr.result)

mr.single <- mr_singlesnp(harmed_data)
mr.single$outcome <- "CAD"
mr.single$exposure <- metab
mr.single$lci <- mr.single$b - qnorm(0.975,0,1)*mr.single$se
mr.single$uci <- mr.single$b + qnorm(0.975,0,1)*mr.single$se
mr.single <- mr.single[,-which(names(mr.single)%in%c("id.exposure","id.outcome","samplesize"))]

out.single <- rbind(out.single, mr.single)
}

}

write.table(out.matrix, file="../Offline Results/CAD serum metablites MR results.csv", col.names=TRUE, row.names=FALSE, quote=FALSE, sep=",")
write.table(out.single, file="../Offline Results/CAD serum metablites MR results single SNP.csv", col.names=TRUE, row.names=FALSE, quote=FALSE, sep=",")

Loading

0 comments on commit 503ec62

Please sign in to comment.