This packages provides tools to make spectroscopic data processing easier and faster. It allows to find and select peaks based on the second derivative or absorbance sum spectrum. Furthermore, it supplies functions for graphic support, which makes the workflow more user friendly.
library(andurinha)
There are two common situations when importing the spectroscopic data.
In the first case, data may be in the same file with the structure:
First column: wave numbers.
The following columns: the samples absorbances.
In that case, import the data with the most suitable function.
In the second case, data may be in separated files with the structure:
First column: wave numbers.
Second column: sample absorbance.
In that case, the function importSpectra()
can be used; to do so the files extension should be .csv
and they must be in the same directory - this folder must not contain any other file.
importSpectra(path = tempdir(), sep = ";")
spectra <-head(spectra)
#> WN A B C
#> 1 399 0.011 0.008 0.009
#> 2 401 0.008 0.006 0.006
#> 3 403 0.006 0.005 0.006
#> 4 405 0.005 0.005 0.005
#> 5 407 0.005 0.005 0.003
#> 6 409 0.003 0.004 0.002
The function findPeaks()
verifies the spectra quality, finds peaks (surprise!) and allows to select the most relevant ones based on the absorbance or second derivative sum spectrum. To use it the data must be in the appropriate format, it means that the object class must be a data frame
with the structure:
First column: wave numbers.
The following columns: samples absorbances.
This function has five arguments:
resolution
: the equipment measurement resolution, which is by default 4 cm-1.
minAbs
: the cut off value to check spectra quality, which is by default a spectrum absorbance maximum of 0.1.
cutOff
: the second derivative or absorbance sum spectrum cut off to reduce the raw peaks table, which is by default NULL
.
scale
: by default is TRUE
and data is scaled as Z-scores. FALSE
should be used in case you do not want to scale it.
ndd
: by default is TRUE
and peaks are searched based on the second derivative sum spectrum. FALSE
should be used in case you want to search them based on absorbance sum spectrum.
This function - with all the arguments by default - returns a list
with four data frames
:
dataZ: the standardised data by Z-scores.
secondDerivative: the second derivative values of the data.
sumSpectrum_peaksTable: the peaks wave numbers and their second derivative or absorbance sum spectrum values.
peaksTable: the peaks wave numbers and their absorbance for each spectrum.
By default, if there is any spectrum with a maximum absorbance lower than 0.1 a warning will be returned; in case this shows up and you want to continue, you should modify the minAbs
value. Once the quality control has been passed, by default the data is scaled - to skip it use scale = FASLE
- the next steps will depend on the selected method for finding peaks:
Absorbance sum spectrum: in this case the absorbance sum spectrum is calculated and the peaks are searched based on it.
Second derivative sum spectrum: in this case the second derivative of the absorbance data is calculated and then the peaks are searched based on the sum spectrum.
# Search peaks based on absorbance sum spectrum
# with standarised absorbance data
findPeaks(andurinhaData, ndd = FALSE)
fp.abs <-summary(fp.abs)
#> Length Class Mode
#> dataZ 4 data.frame list
#> sumSpectrum_peaksTable 2 data.frame list
#> peaksTable 4 data.frame list
dim(fp.abs$sumSpectrum_peaksTable)
#> [1] 34 2
# Search peaks based on second derivative sum spectrum
# with standarised absorbance data
findPeaks(andurinhaData)
fp.ndd <-summary(fp.ndd)
#> Length Class Mode
#> dataZ 4 data.frame list
#> secondDerivative 4 data.frame list
#> sumSpectrum_peaksTable 2 data.frame list
#> peaksTable 4 data.frame list
dim(fp.ndd$sumSpectrum_peaksTable)
#> [1] 220 2
# Search peaks based on second derivative sum spectrum
# with no standarised absorbance data
findPeaks(andurinhaData, scale = FALSE)
fp.nZs <-summary(fp.nZs)
#> Length Class Mode
#> secondDerivative 4 data.frame list
#> sumSpectrum_peaksTable 2 data.frame list
#> peaksTable 4 data.frame list
dim(fp.nZs$sumSpectrum_peaksTable)
#> [1] 219 2
To visualised both the raw data and the processed data by findPeaks()
; the functions gOverview()
and plotPeaks()
may be applied.
gOverview()
:Gives a graphic summary of the data. This function has the arguments:
data_abs
: to provide a data frame with the absorbance data. The structure should be: wave numbers in the first column and samples absorbance in the following columns.
data_ndd
: to provide a data frame with the second derivative data. The structure should be: wave numbers in the first column and samples second derivative values in the following columns.
fontFamily
: to change the plot font.
# Graphic overview of the raw data
gOverview(andurinhaData)