### read_generic() -----------------------------------------------------
context("Test read_generic()")
test_that("inputs of NULL fail", {
expect_error(read_generic(NULL))
})
test_that("invalid file formats fail", {
expect_error(read_generic("my_file.not"))
})
openxlsx::write.xlsx(mtcars, "tst.xlsx")
test_that("XLSX files are read in", {
expect_is(read_generic("tst.xlsx"), "data.frame")
})
test_that("row index is respected for XLSX files", {
x <- read_generic("tst.xlsx", rows = c(1, 5:7), col_names = TRUE)
expect_equivalent(x, mtcars[4:6, ])
})
### read_fluostar() ---------------------------------------------------------
context("Test read_fluostar()")
file <- system.file("extdata", "FLUOstar_Albumin_example.xlsx", package = "assayr2")
read <- suppressWarnings(read_fluostar(file))
test_that("read_fluostar() raises Warning if saturated values are present.",
expect_warning(read_fluostar(file), "Saturated values detected"))
test_that("read in works if standard concentrations are provided in file", {
expect_output(str(read), "76 obs")
})
test_that("readin notifies the user of columns being parsed if measurments = NULL", {
expect_message(suppressWarnings(read_fluostar(file)), "standard_concentrations_ng_ml")
})
# testing with missing concentrations
file <- system.file("extdata", "FLUOstar_ATP_example.xlsx", package = "assayr2")
test_that("read in fails if standard concentrations are not present", {
expect_error(read_fluostar(file))
})
values <- serial_dilution(500, 5)
test_that("works when standard concentrations are provided manually", {
expect_output(str(suppressWarnings(read_fluostar(file, std_concs = values))), "74 obs")
})
## read_moldev() --------------------------------------------
context("Test read_moldev() for NileRed")
file <- system.file("extdata", "NileRed_Moldev_example.txt", package = "assayr2")
test_that("detected measurements as printed as messages", {
expect_message(read_moldev(file), "nile_intensity")
})
value <- read_moldev(file)
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
test_that("column names are correct", {
expect_setequal(names(value), c("run", "plate", "well", "site", "nile_intensity", "nuc_count"))
})
test_that("measurements are coherced to numeric", {
expect_type(value$nuc_count, "double")
})
test_that("default plate_capture works", {
expect_equivalent(unique(value$plate), as.character(1:17))
})
context("Test read_moldev() for SMAA")
file <- system.file("extdata", "SMAA_Moldev_example.txt", package = "assayr2")
test_that("detected measurements as printed as messages", {
expect_message(read_moldev(file), "smaa_area")
expect_message(read_moldev(file), "smaa_intensity")
expect_message(read_moldev(file), "mac_count")
expect_message(read_moldev(file), "stellate_count")
})
value <- read_moldev(file)
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
test_that("column names are correct", {
expect_setequal(names(value), c("run", "plate", "well", "site", "smaa_area",
"smaa_intensity", "mac_count", "stellate_count"))
})
test_that("measurements are coherced to numeric", {
expect_type(value$smaa_intensity, "double")
expect_type(value$smaa_area, "double")
expect_type(value$mac_count, "double")
expect_type(value$stellate_count, "double")
})
# behavior removed in favor of consistancy
# test_that("well columns does not have padding zeros", {
# expect_false(any(grepl("^\\D0", value$well)))
# })
## read_discards() --------------------------------------------
file <- system.file("extdata", "PAD0304_NileRed_Discards.csv", package = "assayr2")
value <- read_discards(file)
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
test_that("column names are correct", {
expect_setequal(names(value), c("run", "plate", "well", "site"))
})
## read_ph_assay() --------------------------------------------
context("Test read_ph_assay()")
file <- system.file("extdata", "PH_Assay_example.xlsx", package = "assayr2")
value <- read_ph_assay(file)
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
test_that("plate numbers are parsed correctly", {
expect_setequal(unique(value$plate_id), as.character(c(1242:1247)))
})
## read_ph_raw() --------------------------------------------
context("Test read_ph_raw()")
file <- system.file("extdata", "PH_raw_example.csv", package = "assayr2")
value <- read_ph_raw(file)
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
## read_cfx() -------------------------------------------
context("Test read_cfx()")
file <- system.file("extdata", "CFX_example.csv", package = "assayr2")
value <- read_cfx(file, ".*_(.*)\\.csv")
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
test_that("column names are correct", {
expect_setequal(names(value), c("plate", "well", "cq"))
})
test_that("measurements are coherced to numeric", {
expect_type(value$cq, "double")
})
## read_device_layout() --------------------------------------------
context("Test read_device_layout()")
test_that("inputs of NULL fail", {
expect_error(read_device_layout(NULL))
})
file <- system.file("extdata", "device_layout_example.xlsx", package = "assayr2")
value <- read_device_layout(file)
test_that("outputs a data frame", {
expect_type(value, "list")
expect_is(value, "data.frame")
})
test_that("contains a column 'run'", {
expect_true("run" %in% names(value))
})
## read_magpix() --------------------------------------------
context("Test read_magpix")
file <- system.file("extdata", "Magpix_example.csv", package = "assayr2")
value <- suppressWarnings(read_magpix(file))
test_that("a list is returned", {
expect_is(value, "list")
})
test_that("a list of length 2 is returned", {
expect_equal(length(value), 2)
})
test_that("column names for samples are correct", {
expect_setequal(names(value[[1]]), c("well", "content", "target", "intensity", "log10_intensity"))
})
test_that("column names for standards are correct", {
expect_setequal(names(value[[2]]), c("content", "target", "concentration"))
})
test_that("measurements are coherced to numeric", {
expect_type(value[[1]]$intensity, "double")
expect_type(value[[1]]$log10_intensity, "double")
expect_type(value[[2]]$concentration, "double")
})
test_that("dimensions are expected", {
expect_equal(dim(value[[1]]) , c(608, 5))
expect_equal(dim(value[[2]]) , c(56, 3))
})
## melt_plate_xlsx() --------------------------------------------
context("Test melt_plate_xlsx")
# simulate a plate, with an empty row and empty col
dat <- expand.grid(1:12, LETTERS[1:8])
dat <- dplyr::mutate(dat, content = dplyr::case_when(Var2 == "A" ~ NA_character_,
Var1 == "1" ~ NA_character_,
TRUE ~ "something"))
dat <- tidyr::spread(dat, Var1, content)
openxlsx::write.xlsx(dat, "tst.xlsx")
# this is pattern suggest in the docs for empty rows
value <- melt_plate_xlsx("tst.xlsx", rows = 1:9, cols = "B:M", col_names = TRUE)
test_that("dimensions are expected", {
expect_equal(dim(value) , c(96, 3))
})
test_that("a data frame is returned", {
expect_is(value, "data.frame")
})
test_that("column names are correct", {
expect_setequal(names(value), c("row", "column", "content"))
})
test_that("empty rows are respected", {
expect_true(all(is.na(value$content[value$row == "A"])))
})
test_that("empty cols are respected", {
expect_true(all(is.na(value$content[value$column == "1"])))
})
test_that("content column can be renamed with .id", {
value <- melt_plate_xlsx("tst.xlsx", rows = 1:9, cols = "B:M", col_names = TRUE, .id = "well-stuff")
expect_true("well-stuff" %in% names(value))
})
test_that(".id smoothly handles NULL and NAs", {
expect_silent(melt_plate_xlsx("tst.xlsx", rows = 1:9, cols = "B:M", col_names = TRUE, .id = NULL))
expect_silent(melt_plate_xlsx("tst.xlsx", rows = 1:9, cols = "B:M", col_names = TRUE, .id = NA))
})
# clean up ----------------------------------------------------------------
rm(dat, value)
unlink("tst.xlsx")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.