-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEGG API download of pathways and 'Offline' MR BACOn CAD-serum analyses
- Loading branch information
Showing
6 changed files
with
33,400 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
2,347 changes: 2,347 additions & 0 deletions
2,347
Offline/Offline Results/CAD serum metablites MR results single SNP.csv
Large diffs are not rendered by default.
Oops, something went wrong.
1,037 changes: 1,037 additions & 0 deletions
1,037
Offline/Offline Results/CAD serum metablites MR results.csv
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Offline/R code/MR serum data offline processing functions v1.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=",") | ||
|
Oops, something went wrong.