Skip to content

Commit

Permalink
New function eem_peaks() to extract user-defined fluorescence peaks (#42
Browse files Browse the repository at this point in the history
)
  • Loading branch information
PMassicotte committed Mar 29, 2018
1 parent 4208497 commit 0d6323f
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 2 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Expand Up @@ -3,7 +3,7 @@ Type: Package
Title: Tools for Pre-Processing Emission-Excitation-Matrix (EEM) Fluorescence
Data
Version: 0.1.5.9000
Date: 2017-05-08
Date: 2018-03-29
Authors@R: person("Philippe", "Massicotte", email = "pmassicotte@hotmail.com",
role = c("aut", "cre"))
Description: Provides various tools for preprocessing Emission-Excitation-Matrix (EEM) for Parallel Factor Analysis (PARAFAC). Different
Expand All @@ -22,7 +22,9 @@ Imports:
readr,
stats,
rlist,
viridis
viridis,
purrr,
assertthat
RoxygenNote: 6.0.1
Suggests:
cdom,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -15,16 +15,19 @@ export(eem_fluorescence_index)
export(eem_humification_index)
export(eem_inner_filter_effect)
export(eem_names)
export(eem_peaks)
export(eem_raman_normalisation)
export(eem_read)
export(eem_remove_blank)
export(eem_remove_scattering)
export(eem_set_wavelengths)
import(assertthat)
importFrom(graphics,filled.contour)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,text)
importFrom(graphics,title)
importFrom(purrr,map2)
importFrom(readr,read_lines)
importFrom(rlist,list.apply)
importFrom(rlist,list.group)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# eemR 0.1.6 (Unreleased)

- New function `eem_peaks()` to extract user-defined fluorescence peaks (#42).

- `eem_read()` will try to import unknown file format if it fails to determine it. At the moment the heuristic is not perfect, so the file must be "easy" to read (i.e. contain a square matrix of data).

# eemR 0.1.5
Expand Down
57 changes: 57 additions & 0 deletions R/eem_metrics.R
Expand Up @@ -135,6 +135,63 @@ eem_coble_peaks <- function(eem, verbose = TRUE){
stringsAsFactors = FALSE))
}

#' Extract fluorescence peaks
#'
#' @param ex A numeric vector with excitation wavelengths.
#' @param em A numeric vector with emission wavelengths.
#'
#' @template template_eem
#'
#' @template template_section_interp2
#'
#' @return A data frame containing excitation and emission peak values. See
#' details for more information.
#'
#' @importFrom purrr map2
#' @import assertthat
#'
#' @examples
#' file <- system.file("extdata/cary/scans_day_1/", "sample1.csv", package = "eemR")
#' eem <- eem_read(file)
#'
#' eem_peaks(eem, ex = c(250, 350), em = c(300, 400))
#'
#' @export
eem_peaks <- function(eem, ex, em, verbose = TRUE) {
stopifnot(.is_eemlist(eem) | .is_eem(eem))
stopifnot(
is.numeric(ex),
is.numeric(em),
length(ex) == length(em),
all(ex > 0),
all(em > 0)
)

## It is a list of eems, then call lapply
if (.is_eemlist(eem)) {
res <- lapply(eem, eem_peaks, ex, em, verbose = verbose)
res <- dplyr::bind_rows(res)

return(res)
}

assertthat::assert_that(all(dplyr::between(ex, range(eem$ex)[1], range(eem$ex)[2])), msg = "Excitation values are not within the range of excitation values of the EEM.")
assertthat::assert_that(all(dplyr::between(em, range(eem$em)[1], range(eem$em)[2])), msg = "Emission values are not within the range of emission values of the EEM.")

peak_intensity <- purrr::map2(ex, em, function(ex, em) {
pracma::interp2(eem$ex, eem$em, eem$x, ex, em)
})

peak_intensity <- unlist(peak_intensity)

return(data.frame(
sample = eem$sample,
ex = ex,
em = em,
peak_intensity = peak_intensity
))
}

#' Calculate the fluorescence humification index (HIX)
#'
#' @template template_eem
Expand Down
47 changes: 47 additions & 0 deletions man/eem_peaks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d6323f

Please sign in to comment.