This article shows how Metabodecon can be used for deconvoluting and aligning one-dimensional NMR spectra using the pre-installed Sim dataset as an example. The Sim dataset includes 16 simulated spectra, each with 2048 data points ranging from ≈ 3.6 to 3.3 ppm. These simulated spectra closely mimic the resolution and signal strength of real NMR experiments on blood plasma from 16 individuals. The Sim dataset is used instead of the Blood dataset because it is smaller, faster to process, and comes pre-installed with the package. For more information on the Sim and Blood datasets, see Datasets.
Deconvolute spectra
To find the path to the Sim dataset, you can use the
metabodecon_file()
function, which returns the path to any
file or directory within the package directory. To deconvolute the
spectra within the Sim dataset you can use
generate_lorentz_curves()
:
sim_dir <- metabodecon::metabodecon_file("bruker/sim")
deconvoluted_spectra <- metabodecon::generate_lorentz_curves(
data_path = sim_dir, # Path to directory containing spectra
sfr = c(3.35, 3.55), # Borders of signal free region (SFR) in ppm
wshw = 0, # Half width of water signal (WS) in ppm
smopts = c(2, 5), # Configure smoothing parameters
verbose = FALSE # Suppress status messages
)
After calling generate_lorentz_curves()
, the function
will ask you to answer the following questions to determine the optimal
deconvolution parameters:
- Use same parameters for all spectra? (y/n)
- Number of spectrum for adjusting parameters? (1: sim_01, 2: sim_02, …)
- Signal free region correctly selected? (y/n)
- Water artefact fully inside red vertical lines? (y/n)
You can answer questions one and two with y
and
1
, as the dataset is homogeneous, i.e., all spectra were
measured in the same lab with the same acquisition and processing
parameters. However, for heterogeneous datasets, it’s advisable to
optimize parameters for each batch of spectra individually.
Questions three and four are accompanied by two plots, shown in Figure 1, which help you to verify the
accuracy of the selected signal-free region (SFR) and water signal
half-width (WSHW) 1. In this case, the provided parameters are
already fine, so you can answer both questions with y
. If
adjustments are needed, you can respond with n
and input
the correct values.
When using the function in scripts, where interactive user input is
not desired, you can disable the interactive prompting by setting
parameter ask
to FALSE
. In this case, the
provided parameters will be used for the deconvolution of all spectra
automatically. 2
Visualize deconvoluted spectra
After completing the deconvolution, it is advisable to visualize the
extracted signals using plot_spectrum()
to assess the
quality of the deconvolution:
# Visualize the first spectrum only
metabodecon::plot_spectrum(deconvoluted_spectra[[1]])
# Visualize all spectra and save them to a pdf file
pdfpath <- tempfile(fileext = ".pdf")
pdf(pdfpath, width = 12, height = 8)
for (i in seq_along(deconvoluted_spectra)) {
metabodecon::plot_spectrum(
x = deconvoluted_spectra[[i]],
main = deconvoluted_spectra[[i]]$filename,
foc_frac = c(0.25, 0.75)
)
}
dev.off()
cat("Plots saved to", pdfpath, "\n")
Out of the 16 generated plots, the first two are shown as examples in Figure 2. Things to look out for are:
- That the smoothing does not remove any real signals. If the
smoothing is too strong, i.e., the smoothed signal intensity (SI) is
very different from the raw SI, you should adjust the smoothing
parameters
smopts
in the call togenerate_lorentz_curves()
. - That the superposition of the lorentz curves is a good approximation
of the smoothed SI. If major peaks are missed by the algorithm, you
should reduce the threshold
delta
in the call togenerate_lorentz_curves()
.
Align deconvoluted spectra
The last step in the Metabodecon Workflow is to align the deconvoluted spectra. This is necessary because the chemical shifts of the peaks in the spectra may vary slightly due to differences in the measurement conditions.
To visualize the data before and after the alignment, you can use
plot_spectra()
. To do the alignment, you can use
align()
:
metabodecon::plot_spectra(deconvoluted_spectra)
aligned_spectra <- metabodecon::align(deconvoluted_spectra, maxCombine = 1)
metabodecon::plot_spectra(aligned_spectra)
The resulting plots are shown in Figure 3