knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
When eemR
was originally created, I wrote few functions to import eems derived from the spectrofluorometers I knew. Given the high diversity in file formats, eemR
now offers the possibility for the user to write his/her own import function.
In this example, we will learn how to create a import function for a specific eem file generated by the software of a Cary Eclipse spectrofluorometer. First, lets have a look to the content of custom_cary.csv
.
file <- system.file("extdata/custom_cary.csv", package = "eemR") cat(readLines(file, n = 25), sep = "\n")
From this output, we see that:
The first thing we need to do is to create a function that will read this data in a format that can be used by eemR
. The function needs to meet these flowing criteria:
file
that will contains the path of the file(s) to read.file
: the path of the fileem
: a numeric vector containing emission wavelengths.ex
: a numeric vector containing excitation wavelengths.x
: a matrix of length(em)
rows by length(ex)
columns.Further more, the x
matrix of the list need to be arranged as follow:
Let's now write a function that will read the eem file and format the data accordingly. In this particular example, fluorescence has been measured in asynchronous mode. Hence, extra manipulations are needed to get the data on a regular grid.
library(dplyr) library(tidyr) library(eemR) import_cary <- function(file) { dat <- read.csv(file, nrows = 102, skip = 1) ex <- na.omit(dat[, 1]) em <- seq(50, 330, by = 5) em <- outer(ex, em, "+") em <- as.vector(em) ex <- rep(ex, 57) x <- dat[, -1] x <- x[-1, ] x <- matrix(as.numeric(unlist(x, use.names = FALSE)), ncol = 101, byrow = FALSE) res <- tibble(ex, em, x = as.vector(x)) %>% arrange(ex, em) %>% complete(ex, em, fill = list(x = NA)) ex <- sort(unique(ex)) em <- sort(unique(em)) x <- matrix(res$x, ncol = length(ex), byrow = TRUE) # We need to interpolate because you do not have a regular grid (i.e. asynchronous) r <- MBA::mba.surf(res %>% drop_na(), no.X = 200, no.Y = 200, extend = FALSE) l <- list( file = file, x = t(r$xyz.est$z), ex = r$xyz.est$x, em = r$xyz.est$y ) return(l) }
We can now try our function and have a look to the structure of the returned list.
str(import_cary(file))
We will use the import_function
argument of the eem_read()
function to tell eemR
how to read our file.
eem <- eem_read(file, import_function = import_cary) eem
We can visualize the eem by using the plot()
function:
plot(eem)
All other functions of the eemR
package can now be used on the created eem
. For example, we can remove the second order scattering.
# Remove second order Rayleigh scattering plot(eem_remove_scattering(eem, "rayleigh", order = 2, width = 15)) # Extract Coble' peaks eem_coble_peaks(eem)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.