Title: | Make Spectroscopic Data Processing Easier |
---|---|
Description: | The goal of 'andurinha' is provide a fast and friendly way to process spectroscopic data. It is intended for processing several spectra of samples with similar composition (tens to hundreds of spectra). It compiles spectroscopy data files, produces standardized and second derivative spectra, finds peaks and allows to select the most significant ones based on the second derivative/absorbance sum spectrum. It also provides functions for graphic evaluation of the outputs. |
Authors: | Noemi Alvarez Fernandez [aut, cre] , Antonio Martinez Cortizas [aut] |
Maintainer: | Noemi Alvarez Fernandez <[email protected]> |
License: | GPL-2 | file LICENSE |
Version: | 0.0.2 |
Built: | 2024-11-23 03:48:36 UTC |
Source: | https://github.com/noemiallefs/andurinha |
This package contains a set of functions that makes spectroscopic data processing easier and faster. It is intended for processing several spectra (tens to hundreds) of samples with similar composition. It compiles spectroscopy data files, produces standardised and second derivative spectra, finds peaks and allows to select the most significant ones based on the second derivative/absorbance sum spectrum. It also provides functions for graphic evaluation of the outputs.
importSpectra
: in case you have your spectra in
separated files (.csv) this function imports and bind them in a single data
frame.
findPeaks
: finds peaks and allows to select the most
relevant based on the second derivative sum spectrum.
gOverview
: generates a graphic overview of the
spectroscopic data.
plotPeaks
: makes a graphic representation of the
peaks over the second derivative/absorbance sum spectrum.
A collection of FTIR-ATR mid-infrared spectra of peat samples with increasing degree of peat humification.
andurinhaData
andurinhaData
A data frame with 1736 observations of 3 peat samples.
WN: wave numbers of the spectra.
A-C: absorbances of a FTIR spectra of three peat samples.
EcoPast research group, Universidade de Santiago de Compostela (Spain) https://ecopast.es
importSpectra
, findPeaks
,
plotPeaks
and gOverview
This function finds peaks and allows to the most relevant based on the second derivative/absorbance sum spectrum.
findPeaks( data, resolution = 4, minAbs = 0.1, cutOff = NULL, scale = TRUE, ndd = TRUE )
findPeaks( data, resolution = 4, minAbs = 0.1, cutOff = NULL, scale = TRUE, ndd = TRUE )
data |
A data frame object, which contains in the first column the wave numbers and in the following columns the samples absorbances. |
resolution |
The equipment measurement resolution; by default 4 cm-1. |
minAbs |
The cut off value to check spectra quality; by default 0.1. |
cutOff |
The second derivative/absorbance sum spectrum cut off to reduce the raw peaks table; by default NULL. |
scale |
By default (TRUE) the data is scaled by Z-scores. Use FALSE in case you do not want to scale it. |
ndd |
By default (TRUE) the peaks are searched based on the second derivative sum spectrum. Use FALSE in case you want to search them based on the absorbance sum spectrum. |
A list with a collection of data frames which contains:
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/absorbance sum spectrum values.
peaksTable: the selected peaks wave numbers and their absorbance for each spectrum.
importSpectra
, gOverview
and
plotPeaks
# Find Peaks based on the absorbance sum spectrum fp.abs <- findPeaks(andurinhaData, ndd = FALSE) # See the peaks table of the absorbance sum spectrum fp.abs$sumSpectrum_peaksTable # Find Peaks based on the second derivative sum spectrum fp.ndd <- findPeaks(andurinhaData) # See the peaks table of the second derivative sum spectrum fp.ndd$sumSpectrum_peaksTable # Select a cutOff to reduce the number of peaks in the table # (i.e. select the most relevant) # fp.ndd$sumSpectrum_peaksTable %>% # arrange(desc(sumSpectrum)) # Run findPeaks() with the new cutOff fp.ndd2 <- findPeaks(andurinhaData, cutOff = 0.25)
# Find Peaks based on the absorbance sum spectrum fp.abs <- findPeaks(andurinhaData, ndd = FALSE) # See the peaks table of the absorbance sum spectrum fp.abs$sumSpectrum_peaksTable # Find Peaks based on the second derivative sum spectrum fp.ndd <- findPeaks(andurinhaData) # See the peaks table of the second derivative sum spectrum fp.ndd$sumSpectrum_peaksTable # Select a cutOff to reduce the number of peaks in the table # (i.e. select the most relevant) # fp.ndd$sumSpectrum_peaksTable %>% # arrange(desc(sumSpectrum)) # Run findPeaks() with the new cutOff fp.ndd2 <- findPeaks(andurinhaData, cutOff = 0.25)
This function generates a graphic overview of the spectroscopic data.
gOverview(data_abs, data_ndd, fontFamily = NULL)
gOverview(data_abs, data_ndd, fontFamily = NULL)
data_abs |
A data frame, which contains in the first column the wave numbers and in the following columns the samples absorbances. |
data_ndd |
A data frame, which contains in the first column the wave numbers and in the following columns the samples second derivative values. |
fontFamily |
The desired graphic font family. |
It returns a grid with three plots:
The ensemble of all samples spectra.
The ensemble of the second derivative spectra of all samples.
The average and standard deviation spectra.
It returns a grid with two plots:
The ensemble of all samples spectra.
The average and standard deviation spectra.
importSpectra
, findPeaks
and
plotPeaks
# Grapic overview of your raw data gOverview(andurinhaData) # Graphic overview of your processed data by findPeaks() fp <- findPeaks(andurinhaData) gOverview(fp$dataZ, fp$secondDerivative)
# Grapic overview of your raw data gOverview(andurinhaData) # Graphic overview of your processed data by findPeaks() fp <- findPeaks(andurinhaData) gOverview(fp$dataZ, fp$secondDerivative)
In case you have your spectra in separated files (.csv) this function imports and binds them in a single data frame. The files directory must contain only the samples files.
importSpectra(path, sep = ";")
importSpectra(path, sep = ";")
path |
A character vector with the full path to the data directory; by
default corresponds to the working directory, |
sep |
The field separator character; by default sep = ";". |
A data frame with the structure:
First column (WN): wave numbers of the spectra.
1-n: samples spectra (the column names correspond to the files names).
findPeaks
, gOverview
and
plotPeaks
# Create an empty directory # Now create some spectra separate files A <- andurinhaData[, 1:2] B <- andurinhaData[, c(1, 3)] C <- andurinhaData[, c(1, 4)] MASS::write.matrix(A, file = tempfile(pattern = "A.csv"), sep = ";") MASS::write.matrix(A, file = tempfile(pattern = "B.csv"), sep = ";") MASS::write.matrix(A, file = tempfile(pattern = "C.csv"), sep = ";") # Try importSpectra(path = paste0(tempdir(), "/"), ";")
# Create an empty directory # Now create some spectra separate files A <- andurinhaData[, 1:2] B <- andurinhaData[, c(1, 3)] C <- andurinhaData[, c(1, 4)] MASS::write.matrix(A, file = tempfile(pattern = "A.csv"), sep = ";") MASS::write.matrix(A, file = tempfile(pattern = "B.csv"), sep = ";") MASS::write.matrix(A, file = tempfile(pattern = "C.csv"), sep = ";") # Try importSpectra(path = paste0(tempdir(), "/"), ";")
This function makes a graphic representation of the peaks over the second derivative and/or absorbance sum spectra.
plotPeaks(peaksWN, data_abs, data_ndd, fontFamily = NULL)
plotPeaks(peaksWN, data_abs, data_ndd, fontFamily = NULL)
peaksWN |
A vector with the peaks wave numbers. |
data_abs |
A data frame, which contains in the first column the wave numbers and in the following columns the samples absorbances. |
data_ndd |
A data frame, which contains in the first column the wave numbers and in the following columns the samples second derivative values. |
fontFamily |
The desired graphic font family. |
importSpectra
, findPeaks
and
gOverview
# Plot the peaks found by findPeaks() # 1. Based on absorbance sum spectrum fp.abs <- findPeaks(andurinhaData, ndd = FALSE) plotPeaks(fp.abs[[3]]$WN, fp.abs$dataZ) # 2. Based on second derivative spectrum fp.ndd <- findPeaks(andurinhaData, cutOff = 0.25) plotPeaks(fp.ndd[[4]]$WN, fp.ndd$dataZ, fp.ndd$secondDerivative)
# Plot the peaks found by findPeaks() # 1. Based on absorbance sum spectrum fp.abs <- findPeaks(andurinhaData, ndd = FALSE) plotPeaks(fp.abs[[3]]$WN, fp.abs$dataZ) # 2. Based on second derivative spectrum fp.ndd <- findPeaks(andurinhaData, cutOff = 0.25) plotPeaks(fp.ndd[[4]]$WN, fp.ndd$dataZ, fp.ndd$secondDerivative)