From 43039b2cb76c86fe6afb9974b26cff849fe81633 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Thu, 28 May 2026 17:16:54 +0200 Subject: [PATCH 1/9] support >2/3D --- NAMESPACE | 1 - R/sdArray.R | 4 ++-- R/sdAttrs.R | 5 ++++- R/validity.R | 10 ++++++---- man/SpatialData.Rd | 6 ++++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 1643cccc..fdfe35ef 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -130,7 +130,6 @@ importFrom(Rarr,zarr_overview) importFrom(S4Vectors,"metadata<-") importFrom(S4Vectors,DataFrame) importFrom(S4Vectors,coolcat) -importFrom(S4Vectors,isSequence) importFrom(S4Vectors,make_zero_col_DFrame) importFrom(S4Vectors,metadata) importFrom(S4Vectors,setValidity2) diff --git a/R/sdArray.R b/R/sdArray.R index bc4ac5c6..dde5a940 100644 --- a/R/sdArray.R +++ b/R/sdArray.R @@ -133,12 +133,12 @@ setMethod("channels", "SpatialDataImage", \(x, ...) channels(meta(x))) setMethod("channels", "SpatialDataElement", \(x, ...) stop("only 'images' have channels")) # compares metadata dataset paths to arrays on disk -#' @importFrom S4Vectors isSequence .validate_multiscales_paths <- function(x, ds) { ps <- list.files(x) ds <- ds[ds %in% ps] if (!length(ds)) - stop("Invalid SpatialData image or label: metadata does not match the names of Zarr arrays") + stop("Invalid 'SpatialData' image or label:", + " metadata does not match the names of Zarr arrays") return(ds) } diff --git a/R/sdAttrs.R b/R/sdAttrs.R index 8d03ae1b..16801f1b 100644 --- a/R/sdAttrs.R +++ b/R/sdAttrs.R @@ -127,7 +127,10 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]]) # internal use only! #' @noRd .zv <- \(x) { - v <- x$spatialdata_attrs$version + v <- x$ome$version %||% + x$omero$version %||% + x$multiscales[[1]]$version %||% + x$spatialdata_attrs$version if (!length(v)) stop("couldn't find 'version' in 'spatialdata_attrs'") ok <- length(v) == 1 && is.character(v) && v %in% sprintf("0.%d", seq_len(5)) if (!ok) stop("invalid 'version' in 'spatialdata_attrs'; expected '0.x' where x is 1-5") diff --git a/R/validity.R b/R/validity.R index 7906e3d6..c757c52c 100644 --- a/R/validity.R +++ b/R/validity.R @@ -49,10 +49,11 @@ .validateImage <- \(object) { msg <- c() res <- length(object) + d <- length(dim(object)) for (k in seq_len(res)) { x <- data(object, k) - if (length(dim(x)) != 3) msg <- c(msg, paste( - "'SpatialDataImage' resolution", k, "is not 3D")) + if (length(dim(x)) != d) msg <- c(msg, paste( + "'SpatialDataImage' resolution", k, "is not ", d, "D")) if (!type(x) %in% c("double", "integer")) msg <- c(msg, paste( "'SpatialDataImage' resolution", k, "is not of type double or integer")) } @@ -65,10 +66,11 @@ setValidity2("SpatialDataImage", .validateImage) .validateLabel <- \(object) { msg <- c() res <- length(object) + d <- length(axes(object)) for (k in seq_len(res)) { x <- data(object, k) - if (length(dim(x)) != 2) msg <- c(msg, paste( - "'SpatialDataLabel' resolution", k, "is not 2D")) + if (length(dim(x)) != d) msg <- c(msg, paste( + "'SpatialDataLabel' resolution", k, "is not ", d, "D")) if (type(x) != "integer") msg <- c(msg, paste( "'SpatialDataLabel' resolution", k, "is not of type integer")) } diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index 7390113d..f377ade8 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -63,6 +63,8 @@ \alias{points,SpatialData-method} \alias{shapes,SpatialData-method} \alias{tables,SpatialData-method} +\alias{[[<-,SpatialData,numeric,ANY,ANY-method} +\alias{[[<-,SpatialData,character,ANY,ANY-method} \title{The `SpatialData` class} \usage{ SpatialData(images, labels, points, shapes, tables) @@ -109,9 +111,9 @@ SpatialData(images, labels, points, shapes, tables) \S4method{tables}{SpatialData}(x) -\S4method{[[}{SpatialData,numeric,ANY}(x, i) <- value +\S4method{[[}{SpatialData,numeric,ANY,ANY}(x, i) <- value -\S4method{[[}{SpatialData,character,ANY}(x, i) <- value +\S4method{[[}{SpatialData,character,ANY,ANY}(x, i) <- value } \arguments{ \item{images}{list of \code{\link{SpatialDataImage}}s} From 71514b26f168f6842d3dbbae42fb88b86ea5df6e Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Fri, 29 May 2026 09:01:09 +0200 Subject: [PATCH 2/9] fix tests; use new BiocGenerics --- NAMESPACE | 4 +++- R/AllGenerics.R | 6 +++--- R/sdAttrs.R | 9 +++++---- R/trans.R | 21 +++++++++++---------- R/validity.R | 8 ++++++-- man/SpatialData.Rd | 6 ++---- man/trans.Rd | 20 ++++++++++---------- tests/testthat/test-sdattrs.R | 4 +--- 8 files changed, 41 insertions(+), 37 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 4c0c716f..2b7e109e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -115,12 +115,14 @@ exportMethods(translation) importFrom(BiocGenerics,as.data.frame) importFrom(BiocGenerics,colnames) importFrom(BiocGenerics,combine) +importFrom(BiocGenerics,rotate) importFrom(BiocGenerics,rownames) +importFrom(BiocGenerics,scale) +importFrom(BiocGenerics,sequence) importFrom(BiocGenerics,table) importFrom(BiocGenerics,transform) importFrom(DBI,dbIsValid) importFrom(DelayedArray,DelayedArray) -importFrom(EBImage,rotate) importFrom(Matrix,sparseMatrix) importFrom(Matrix,sparseVector) importFrom(Matrix,summary) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 1ab28674..88b269c6 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -57,9 +57,9 @@ setGeneric("CTgraph", \(x, ...) standardGeneric("CTgraph")) setGeneric("rmvCT", \(x, ...) standardGeneric("rmvCT")) setGeneric("addCT", \(x, ...) standardGeneric("addCT")) -setGeneric("scale", \(x, t, ...) standardGeneric("scale")) -setGeneric("rotate", \(x, t, ...) standardGeneric("rotate")) -setGeneric("sequence", \(x, t, ...) standardGeneric("sequence")) +#setGeneric("scale", \(x, t, ...) standardGeneric("scale")) +#setGeneric("rotate", \(x, t, ...) standardGeneric("rotate")) +#setGeneric("sequence", \(x, t, ...) standardGeneric("sequence")) setGeneric("translation", \(x, t, ...) standardGeneric("translation")) setGeneric("flip", \(x, ...) standardGeneric("flip")) diff --git a/R/sdAttrs.R b/R/sdAttrs.R index 16801f1b..018d5916 100644 --- a/R/sdAttrs.R +++ b/R/sdAttrs.R @@ -127,12 +127,13 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]]) # internal use only! #' @noRd .zv <- \(x) { - v <- x$ome$version %||% - x$omero$version %||% + v <- + x$spatialdata_attrs$version %||% x$multiscales[[1]]$version %||% - x$spatialdata_attrs$version + x$omero$version %||% + x$ome$version if (!length(v)) stop("couldn't find 'version' in 'spatialdata_attrs'") - ok <- length(v) == 1 && is.character(v) && v %in% sprintf("0.%d", seq_len(5)) + ok <- length(v) == 1 && is.character(v) && gsub("-.*", "", v) %in% sprintf("0.%d", seq_len(5)) if (!ok) stop("invalid 'version' in 'spatialdata_attrs'; expected '0.x' where x is 1-5") return(v) } diff --git a/R/trans.R b/R/trans.R index 2af78569..94f806fd 100644 --- a/R/trans.R +++ b/R/trans.R @@ -48,9 +48,9 @@ #' y["shapes", c("rot", "wide", "left")] NULL -#' @importFrom BiocGenerics transform #' @export #' @rdname trans +#' @importFrom BiocGenerics transform setMethod("transform", "SpatialDataElement", \(x, i=1, ...) { stopifnot( length(i) == 1, is.character(i) | @@ -70,7 +70,8 @@ setMethod("transform", "SpatialDataElement", \(x, i=1, ...) { #' @export #' @rdname trans -setMethod("sequence", c("SpatialDataElement", "list"), \(x, t, ..., rev=FALSE) { +#' @importFrom BiocGenerics sequence +setMethod("sequence", "SpatialDataElement", \(x, t, ..., rev=FALSE) { if (rev) t <- rev(t) for (. in seq_along(t)) { if (is.null(t[[.]])) next @@ -108,9 +109,9 @@ setMethod("flop", "SpatialDataArray", \(x, k=1, ...) .mirror(x, 90, k)) #' @export #' @rdname trans #' @importFrom methods as -#' @importFrom EBImage rotate +#' @importFrom BiocGenerics rotate #' @importFrom S4Vectors metadata<- -setMethod("rotate", c("SpatialDataArray", "numeric"), \(x, t, k=1, ..., rev=FALSE) { +setMethod("rotate", "SpatialDataArray", \(x, t, k=1, ..., rev=FALSE) { # negate angle since 'EBImage' rotates clockwise stopifnot(length(t) == 1, is.finite(t)) if (t %% 360 == 0) return(x) @@ -151,8 +152,8 @@ setMethod("rotate", c("SpatialDataArray", "numeric"), \(x, t, k=1, ..., rev=FALS #' @export #' @rdname trans -setMethod("scale", - c("SpatialDataArray", "numeric"), +#' @importFrom BiocGenerics scale +setMethod("scale", "SpatialDataArray", \(x, t, ...) .trans_a(x, t, "scale", ...)) #' @export @@ -204,14 +205,14 @@ setMethod("translation", #' @export #' @rdname trans -setMethod("rotate", - c("SpatialDataFrame", "numeric"), +#' @importFrom BiocGenerics rotate +setMethod("rotate", "SpatialDataFrame", \(x, t, ...) .trans_f(x, t, "rotate", ...)) #' @export #' @rdname trans -setMethod("scale", - c("SpatialDataFrame", "numeric"), +#' @importFrom BiocGenerics scale +setMethod("scale", "SpatialDataFrame", \(x, t, ...) .trans_f(x, t, "scale", ...)) #' @export diff --git a/R/validity.R b/R/validity.R index c757c52c..d609fc92 100644 --- a/R/validity.R +++ b/R/validity.R @@ -49,7 +49,9 @@ .validateImage <- \(object) { msg <- c() res <- length(object) - d <- length(dim(object)) + axs <- axes(object) + typ <- vapply(axs, \(.) .$type, character(1)) + d <- sum(typ != "time") for (k in seq_len(res)) { x <- data(object, k) if (length(dim(x)) != d) msg <- c(msg, paste( @@ -66,7 +68,9 @@ setValidity2("SpatialDataImage", .validateImage) .validateLabel <- \(object) { msg <- c() res <- length(object) - d <- length(axes(object)) + axs <- axes(object) + typ <- vapply(axs, \(.) .$type, character(1)) + d <- sum(typ == "space") for (k in seq_len(res)) { x <- data(object, k) if (length(dim(x)) != d) msg <- c(msg, paste( diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index f377ade8..7390113d 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -63,8 +63,6 @@ \alias{points,SpatialData-method} \alias{shapes,SpatialData-method} \alias{tables,SpatialData-method} -\alias{[[<-,SpatialData,numeric,ANY,ANY-method} -\alias{[[<-,SpatialData,character,ANY,ANY-method} \title{The `SpatialData` class} \usage{ SpatialData(images, labels, points, shapes, tables) @@ -111,9 +109,9 @@ SpatialData(images, labels, points, shapes, tables) \S4method{tables}{SpatialData}(x) -\S4method{[[}{SpatialData,numeric,ANY,ANY}(x, i) <- value +\S4method{[[}{SpatialData,numeric,ANY}(x, i) <- value -\S4method{[[}{SpatialData,character,ANY,ANY}(x, i) <- value +\S4method{[[}{SpatialData,character,ANY}(x, i) <- value } \arguments{ \item{images}{list of \code{\link{SpatialDataImage}}s} diff --git a/man/trans.Rd b/man/trans.Rd index 447ec9a2..1555c6ec 100644 --- a/man/trans.Rd +++ b/man/trans.Rd @@ -11,21 +11,21 @@ \alias{mirror} \alias{sequence} \alias{transform,SpatialDataElement-method} -\alias{sequence,SpatialDataElement,list-method} +\alias{sequence,SpatialDataElement-method} \alias{mirror,SpatialDataArray-method} \alias{flip,SpatialDataArray-method} \alias{flop,SpatialDataArray-method} -\alias{rotate,SpatialDataArray,numeric-method} -\alias{scale,SpatialDataArray,numeric-method} +\alias{rotate,SpatialDataArray-method} +\alias{scale,SpatialDataArray-method} \alias{translation,SpatialDataArray,numeric-method} -\alias{rotate,SpatialDataFrame,numeric-method} -\alias{scale,SpatialDataFrame,numeric-method} +\alias{rotate,SpatialDataFrame-method} +\alias{scale,SpatialDataFrame-method} \alias{translation,SpatialDataFrame,numeric-method} \title{Transformations} \usage{ \S4method{transform}{SpatialDataElement}(x, i = 1, ...) -\S4method{sequence}{SpatialDataElement,list}(x, t, ..., rev = FALSE) +\S4method{sequence}{SpatialDataElement}(x, t, ..., rev = FALSE) \S4method{mirror}{SpatialDataArray}(x, t = c("v", "h"), k = 1, ...) @@ -33,15 +33,15 @@ \S4method{flop}{SpatialDataArray}(x, k = 1, ...) -\S4method{rotate}{SpatialDataArray,numeric}(x, t, k = 1, ..., rev = FALSE) +\S4method{rotate}{SpatialDataArray}(x, t, k = 1, ..., rev = FALSE) -\S4method{scale}{SpatialDataArray,numeric}(x, t, ...) +\S4method{scale}{SpatialDataArray}(x, t, ...) \S4method{translation}{SpatialDataArray,numeric}(x, t, ...) -\S4method{rotate}{SpatialDataFrame,numeric}(x, t, ...) +\S4method{rotate}{SpatialDataFrame}(x, t, ...) -\S4method{scale}{SpatialDataFrame,numeric}(x, t, ...) +\S4method{scale}{SpatialDataFrame}(x, t, ...) \S4method{translation}{SpatialDataFrame,numeric}(x, t, ...) } diff --git a/tests/testthat/test-sdattrs.R b/tests/testthat/test-sdattrs.R index 0424164a..63cc1fca 100644 --- a/tests/testthat/test-sdattrs.R +++ b/tests/testthat/test-sdattrs.R @@ -11,8 +11,6 @@ for (v in names(z)) { z <- multiscales(y) expect_is(z, "list") expect_length(z, 1) - y$spatialdata_attrs <- NULL - expect_error(multiscales(y)) }) test_that(paste0(v, "-axes"), { @@ -48,4 +46,4 @@ for (v in names(z)) { expect_length(z, dim(y)[1]) }) -} \ No newline at end of file +} From 02106e89a284521cca7fd9bc0a21e29af8557081 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Fri, 29 May 2026 09:27:27 +0200 Subject: [PATCH 3/9] revise ome(ro) version retrieval --- R/CTutils.R | 3 ++- R/sdArray.R | 2 +- R/sdAttrs.R | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/R/CTutils.R b/R/CTutils.R index 09c09dc3..5f281096 100644 --- a/R/CTutils.R +++ b/R/CTutils.R @@ -219,7 +219,8 @@ setMethod("addCT", "SpatialDataAttrs", \(x, name, type="identity", data=NULL) { if (is.null(multiscales(x))) { x[[ct]] <- new } else { - switch(.zv(x), + switch( + tryCatch(.zv(x), error=\(e) "9.9"), "0.3"=x$ome[[ms]][[1]][[ct]] <- new, x[[ms]][[1]][[ct]] <- new) } diff --git a/R/sdArray.R b/R/sdArray.R index dde5a940..3b21c056 100644 --- a/R/sdArray.R +++ b/R/sdArray.R @@ -116,7 +116,7 @@ setMethod("data_type", "DelayedArray", \(x) { # internal use only! #' @noRd .ch <- \(x) { - if (.zv(x) == "0.3") x <- x$ome + if (.zv(x) == "0.5") x <- x$ome unlist(x$omero$channels) } diff --git a/R/sdAttrs.R b/R/sdAttrs.R index 018d5916..5e52a750 100644 --- a/R/sdAttrs.R +++ b/R/sdAttrs.R @@ -128,19 +128,22 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]]) #' @noRd .zv <- \(x) { v <- - x$spatialdata_attrs$version %||% x$multiscales[[1]]$version %||% - x$omero$version %||% + x$omero$version %||% x$ome$version if (!length(v)) stop("couldn't find 'version' in 'spatialdata_attrs'") - ok <- length(v) == 1 && is.character(v) && gsub("-.*", "", v) %in% sprintf("0.%d", seq_len(5)) + ok <- length(v) == 1 && is.character(v) && (v <- gsub("-.*", "", v)) %in% sprintf("0.%d", seq_len(5)) if (!ok) stop("invalid 'version' in 'spatialdata_attrs'; expected '0.x' where x is 1-5") return(v) } # internal use only! #' @noRd -.ms <- \(x) switch(.zv(x), "0.3"=x$ome$multiscales, x$multiscales) +.ms <- \(x) { + v <- tryCatch(.zv(x), error=\(e) NULL) + if (is.null(v)) return() + switch(v, "0.5"=x$ome$multiscales, x$multiscales) +} # internal use only! #' @noRd From e2acbbd39e142067f32d3c2e24dc73d0216b82ba Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Fri, 29 May 2026 10:49:00 +0200 Subject: [PATCH 4/9] remove praws, move EBImage to Suggests: --- DESCRIPTION | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9d87adbd..eab83ee8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -58,7 +58,6 @@ Imports: DelayedArray, dplyr, duckspatial, - EBImage, graph, Matrix, methods, @@ -73,8 +72,8 @@ Imports: ZarrArray Suggests: BiocStyle, + EBImage, knitr, - paws, Rgraphviz, testthat biocViews: From faa0884974920a320b152e482afae1417f875c5d Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Fri, 29 May 2026 10:49:12 +0200 Subject: [PATCH 5/9] fix version retrieval for frames --- R/sdArray.R | 4 +++- R/trans.R | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/R/sdArray.R b/R/sdArray.R index 3b21c056..5fd42c64 100644 --- a/R/sdArray.R +++ b/R/sdArray.R @@ -116,7 +116,9 @@ setMethod("data_type", "DelayedArray", \(x) { # internal use only! #' @noRd .ch <- \(x) { - if (.zv(x) == "0.5") x <- x$ome + v <- tryCatch(.zv(x), error=\(e) NULL) + if (is.null(v)) return() + if (v == "0.5") x <- x$ome unlist(x$omero$channels) } diff --git a/R/trans.R b/R/trans.R index 94f806fd..e4109511 100644 --- a/R/trans.R +++ b/R/trans.R @@ -112,6 +112,8 @@ setMethod("flop", "SpatialDataArray", \(x, k=1, ...) .mirror(x, 90, k)) #' @importFrom BiocGenerics rotate #' @importFrom S4Vectors metadata<- setMethod("rotate", "SpatialDataArray", \(x, t, k=1, ..., rev=FALSE) { + if (!requireNamespace("EBImage", quietly=TRUE)) + stop("install 'EBImage' to use this function") # negate angle since 'EBImage' rotates clockwise stopifnot(length(t) == 1, is.finite(t)) if (t %% 360 == 0) return(x) From 67f1b14872940e064553d19c2e24a6472d3352ee Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Fri, 29 May 2026 11:06:43 +0200 Subject: [PATCH 6/9] fix combine test --- tests/testthat/test-combine.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-combine.R b/tests/testthat/test-combine.R index 72f7af00..b52fe302 100644 --- a/tests/testthat/test-combine.R +++ b/tests/testthat/test-combine.R @@ -4,7 +4,6 @@ x <- readSpatialData(x) test_that("combine", { # auto-fixed names - expect_error(combine(x)) expect_no_message(y <- combine(x, x)) f <- \(.) unlist(colnames(.)) expect_all_true(f(x) %in% f(y)) From 1fc8a5658a3da86e499e01893824296ac5b140e3 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Fri, 29 May 2026 15:58:32 +0200 Subject: [PATCH 7/9] address HG comments --- R/AllGenerics.R | 6 +----- R/CTutils.R | 2 +- R/sdArray.R | 2 +- R/sdAttrs.R | 8 ++++---- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 88b269c6..2e3bea24 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -57,14 +57,10 @@ setGeneric("CTgraph", \(x, ...) standardGeneric("CTgraph")) setGeneric("rmvCT", \(x, ...) standardGeneric("rmvCT")) setGeneric("addCT", \(x, ...) standardGeneric("addCT")) -#setGeneric("scale", \(x, t, ...) standardGeneric("scale")) -#setGeneric("rotate", \(x, t, ...) standardGeneric("rotate")) -#setGeneric("sequence", \(x, t, ...) standardGeneric("sequence")) -setGeneric("translation", \(x, t, ...) standardGeneric("translation")) - setGeneric("flip", \(x, ...) standardGeneric("flip")) setGeneric("flop", \(x, ...) standardGeneric("flop")) setGeneric("mirror", \(x, ...) standardGeneric("mirror")) +setGeneric("translation", \(x, t, ...) standardGeneric("translation")) # sda ---- diff --git a/R/CTutils.R b/R/CTutils.R index 5f281096..5c471d58 100644 --- a/R/CTutils.R +++ b/R/CTutils.R @@ -220,7 +220,7 @@ setMethod("addCT", "SpatialDataAttrs", \(x, name, type="identity", data=NULL) { x[[ct]] <- new } else { switch( - tryCatch(.zv(x), error=\(e) "9.9"), + tryCatch(.ome_ver(x), error=\(e) "9.9"), "0.3"=x$ome[[ms]][[1]][[ct]] <- new, x[[ms]][[1]][[ct]] <- new) } diff --git a/R/sdArray.R b/R/sdArray.R index 5fd42c64..12aaf696 100644 --- a/R/sdArray.R +++ b/R/sdArray.R @@ -116,7 +116,7 @@ setMethod("data_type", "DelayedArray", \(x) { # internal use only! #' @noRd .ch <- \(x) { - v <- tryCatch(.zv(x), error=\(e) NULL) + v <- tryCatch(.ome_ver(x), error=\(e) NULL) if (is.null(v)) return() if (v == "0.5") x <- x$ome unlist(x$omero$channels) diff --git a/R/sdAttrs.R b/R/sdAttrs.R index 5e52a750..7f6ae526 100644 --- a/R/sdAttrs.R +++ b/R/sdAttrs.R @@ -126,21 +126,21 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]]) # internal use only! #' @noRd -.zv <- \(x) { +.ome_ver <- \(x) { v <- x$multiscales[[1]]$version %||% x$omero$version %||% x$ome$version if (!length(v)) stop("couldn't find 'version' in 'spatialdata_attrs'") - ok <- length(v) == 1 && is.character(v) && (v <- gsub("-.*", "", v)) %in% sprintf("0.%d", seq_len(5)) - if (!ok) stop("invalid 'version' in 'spatialdata_attrs'; expected '0.x' where x is 1-5") + ok <- length(v) == 1 && is.character(v) && (v <- gsub("-.*", "", v)) %in% sprintf("0.%d", seq_len(6)) + if (!ok) stop("invalid OME 'version'; expected '0.x' where x is 1-5") return(v) } # internal use only! #' @noRd .ms <- \(x) { - v <- tryCatch(.zv(x), error=\(e) NULL) + v <- tryCatch(.ome_ver(x), error=\(e) NULL) if (is.null(v)) return() switch(v, "0.5"=x$ome$multiscales, x$multiscales) } From d97d035b9dfa3ee31bc27d549d684eb8af93c214 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Sat, 30 May 2026 10:41:12 +0200 Subject: [PATCH 8/9] use BiocGenerics::data --- NAMESPACE | 1 + R/AllGenerics.R | 4 +--- R/methods.R | 11 +++-------- man/SpatialData.Rd | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 6563c390..33a80a63 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -115,6 +115,7 @@ exportMethods(translation) importFrom(BiocGenerics,as.data.frame) importFrom(BiocGenerics,colnames) importFrom(BiocGenerics,combine) +importFrom(BiocGenerics,data) importFrom(BiocGenerics,rownames) importFrom(BiocGenerics,table) importFrom(BiocGenerics,transform) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 1ab28674..ad04d4d5 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -83,11 +83,9 @@ setGeneric("instance_key<-", \(x, value) standardGeneric("instance_key<-")) # uts ---- -setGeneric("data", \(...) standardGeneric("data")) setGeneric("meta", \(x, ...) standardGeneric("meta")) - -setGeneric("data<-", \(x, ..., value) standardGeneric("data<-")) setGeneric("meta<-", \(x, ..., value) standardGeneric("meta<-")) +setGeneric("data<-", \(x, ..., value) standardGeneric("data<-")) setGeneric("layer", \(x, i, ...) standardGeneric("layer")) setGeneric("element", \(x, i, ...) standardGeneric("element")) diff --git a/R/methods.R b/R/methods.R index 6e26ef21..1f341393 100644 --- a/R/methods.R +++ b/R/methods.R @@ -27,15 +27,10 @@ setMethod("[[", c("SpatialData", "character"), \(x, i, ...) attr(x, i)) #' @export #' @rdname SpatialData -setMethod("data", "ANY", \(...) { - l <- list(...) - x <- l[[1]] - if (!is(x, "SpatialDataElement")) - return(utils::data(...)) - if (!is(x, "SpatialDataArray")) - return(x@data) +#' @importFrom BiocGenerics data +setMethod("data", "SpatialDataElement", \(x, k=1, ...) { + if (!is(x, "SpatialDataArray")) return(x@data) # return list of available scales - k <- if (length(l) == 1) 1 else l[[2]] if (is.null(k)) return(x@data) # should be a scalar positive integer ok <- length(k) == 1 && is.numeric(k) && k > 0 && k == round(k) diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index 7390113d..bcf65623 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -46,7 +46,7 @@ \alias{$<-,SpatialData-method} \alias{[[,SpatialData,numeric,ANY-method} \alias{[[,SpatialData,character,ANY-method} -\alias{data,ANY-method} +\alias{data,SpatialDataElement-method} \alias{meta,SpatialDataElement-method} \alias{[,SpatialData,ANY,ANY,ANY-method} \alias{rownames,SpatialData-method} @@ -75,7 +75,7 @@ SpatialData(images, labels, points, shapes, tables) \S4method{[[}{SpatialData,character,ANY}(x, i, j, ...) -\S4method{data}{ANY}(...) +\S4method{data}{SpatialDataElement}(x, k = 1, ...) \S4method{meta}{SpatialDataElement}(x) From 31a66cac2296063f1a816d3fde5576cd490f17c9 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Sat, 30 May 2026 11:01:37 +0200 Subject: [PATCH 9/9] fix typo --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c7104712..dc81ffe6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,7 +26,7 @@ Authors@R: c( person("Vince", "Carey", role=c("aut"), email="stvjc@channing.harvard.edu", - comment=c(ORCID="0000-0003-4046-0063")) + comment=c(ORCID="0000-0003-4046-0063"))) Imports: anndataR (>= 1.1.3), BiocGenerics,