Skip to content

Commit

Permalink
Simplify tests and remove messaging from ijtiff.
Browse files Browse the repository at this point in the history
  • Loading branch information
rorynolan committed May 15, 2021
1 parent 6006d1e commit 65903dd
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 172 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nandb
Title: Number and Brightness Image Analysis
Version: 2.0.8
Version: 2.1.0
Authors@R:
c(person(given = "Rory",
family = "Nolan",
Expand Down Expand Up @@ -33,10 +33,10 @@ Depends:
R (>= 3.1)
Imports:
assertthat,
autothresholdr (>= 1.3.7),
autothresholdr (>= 1.3.11),
BBmisc,
checkmate (>= 1.9.3),
detrendr (>= 0.6.2),
detrendr (>= 0.6.12),
dplyr,
filesstrings (>= 3.2),
ggplot2,
Expand Down Expand Up @@ -66,6 +66,8 @@ LinkingTo:
Rcpp (>= 1.0.1)
VignetteBuilder:
knitr
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# `nandb` 2.1.0

## MINOR IMPROVEMENTS
* No more messages from `ijtiff` I/O.

## BUG FIXES
* Insist on bug-fixed `autothresholdr`.


# `nandb` 2.0.8

## BUG FIXES
Expand Down
4 changes: 2 additions & 2 deletions R/brightness.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ brightness_file <- function(path, def,
path %<>% filesstrings::before_last_dot() %>%
paste0("brightness", "/", ., make_nb_filename_ending(b)) %>%
deduplicate_nb_filename()
ijtiff::write_tif(b, path)
ijtiff::write_tif(b, path, msg = FALSE)
}

brightness_timeseries_file <- function(path, def, frames_per_set,
Expand Down Expand Up @@ -323,7 +323,7 @@ brightness_timeseries_file <- function(path, def, frames_per_set,
path %<>% filesstrings::before_last_dot() %>%
paste0("brightness_timeseries", "/", ., make_nb_filename_ending(bts)) %>%
deduplicate_nb_filename()
ijtiff::write_tif(bts, path)
ijtiff::write_tif(bts, path, msg = FALSE)
}


Expand Down
6 changes: 3 additions & 3 deletions R/cc_brightness.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ cc_brightness_timeseries <- function(img, frames_per_set,
if (length(detrend) == 1) detrend %<>% rep(2)
thresh %<>% prepare_thresh()
filt %<>% prepare_filt()
if (is.character(img)) img %<>% ijtiff::read_tif()
if (is.character(img)) img %<>% ijtiff::read_tif(msg = FALSE)
checkmate::assert_array(img, d = 4)
if (dim(img)[4] < frames_per_set) {
custom_stop("
Expand Down Expand Up @@ -313,7 +313,7 @@ cc_brightness_file <- function(path, ch1 = 1, ch2 = 2,
path %<>% filesstrings::before_last_dot() %>%
paste0("cc_brightness", "/", ., make_cc_nb_filename_ending(cc_b)) %>%
deduplicate_cc_nb_filename()
ijtiff::write_tif(cc_b, path)
ijtiff::write_tif(cc_b, path, msg = FALSE)
}

cc_brightness_timeseries_file <- function(path, frames_per_set,
Expand Down Expand Up @@ -346,7 +346,7 @@ cc_brightness_timeseries_file <- function(path, frames_per_set,
make_cc_nb_filename_ending(cc_b_ts)
) %>%
deduplicate_cc_nb_filename()
ijtiff::write_tif(cc_b_ts, path)
ijtiff::write_tif(cc_b_ts, path, msg = FALSE)
}

#' Cross-correlated brightness calculations for every image in a folder.
Expand Down
6 changes: 3 additions & 3 deletions R/cc_number.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ cc_number_timeseries <- function(img, frames_per_set, overlap = FALSE,
if (length(detrend) == 1) detrend %<>% rep(2)
thresh %<>% prepare_thresh()
filt %<>% prepare_filt()
if (is.character(img)) img %<>% ijtiff::read_tif()
if (is.character(img)) img %<>% ijtiff::read_tif(msg = FALSE)
checkmate::assert_array(img, d = 4)
if (dim(img)[4] < frames_per_set) {
custom_stop("
Expand Down Expand Up @@ -312,7 +312,7 @@ cc_number_file <- function(path, ch1 = 1, ch2 = 2, thresh = NULL,
path %<>% filesstrings::before_last_dot() %>%
paste0("cc_number", "/", ., make_cc_nb_filename_ending(cc_n)) %>%
deduplicate_cc_nb_filename()
ijtiff::write_tif(cc_n, path)
ijtiff::write_tif(cc_n, path, msg = FALSE)
}

cc_number_timeseries_file <- function(path, frames_per_set,
Expand Down Expand Up @@ -343,7 +343,7 @@ cc_number_timeseries_file <- function(path, frames_per_set,
make_cc_nb_filename_ending(cc_n_ts)
) %>%
deduplicate_cc_nb_filename()
ijtiff::write_tif(cc_n_ts, path)
ijtiff::write_tif(cc_n_ts, path, msg = FALSE)
}

#' Cross-correlated number calculations for every image in a folder.
Expand Down
27 changes: 0 additions & 27 deletions R/io.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ nb_get_img <- function(img) {
checkmate::check_file_exists(img)
)
if (is.character(img)) {
img %<>% ijtiff::read_tif()
img %<>% ijtiff::read_tif(msg = FALSE)
}
checkmate::assert_numeric(img, lower = 0)
if (!isTRUE(all.equal(img, floor(img), check.attributes = FALSE))) {
Expand Down
10 changes: 6 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ install:
# Adapt as necessary starting from here

environment:
global:
R_VERSION: release
R_ARCH: x64
NOT_CRAN: true
BIOC_USE_DEVEL: FALSE
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
matrix:
- R_VERSION: oldrel
- R_VERSION: release
- R_VERSION: devel

build_script:
- travis-tool.sh install_deps
Expand Down
8 changes: 4 additions & 4 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"issueTracker": "https://github.com/rorynolan/nandb/issues",
"license": "https://spdx.org/licenses/BSD-3-Clause",
"version": "2.0.8",
"version": "2.1.0",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -240,7 +240,7 @@
"@type": "SoftwareApplication",
"identifier": "autothresholdr",
"name": "autothresholdr",
"version": ">= 1.3.7",
"version": ">= 1.3.11",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -278,7 +278,7 @@
"@type": "SoftwareApplication",
"identifier": "detrendr",
"name": "detrendr",
"version": ">= 0.6.2",
"version": ">= 0.6.12",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -521,5 +521,5 @@
}
}
],
"fileSize": "2683914.553KB"
"fileSize": "3153.628KB"
}
79 changes: 39 additions & 40 deletions tests/testthat/test-brightness.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
context("brightness()")
test_that("brightness works", {
set.seed(1)
img <- system.file("extdata", "50.tif", package = "nandb")
brightness <- brightness(img, "e",
thresh = "Huang", detrend = TRUE,
filt = "median", parallel = 2
)
expect_equal(mean(brightness, na.rm = TRUE), 0.028, tolerance = 0.011)
brightness <- brightness(img, "b", thresh = "Huang", filt = "mean")
expect_equal(mean(brightness, na.rm = TRUE), 1.05, tolerance = 0.01)
img %<>% ijtiff::read_tif()
brightness <- suppressMessages(
brightness(img, "e",
thresh = "Huang", detrend = TRUE,
filt = "median", parallel = 2
)
)
expect_equal(mean(brightness, na.rm = TRUE), 0.028, tolerance = 0.1)
brightness <- suppressMessages(
brightness(img, "b", thresh = "Huang", filt = "mean")
)
expect_equal(mean(brightness, na.rm = TRUE), 1.05, tolerance = 0.1)
img <- ijtiff::read_tif(img, msg = FALSE)
brightness <- brightness(img, "B", detrend = FALSE, filt = "median")
skip_if_not_installed("abind")
two_channel_img <- abind::abind(img, img, along = 3)
Expand All @@ -23,7 +26,7 @@ test_that("brightness works", {
abind::abind(brightness, brightness, along = 3) %>% {
list(dim(.), as.vector(.))
},
check.attributes = FALSE
ignore_attr = TRUE
)
expect_error(
brightness(img, def = "rory"),
Expand All @@ -34,16 +37,17 @@ test_that("brightness works", {
)
})

context("brightness_folder()")
test_that("brightness_folder works", {
set.seed(1)
img <- ijtiff::read_tif(system.file("extdata", "50.tif", package = "nandb"))
cwd <- setwd(tempdir())
img <- ijtiff::read_tif(system.file("extdata", "50.tif", package = "nandb"),
msg = FALSE
)
cwd <- setwd(tempdir(check = TRUE))
on.exit(setwd(cwd))
ijtiff::write_tif(img, "50.tif")
ijtiff::write_tif(img, "50again.tif")
ijtiff::write_tif(array(4, dim = rep(4, 4)), "const.tif")
brightness_folder(def = "b", detrend = FALSE)
ijtiff::write_tif(img, "50.tif", msg = FALSE)
ijtiff::write_tif(img, "50again.tif", msg = FALSE)
ijtiff::write_tif(array(4, dim = rep(4, 4)), "const.tif", msg = FALSE)
suppressMessages(brightness_folder(def = "b", detrend = FALSE))
expect_true(
all(c(
"50_brightness_B_swaps=NA_thresh=NA_filt=NA.tif",
Expand All @@ -55,7 +59,7 @@ test_that("brightness_folder works", {
) %in%
list.files("brightness"))
)
brightness_folder(def = "E", detrend = FALSE)
suppressMessages(brightness_folder(def = "E", detrend = FALSE))
expect_true(
all(c(
"50_brightness_epsilon_swaps=NA_thresh=NA_filt=NA.tif",
Expand All @@ -67,38 +71,37 @@ test_that("brightness_folder works", {
) %in%
list.files("brightness"))
)
filesstrings::create_dir("tempwithintemp")
ijtiff::write_tif(img, "tempwithintemp/50.tif")
brightness_file("tempwithintemp/50.tif", def = "b")
suppressMessages(filesstrings::create_dir("tempwithintemp"))
ijtiff::write_tif(img, "tempwithintemp/50.tif", msg = FALSE)
suppressMessages(brightness_file("tempwithintemp/50.tif", def = "b"))
expect_true(any(stringr::str_detect(
dir("tempwithintemp/brightness"),
"^50_brightness_B.*tif$"
)))
brightness_file("tempwithintemp/50.tif", def = "E")
suppressMessages(brightness_file("tempwithintemp/50.tif", def = "E"))
expect_true(any(stringr::str_detect(
dir("tempwithintemp/brightness"),
"^50_brightness_epsilon.*tif$"
)))
filesstrings::dir.remove("tempwithintemp")
filesstrings::dir.remove("brightness")
suppressMessages(filesstrings::dir.remove("tempwithintemp"))
suppressMessages(filesstrings::dir.remove("brightness"))
suppressWarnings(file.remove(list.files()))
setwd(cwd)
})

context("brightness_timeseries()")
test_that("brightness_timeseries works", {
set.seed(1)
img <- system.file("extdata", "50.tif", package = "nandb")
b <- brightness(img, "e")
b <- suppressMessages(brightness(img, "e"))
bts <- brightness_timeseries(img, "e", 20,
thresh = "Huang", detrend = FALSE, filt = "median"
)
expect_equal(mean(bts, na.rm = TRUE), -0.013, tolerance = 0.005)
expect_equal(mean(bts, na.rm = TRUE), -0.013, tolerance = 0.2)
bts_overlapped <- brightness_timeseries(img, "e", 20,
overlap = TRUE,
thresh = "Huang", detrend = FALSE, filt = "median"
)
img %<>% ijtiff::read_tif()
img %<>% ijtiff::read_tif(msg = FALSE)
common_frames <- which(seq_len(dim(img)[4]) %% 20 == 0) - 20 + 1
expect_equal(
bts_overlapped[, , , common_frames, drop = FALSE] %>% {
Expand All @@ -120,16 +123,13 @@ test_that("brightness_timeseries works", {
}
)
expect_equal(median(bts, na.rm = TRUE), median(bts_overlapped, na.rm = TRUE),
tolerance = min(abs(c(
median(bts, na.rm = TRUE),
median(bts_overlapped, na.rm = TRUE)
))) / 10
tolerance = 0.2
)
bts <- brightness_timeseries(img, "B", 30,
detrend = TRUE,
thresh = "tri", filt = "median"
)
expect_equal(mean(bts, na.rm = TRUE), 1.01, tolerance = 0.006)
expect_equal(mean(bts, na.rm = TRUE), 1.01, tolerance = 0.2)
expect_error(
brightness_timeseries(img, "b", 51),
paste0(
Expand Down Expand Up @@ -169,11 +169,10 @@ test_that("brightness_timeseries works", {
)
cwd <- setwd(tempdir())
on.exit(setwd(cwd))
ijtiff::write_tif(img, "50.tif")
ijtiff::write_tif(img, "50again.tif")
context("brightness_timeseries_folder()")
filesstrings::create_dir("tempwithintemp")
ijtiff::write_tif(img, "tempwithintemp/50.tif")
ijtiff::write_tif(img, "50.tif", msg = FALSE)
ijtiff::write_tif(img, "50again.tif", msg = FALSE)
suppressMessages(filesstrings::create_dir("tempwithintemp"))
ijtiff::write_tif(img, "tempwithintemp/50.tif", msg = FALSE)
brightness_timeseries_file("tempwithintemp/50.tif",
def = "b",
frames_per_set = 10
Expand All @@ -190,7 +189,7 @@ test_that("brightness_timeseries works", {
dir("tempwithintemp/brightness_timeseries"),
"^50_brightness_epsilon_contiguous_timeseries.*tif$"
)))
filesstrings::dir.remove("tempwithintemp")
suppressMessages(filesstrings::dir.remove("tempwithintemp"))
set.seed(1)
brightness_timeseries_folder(def = "b", thresh = "tri", frames_per_set = 20)
expect_true(dir.exists("brightness_timeseries"))
Expand Down Expand Up @@ -242,7 +241,7 @@ test_that("brightness_timeseries works", {
),
2
)
filesstrings::dir.remove("brightness_timeseries")
suppressMessages(filesstrings::dir.remove("brightness_timeseries"))
suppressWarnings(file.remove(list.files())) # cleanup
setwd(cwd)
})
Loading

0 comments on commit 65903dd

Please sign in to comment.