有没有帮我看一下这个代码具体是做什么的
construct_database = function(path = ".",
version = "0.0.1",
metabolite.info.name = "metabolite.info.csv",
source = "Michael Snyder Lab",
link = "http://snyderlab.stanford.edu/",
creater = "Xiaotao Shen",
email = "shenxt1990@163.com",
rt = TRUE,
mz.tol = 15,
rt.tol = 30,
threads = 3) {
##check data first
file <- dir(path)
if (all(file != metabolite.info.name)) {
cat(crayon::red("No", metabolite.info.name, "in your", path, "\n"))
return(NULL)
}
if (all(file != "POS")) {
cat(crayon::red("No POS file in your", path, "\n"))
} else{
file_pos <- dir(file.path(path, "POS"))
if (length(file_pos) == 0) {
cat(crayon::red("No mzXML files in POS folder\n"))
} else{
if (sum(stringr::str_detect(file_pos, "mzXML")) == 0) {
cat(crayon::red("No mzXML files in POS folder\n"))
}
}
}
if (all(file != "NEG")) {
cat(crayon::red("No NEG file in your", path, "\n"))
} else{
file_neg <- dir(file.path(path, "NEG"))
if (length(file_neg) == 0) {
cat(crayon::red("No mzXML files in NEG folder\n"))
} else{
if (sum(stringr::str_detect(file_neg, "mzXML")) == 0) {
cat(crayon::red("No mzXML files in NEG folder\n"))
}
}
}
##read metabolite information
cat(crayon::green("Reading metabolite information...\n"))
metabolite.info <-
readTable(file = file.path(path, metabolite.info.name))
cat(crayon::green("Reading positive MS2 data...\n"))
file.pos <-
dir(file.path(path, 'POS'), full.names = TRUE)
if (length(file.pos) > 0) {
ms2.data.pos <-
read_mzxml(file = file.pos, threads = threads)
ms1.info.pos <- lapply(ms2.data.pos, function