Jacob Anderson 12/12/2021
peak.gas is an R package developed as a useful tool in extrapolating gas concentration data from text file output generated from benchtop infrared gas analyzers(IRGA).
there are 2 processing functions that are included in peak.gas, each processing function is accompanied by a plotting function
-
extract.peaks(cut.off = 2, method = “linear”, standard.sum = F, check.stand = F, check.alpha = .05, ci.meth = “avg”, verbose = F)
- plot(extract.peaks output, file = NULL, sample = NULL, std.curve = F, method = “linear”)
-
timeseries.peaks()
- plot(timeseries.peaks output, file, sample = NULL, time.start = NULL, time.stop = NULL)
The text file output should be formatted into 3 columns.
-
the first column should contain the time between samples starting at time zero as well as the sample names distinguished between dash marks (typically labeled as Etime),
-
the second column should be the datetime the sample was collected (typically labeled as Time),
-
and the third column should be the readings outpurt from the machine (in the case below labeled as CO2 (μmo**l/mol)). the sample name annotation should be included in the Etime column and distinguished by a series of dash marks. (see example below)
Should your data look differently the code should be modified to account for the change, or the data itself should be modified to match the structure of the example below
Example of proper .txt file output generated using a LI-COR LI-8100A IRGA
This function can be installed from the github repository
andersonjake1988/peak.gas by using the package devtools
and the
following approach
library(devtools)
install_github('andersonjake1988/peak.gas')
library(peak.gas)
extract.peaks(directory = choose.dir(), cut.off = 2, method = “linear” or “log”, standard.sum = F, check.stand = F, check.alpha = .05, ci.meth = “avg”, verbose = T)
extract.peaks() function will loop through a folder of text files sharing identical formatting to combine and output a single dataframe containing the columns:
- directory The path to the directory (folder) that the function will process. Defaults to user selection window
- cut.off: this argument sets the value to indicate the start and the end each peak. (essentially where to set the baseline of the peaks). Defaults to 2
- method: this argument specifies whether to use a ‘linear’ equation during the standard curve calibration or a ‘log’ transformed equation. Defaults to “linear”
- standard.sum: this argument specifies whether or not to output a table containing standard curve statistics along with the data output or not. Defaults to FALSE
- check.stand: A logical argument stating whether or not to compare “check” standards to the standard curve. Defaults to FALSE
- check.alpha: The value (0-1) to accept for check standard deviation, lower numbers indicate the confidence interval increases. Defaults to .05
- ci.meth Argument to specify whether to compare average (“avg”) check standard AUC values, or individual (“indiv”) check standard AUC values. Defaults to “avg”
- verbose A logical argument stating whether or not to display all function processing information. Defaults to TRUE
- File_Name: The file name containing the data
- Sample: The sample annotations found within the file
- Replicate: The individual peaks found in each sample annotation
- Order_run: The numbered order that the sample was run in each file
- AUC: The sum of the area under the curve of each peak before standard calibration
- Peak: The maximum peak value recorded before standard calibration
- Time_Peak_Start: Datetime of the value recorded signalling the start of each peak
- Time_Peak_Stop: Datetime of the value recorded signalling the end of each peak
- Timespan_(s): The duration of each peak
- AUC_ppm: The sum of the area under the curve of each peak corrected using a standard calibration curve of known concentrations.
# run extract.peaks() function and store as object
output <- extract.peaks(directory = path.package("peak.gas"))
## Working directory set to:
## C:/Users/ander/Documents/R/win-library/4.1/peak.gas
## [1] "Looping through Folder:"
## | | | 0% | |================== | 25% | |=================================== | 50% | |==================================================== | 75% | |======================================================================| 100%[1] "done"
# look at output
head(output)
## # A tibble: 6 x 10
## File_Name Sample Replicate Order_Run AUC Peak Time_Peak_Start
## <chr> <chr> <chr> <dbl> <dbl> <dbl> <dttm>
## 1 vn_clear_071621.txt 300cu~ 1 1 30.5 10.5 2021-07-16 11:32:07
## 2 vn_clear_071621.txt 300cu~ 2 1 24.4 9.02 2021-07-16 11:32:51
## 3 vn_clear_071621.txt 300cu~ 3 1 23.2 8.69 2021-07-16 11:33:19
## 4 vn_clear_071621.txt 500cu~ 1 2 44.8 14.4 2021-07-16 11:34:25
## 5 vn_clear_071621.txt 500cu~ 2 2 46.8 14.9 2021-07-16 11:35:18
## 6 vn_clear_071621.txt 500cu~ 3 2 47.7 15.4 2021-07-16 11:36:03
## # ... with 3 more variables: Time_Peak_End <dttm>, Timespan_(s) <dbl>,
## # AUC_ppm <dbl>
peak.gas provides a plotting framework for exploring the data output from the extract.peaks() function
- data: the output from the extract.peaks() function
- file: select a specific file to plot. Defaults to NULL
- sample: select a specific sample to plot. Defaults to NULL
- std.curve: plot the standard curve data. Defaults to FALSE
- method: and option to plot the linear standard curve or the log standard curve. Defaults to ‘linear’
# Pulls up a random plot from extract.peaks() output
plot(output)
# plots all samples called "NN_DARKVEG"
plot(output, sample = "NN_DARKVEG")
# plots all samples called "NN_DARKVEG" from file "vn_darkveg_071621.txt"
plot(output, file = "vn_darkveg_071621.txt", sample = "NC_DARKVEG")
# Plots the total linear standard curve using all files
plot(output, std.curve = T)
# Plots the total log transformed standard curve using all files
plot(output, std.curve = T, method = 'log')
# Plots the standard curve for the file "vn_clear_07292021.txt"
plot(output, file = "vn_clear_07292021.txt", std.curve = T)
This is a simplified version of extract.peaks()
this function will
transfer over the sample name and combine all the text files into a
single timeseries dataframe. There are no arguments needed for this
function.
- directory The path to the directory (folder) that the function will process. Defaults to user selection window
- verbose A logical argument stating whether or not to display all function processing information. Defaults to TRUE
test <- timeseries.peaks(directory = path.package("peak.gas"))
## Working directory set to:
## C:/Users/ander/Documents/R/win-library/4.1/peak.gas
## [1] "Looping through Folder:"
## | | | 0% | |================== | 25% | |=================================== | 50% | |==================================================== | 75% | |======================================================================| 100%
head(test)
## File Sample Time CO2
## 46 vn_clear_071621.txt 300curve 2021-07-16 11:31:44 -1.16
## 47 vn_clear_071621.txt 300curve 2021-07-16 11:31:45 -1.02
## 48 vn_clear_071621.txt 300curve 2021-07-16 11:31:46 -1.14
## 49 vn_clear_071621.txt 300curve 2021-07-16 11:31:47 -1.03
## 50 vn_clear_071621.txt 300curve 2021-07-16 11:31:48 -0.88
## 52 vn_clear_071621.txt 300curve 2021-07-16 11:31:49 -0.87
plot(timeseries.peaks output, file, sample = NULL, samp.div = TRUE, time.start = NULL, time.stop = NULL)
peak.gas provides a plotting framework for exploring the data output from the timeseries.peaks() function
- data: the output from the timeseries.peaks() function
- file: select a specific file to plot
- sample: select a specific sample to plot. Defaults to NULL
- samp.div: logical statment stating whether or not to display sample dividers in plot. Defaults to TRUE
- time.start: plot data appearing after the value entered. Defaults to NULL
- time.stop: plot data appearing before the value entered. Defaults to NULL
# plot timeseries by file
plot(test, file = "vn_veg_07292021.txt")
# Plot timeseris by file and sample name
plot(test, file = "vn_veg_07292021.txt", sample = "500curve")
# plot timeseries by file starting after "2021-08-02 13:30:00"
plot(test, file = "vn_veg_07292021.txt", time.start = "2021-08-02 13:30:00")
# plot timeseries by file starting before "2021-08-02 12:40:00"
plot(test, file = "vn_veg_07292021.txt", time.stop = "2021-08-02 12:40:00")
# plot timeseries by file between the times "2021-08-02 12:45:00" and "2021-08-02 13:00:00"
plot(test, file = "vn_veg_07292021.txt", time.start = "2021-08-02 12:45:00", time.stop = "2021-08-02 13:00:00")