This document provides a brief summary on how to use the PepsNMR package. In this package, pre-processing functions transform raw FID signals from 1H NMR spectroscopy into a set of interpretable spectra.
The PepsNMR
package is available on Bioconductor and can be installed via
BiocManager::install
:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("PepsNMR",
dependencies = c("Depends", "Imports", "Suggests"))
Note tha installing the Suggests
dependencies will
install the PepsNMRData
package to run the demo below.
The package needs to be loaded once installed to be used:
The package development version is available on Github (Master branch): https://github.com/ManonMartin/PepsNMR, although it is highly recommended to rely on the Bioconductor release version of the package to avoid any package version mismatch.
The first step is meant to access the raw data files. To import Free
Induction Decays (FIDs) in Bruker format, use the ReadFids
function. This function will return a list with the FID data matrix
(saved in Fid_data
) and metadata about these FIDs (saved in
Fid_info
).
fidList <- ReadFids(file.path(path,dataset_name))
Fid_data <- fidList[["Fid_data"]]
Fid_info <- fidList[["Fid_info"]]
The possible directory structures are illustrated here:
And is to be linked with the possible options of the
ReadFids
function:
subdirs = TRUE
,
dirs.names = FALSE
subdirs = FALSE
,
dirs.names = FALSE
subdirs = TRUE
, dirs.names = TRUE
subdirs = FALSE
, dirs.names = TRUE
Here is the recommended pre-processing workflow on the FIDs and the spectra once the raw data have been loaded in R:
Steps | Description |
---|---|
Group Delay Correction | Correct for the Bruker Group Delay. |
Solvent Suppression | Remove the solvent signal from the FIDs. |
Apodization | Increase the Signal-to-Noise ratio of the FIDs. |
ZeroFilling | Improve the visual representation of the spectra. |
Fourier Transform | Transform the FIDs into a spectrum and convert the frequency scale (Hz -> ppm). |
Zero Order Phase Correction | Correct for the zero order phase dephasing. |
Internal Referencing | Calibrate the spectra with an internal reference compound. Referencing with an internal (e.g. TMSP at 0 ppm) |
Baseline Correction | Remove the spectral baseline. |
Negative Values Zeroing | Set negatives values to 0. |
Warping | Warp the spectra according to a reference spectrum. |
Window Selection | Select the informative part of the spectrum. |
Bucketing | Data reduction. |
Region Removal | Set a desired spectral region to 0. |
Zone Aggregation | Aggregate a spectral region into a single peak. |
Normalization | Normalize the spectra. |
Information on each function is provided in R, (e.g. type
?ReadFids
in the R console) and methodological details are
found in Martin et al. (2018).
Human serum (HS
) and urine (HU
) datasets
are available as raw data (FIDs in Bruker format) and as (partially)
pre-processed signals/spectra in the ad hoc PepsNMRData
package that is automatically installed with PepsNMR
(through ).
Here are examples of available datasets:
library(PepsNMRData)
str(FidData_HU)
#> cplx [1:24, 1:29411] 0+0i 0+0i 0+0i ...
#> - attr(*, "dimnames")=List of 2
#> ..$ : chr [1:24] "S1-D0-E1" "S1-D0-E2" "S1-D1-E2" "S2-D0-E2" ...
#> ..$ : chr [1:29411] "0" "5.1e-05" "0.000102" "0.000153" ...
str(FinalSpectra_HS)
#> cplx [1:32, 1:500] 0.0769-371030i 0.0466-362686i 0.0639-216899i ...
#> - attr(*, "dimnames")=List of 2
#> ..$ : chr [1:32] "J1-D1-1D-T1" "J3-D2-1D-T8" "J3-D3-1D-T9" "J3-D4-1D-T14" ...
#> ..$ : chr [1:500] "9.98986984692192" "9.97027064485524" "9.95067144278856" "9.93107224072187" ...
Information for each dataset is available, (e.g. enter
?FidData_HS
in the R Console).
Raw Bruker FIDs can be loaded from where PepsNMRData has been intalled:
To import FIDs in Bruker format, the ReadFids
function
is used. This function will return a list with the FID data matrix (here
saved as Fid_data
) and information about these FIDs (here
saved as Fid_info
).
# ==== read the FIDs and their metadata =================
fidList <- ReadFids(file.path(data_path, "HumanSerum"))
Fid_data0 <- fidList[["Fid_data"]]
Fid_info <- fidList[["Fid_info"]]
kable(head(Fid_info))
TD | BYTORDA | DIGMOD | DECIM | DSPFVS | SW_h | SW | O1 | DTYPA | DT | |
---|---|---|---|---|---|---|---|---|---|---|
J1-D1-1D-T1 | 65536 | 1 | 1 | 16 | 12 | 10245.9 | 20.48638 | 2352.222 | 0 | 4.88e-05 |
J3-D2-1D-T8 | 65536 | 1 | 1 | 16 | 12 | 10245.9 | 20.48638 | 2352.222 | 0 | 4.88e-05 |
J3-D3-1D-T9 | 65536 | 1 | 1 | 16 | 12 | 10245.9 | 20.48638 | 2352.222 | 0 | 4.88e-05 |
J3-D4-1D-T14 | 65536 | 1 | 1 | 16 | 12 | 10245.9 | 20.48638 | 2352.222 | 0 | 4.88e-05 |
J4-D1-1D-T4 | 65536 | 1 | 1 | 16 | 12 | 10245.9 | 20.48638 | 2352.222 | 0 | 4.88e-05 |
J4-D2-1D-T7 | 65536 | 1 | 1 | 16 | 12 | 10245.9 | 20.48638 | 2352.222 | 0 | 4.88e-05 |
The Bruker’s digital filter originally produces a Group Delay that is removed during this step.
# ==== GroupDelayCorrection =================
Fid_data.GDC <- GroupDelayCorrection(Fid_data0, Fid_info)
Pre-acquisition techniques for solvent suppression can be
unsufficient to remove the solvent signal from the FIDs.
SolventSuppression
estimates and removes this residual
solvent signal based on a Whittaker smoother.
# ==== SolventSuppression =================
SS.res <- SolventSuppression(Fid_data.GDC, returnSolvent=TRUE)
Fid_data.SS <- SS.res[["Fid_data"]]
SolventRe <- SS.res[["SolventRe"]]
The apodization step increases the spectral Signal-to-Noise ratio by multiplying the FIDs by an appropriate factor (by default a negative exponential).
The zero filling adds 0 to the end of the FIDs to improve the visual representation of spectra.
The Fourier Transform is applied to the FIDs to obtain spectra
expressed in the frequency domain. The FourierTransform
function further converts this frequency scale originally in hertz into
parts per million (ppm).
# ==== FourierTransform =================
RawSpect_data.FT <- FourierTransform(Fid_data.ZF, Fid_info)
After Fourier Transform, the spectra need to be phased for the real part to be in pure absoptive mode (i.e. with positive intensities).
# ==== ZeroOrderPhaseCorrection =================
Spectrum_data.ZOPC <- ZeroOrderPhaseCorrection(RawSpect_data.FT)
# with a graph of the criterion to maximize over 2pi
Spectrum_data.ZOPC <- ZeroOrderPhaseCorrection(RawSpect_data.FT,
plot_rms = "J1-D1-1D-T1")
During this step, the spectra are aligned with an internal reference compound (e.g. with the TMSP). The user determines the ppm value of the reference compound which is by default 0.
# ==== InternalReferencing =================
target.value <- 0
IR.res <- InternalReferencing(Spectrum_data.ZOPC, Fid_info,
ppm.value = target.value,
rowindex_graph = c(1,2))
# draws Peak search zone and location of the 2 first spectra
IR.res$plots
#> [[1]]
The spectral baseline is estimated and removed from the spectral profiles with the Asymetric Least Squares smoothing algorithm.
# ==== BaselineCorrection =================
BC.res <- BaselineCorrection(Spectrum_data.IR, returnBaseline = TRUE,
lambda.bc = 1e8, p.bc = 0.01)
The remaining negative values are set to 0 since they cannot be interpreted.
# ==== NegativeValuesZeroing =================
Spectrum_data.NVZ <- NegativeValuesZeroing(Spectrum_data.BC)
The spectra are realigned based on a reference spectrum with a Semi-Parametric Time Warping technique.
# ==== Warping =================
W.res <- Warping(Spectrum_data.NVZ, returnWarpFunc = TRUE,
reference.choice = "fixed")
Spectrum_data.W <- W.res[["Spectrum_data"]]
warp_func <- W.res[["Warp.func"]]
During this step the user selects the part of the spectrum that is of interest and the other parts are removed from the spectral matrix.
# ==== WindowSelection =================
Spectrum_data.WS <- WindowSelection(Spectrum_data.W, from.ws = 10,
to.ws = 0.2)
The Bucketing
function reduces the number of spectral
descriptors by aggregating intensities into a series of buckets.
By default, this step sets to zero spectral areas that are of no interest or have a sigificant and unwanted amount of variation (e.g. the water area).
# ==== RegionRemoval =================
Spectrum_data.RR <- RegionRemoval(Spectrum_data.B,
typeofspectra = "serum")
The normalization copes with the dilution factor and other issues that render the spectral profiles non-comparable to each other.
# ==== Normalization =================
Spectrum_data.N <- Normalization(Spectrum_data.RR, type.norm = "mean")
Note: the function ZoneAggregation
is not used here, but
is can be applied e.g. to urine spectra to aggregate the citrate
peak.
The Draw
function enables to produce line plots with
type.draw = "signal"
or PCA results with
type.draw = "pca"
of FIDs or spectra. These plots can be
saved as pdf files with the option output = "pdf"
, see
?Draw
, ?DrawSignal
and ?DrawPCA
for more details on the other available options.
Draw(Spectrum_data.N, type.draw = c("pca"),
output = c("default"), Class = Group_HS,
type.pca = "scores")
Draw(Spectrum_data.N, type.draw = c("pca"),
output = c("default"),
Class = Group_HS, type.pca = "loadings")
sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] PepsNMRData_1.24.0 PepsNMR_1.25.0 knitr_1.49 BiocStyle_2.35.0
#>
#> loaded via a namespace (and not attached):
#> [1] Matrix_1.7-1 gtable_0.3.6 jsonlite_1.8.9
#> [4] compiler_4.4.2 BiocManager_1.30.25 Rcpp_1.0.13-1
#> [7] stringr_1.5.1 gridExtra_2.3 jquerylib_0.1.4
#> [10] scales_1.3.0 yaml_2.3.10 fastmap_1.2.0
#> [13] lattice_0.22-6 plyr_1.8.9 ggplot2_3.5.1
#> [16] R6_2.5.1 labeling_0.4.3 ptw_1.9-16
#> [19] tibble_3.2.1 maketools_1.3.1 munsell_0.5.1
#> [22] bslib_0.8.0 pillar_1.10.0 rlang_1.1.4
#> [25] stringi_1.8.4 cachem_1.1.0 xfun_0.49
#> [28] sass_0.4.9 sys_3.4.3 cli_3.6.3
#> [31] withr_3.0.2 magrittr_2.0.3 digest_0.6.37
#> [34] grid_4.4.2 lifecycle_1.0.4 vctrs_0.6.5
#> [37] evaluate_1.0.1 glue_1.8.0 farver_2.1.2
#> [40] buildtools_1.0.0 RcppDE_0.1.7 colorspace_2.1-1
#> [43] reshape2_1.4.4 rmarkdown_2.29 matrixStats_1.4.1
#> [46] tools_4.4.2 pkgconfig_2.0.3 htmltools_0.5.8.1