Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CATALYST-project committed Jun 20, 2024
1 parent 2977afb commit dd0f2a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: SpatialExperiment
Version: 1.15.0
Version: 1.15.1
Title: S4 Class for Spatially Resolved -omics Data
Description: Defines an S4 class for storing data from spatial -omics experiments.
The class extends SingleCellExperiment to
Expand Down
11 changes: 10 additions & 1 deletion R/imgData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
# - NULL return first available entry
# - character string returns matching entry(ies)
.get_img_idx <- function(x, sample_id=NULL, image_id=NULL) {
# TODO: validity checks
img <- imgData(x)
for (i in c("sample_id", "image_id")) {
j <- get(i)
if (is.factor(j) || is.numeric(j))
assign(i, as.character(j))
if (!(is.null(j) || j %in% img[[i]] ||
length(j) == 1 && is.logical(j)))
stop(sprintf(c(
"'%s' invalid; should be NULL, TRUE/FALSE,",
" or matching entries in imgData(.)$%s"), i))
}
if (is.character(sample_id) && is.character(image_id)) {
sid <- img$sample_id == sample_id
iid <- img$image_id == image_id
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_imgData-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ test_that("getImg,sample_id=image_id=TRUE returns a list", {
expect_identical(x, y)
})

test_that("getImg handles non-character sample/image_id (#151)", {
. <- (spe$sample_id <- factor(spe$sample_id))[1]
expect_silent(getImg(spe, sample_id=.))
. <- (spe$sample_id <- as.integer(spe$sample_id))[1]
expect_silent(getImg(spe, sample_id=.))
. <- imgData(spe)$image_id <- 1
expect_silent(getImg(spe, image_id=.))
expect_silent(getImg(spe, image_id=as.factor(.)))
})

# addImg -----------------------------------------------------------------------

test_that("addImg for existing sample_id,image_id throws error", {
Expand Down

0 comments on commit dd0f2a4

Please sign in to comment.