From f24f59c93c54ecce1e3d28554476b46966330252 Mon Sep 17 00:00:00 2001 From: junikimm717 Date: Mon, 19 Jul 2021 23:20:39 -0400 Subject: [PATCH] added verbose output --- README.md | 7 ++++++- src/script.def.R | 33 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a6db25c..0ab1911 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,17 @@ choosing (preferably halogenated compounds). ## Installation The script has the following dependencies: -- latest version of the [Nontarget R Package](https://github.com/blosloos/nontarget) (This should be installed through the devtools package) +- latest version of the [Nontarget R Package](https://github.com/blosloos/nontarget) +(This should be installed +through the devtools package) - [purrr](https://www.rdocumentation.org/packages/purrr/versions/0.2.5) - [enviPat](https://rdocumentation.org/packages/enviPat/versions/2.2) - [stringr](https://www.rdocumentation.org/packages/stringr/versions/1.4.0) - [parallel](https://www.rdocumentation.org/packages/parallel/versions/3.6.2) +Before running/configuring the script, call `make` while in the `/src` +directory or copy `script.def.R` to `script.R`. + ## Additional Notes In order to make the search run in linear time, as of right now, the entire diff --git a/src/script.def.R b/src/script.def.R index f4e0555..220ba3e 100644 --- a/src/script.def.R +++ b/src/script.def.R @@ -31,8 +31,9 @@ columns.spectra <- "Spectra_Number" output.intensities <- 5 # Verbose output -verbose.enable <- TRUE -verbose.outputdir <- "/output/dir" +verbose.enable <- FALSE +# output directory must already exist. +verbose.outputdir <- "/path/to/directory" # Script ##################################################################### @@ -150,6 +151,14 @@ derive.frame <- function(result) { return(res) } +verbose.dump <- function(result) { + path <- file.path(verbose.outputdir, paste(derive.fragment(result), ".txt", + sep="")) + sink(path) + dput(result) + sink() +} + # Execution ################################################################## ## Set all of the intervals ################################################## @@ -177,14 +186,28 @@ results <- mclapply(use, diagnostics, mc.cores=use_cores) results.positive <- Filter(function(x) positive(x), results) +# print to files if verbose output requested + +if (verbose.enable) { + if (!dir.exists(verbose.outputdir)) { + stop(str_interp("Directory $[s]{dir} does not exist", + list(dir=verbose.outputdir))) + } + res <- readline(prompt=paste("Are you sure you want to overwrite files in ", + verbose.outputdir, "? [y/N] ")) + if (res != "y") { + stop("Process aborted.") + } + print(paste("printing output to ", verbose.outputdir)) + mapply(verbose.dump, results.positive) +} + result.frame <- mapply(derive.frame, results.positive) result.fragment <- mapply(derive.fragment, results.positive) result.iso <- mapply(derive.iso, results.positive) result.intensity <- mapply(derive.intensity, results.positive) result.average <- mapply(derive.average, results.positive) -for (x in result.frame) { - print(x) -} +print(result.fragment) ##############################################################################