## Define the paths to the example datasets we want to deconvolute:
## `sim_dir`: directory containing 16 simulated spectra
## `sim_01`: path to the first spectrum in the `sim` directory
## `sim_01_spec`: the first spectrum in the `sim` directory as a dataframe
sim_dir <- metabodecon_file("sim_subset")
sim_1_dir <- file.path(sim_dir, "sim_01")
sim_2_dir <- file.path(sim_dir, "sim_02")
sim_1_spectrum <- read_spectrum(sim_1_dir)
sim_2_spectrum <- read_spectrum(sim_2_dir)
sim_spectra <- read_spectra(sim_dir)
## Show that `generate_lorentz_curves()` and `generate_lorentz_curves_sim()`
## produce the same results:
sim_1_decon0 <- generate_lorentz_curves(
data_path = sim_1_dir, # Path to directory containing spectra
sfr = c(3.55, 3.35), # Borders of signal free region (SFR) in ppm
wshw = 0, # Half width of water signal (WS) in ppm
ask = FALSE, # Don't ask for user input
verbose = FALSE # Suppress status messages
)
sim_1_decon1 <- generate_lorentz_curves_sim(sim_1_dir)
stopifnot(all.equal(sim_1_decon0, sim_1_decon1))
## Show that passing a spectrum produces the same results as passing the
## the corresponding directory:
decon_from_spectrum_dir <- generate_lorentz_curves_sim(sim_1_dir)
decon_from_spectrum_obj <- generate_lorentz_curves_sim(sim_1_spectrum)
decons_from_spectra_obj <- generate_lorentz_curves_sim(sim_spectra)
decons_from_spectra_dir <- generate_lorentz_curves_sim(sim_dir)
most.equal <- function(x1, x2) {
ignore <- which(names(x1) %in% c("number_of_files", "filename"))
equal <- all.equal(x1[-ignore], x2[-ignore])
invisible(stopifnot(isTRUE(equal)))
}
all.equal( decon_from_spectrum_dir, decon_from_spectrum_obj )
all.equal( decons_from_spectra_dir, decons_from_spectra_obj )
most.equal( decon_from_spectrum_dir, decons_from_spectra_obj[[1]])
most.equal( decon_from_spectrum_dir, decons_from_spectra_dir[[1]])
Run the code above in your browser using DataLab