Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,14 @@ Authors@R: c(
person("Vince", "Carey",
role=c("aut"),
email="stvjc@channing.harvard.edu",
comment=c(ORCID="0000-0003-4046-0063")),
person("Charlotte", "Soneson",
role=c("aut"),
email="charlotte.soneson@fmi.ch",
comment=c(ORCID="0000-0003-3833-2169")),
person("Michael", "Stadler",
role=c("aut"),
email="michael.stadler@fmi.ch",
comment=c(ORCID="0000-0002-2269-4934")),
person("Samuel", "Gunz",
role=c("aut"),
email="samuel.gunz@uzh.ch",
comment=c(ORCID="0000-0002-8909-0932")),
person("Yixing E.", "Dong",
role=c("aut"),
email="estelladong729@gmail.com",
comment=c(ORCID="0009-0003-5115-5686")),
person("Dario", "Righelli",
role=c("aut"),
email="dario.righelli@gmail.com",
comment=c(ORCID="0000-0003-1504-3583")),
person("Louise", "Deconinck",
role=c("aut"),
email="louise.deconinck@gmail.com",
comment=c(ORCID="0000-0001-8100-6823")))
comment=c(ORCID="0000-0003-4046-0063")))
Imports:
anndataR (>= 1.1.3),
BiocGenerics,
DBI,
DelayedArray,
dplyr,
duckspatial,
EBImage,
graph,
Matrix,
methods,
Expand All @@ -73,8 +48,8 @@ Imports:
ZarrArray
Suggests:
BiocStyle,
EBImage,
knitr,
paws,
Rgraphviz,
testthat
biocViews:
Expand Down
6 changes: 4 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ exportMethods(translation)
importFrom(BiocGenerics,as.data.frame)
importFrom(BiocGenerics,colnames)
importFrom(BiocGenerics,combine)
importFrom(BiocGenerics,data)
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)
Expand All @@ -131,7 +134,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)
Expand Down
10 changes: 2 additions & 8 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----

Expand All @@ -83,11 +79,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"))
Expand Down
3 changes: 2 additions & 1 deletion R/CTutils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(.ome_ver(x), error=\(e) "9.9"),
"0.3"=x$ome[[ms]][[1]][[ct]] <- new,
x[[ms]][[1]][[ct]] <- new)
}
Expand Down
11 changes: 3 additions & 8 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions R/sdArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ setMethod("data_type", "DelayedArray", \(x) {
# internal use only!
#' @noRd
.ch <- \(x) {
if (.zv(x) == "0.3") x <- x$ome
v <- tryCatch(.ome_ver(x), error=\(e) NULL)
if (is.null(v)) return()
if (v == "0.5") x <- x$ome
unlist(x$omero$channels)
}

Expand All @@ -133,12 +135,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)
}

Expand Down
17 changes: 12 additions & 5 deletions R/sdAttrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,24 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]])

# internal use only!
#' @noRd
.zv <- \(x) {
v <- x$spatialdata_attrs$version
.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 %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) switch(.zv(x), "0.3"=x$ome$multiscales, x$multiscales)
.ms <- \(x) {
v <- tryCatch(.ome_ver(x), error=\(e) NULL)
if (is.null(v)) return()
switch(v, "0.5"=x$ome$multiscales, x$multiscales)
}

# internal use only!
#' @noRd
Expand Down
23 changes: 13 additions & 10 deletions R/trans.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand All @@ -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
Expand Down Expand Up @@ -108,9 +109,11 @@ 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) {
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)
Expand Down Expand Up @@ -151,8 +154,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
Expand Down Expand Up @@ -204,14 +207,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
Expand Down
14 changes: 10 additions & 4 deletions R/validity.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@
.validateImage <- \(object) {
msg <- c()
res <- length(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)) != 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"))
}
Expand All @@ -65,10 +68,13 @@ setValidity2("SpatialDataImage", .validateImage)
.validateLabel <- \(object) {
msg <- c()
res <- length(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)) != 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"))
}
Expand Down
3 changes: 2 additions & 1 deletion inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
changes in version 0.99.38

- use BiocGenerics::table
- make use of new BiocGenerics:
data,rotate,scale,sequence,table,transform

changes in version 0.99.37

Expand Down
4 changes: 2 additions & 2 deletions man/SpatialData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions man/trans.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/test-combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-sdattrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"), {
Expand Down Expand Up @@ -48,4 +46,4 @@ for (v in names(z)) {
expect_length(z, dim(y)[1])
})

}
}
Loading