diff --git a/DESCRIPTION b/DESCRIPTION index d520a492..7ca09de1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -71,7 +71,8 @@ Imports: SingleCellExperiment, SummarizedExperiment, SparseArray, - ZarrArray + ZarrArray, + ImageArray Suggests: BiocStyle, knitr, diff --git a/NAMESPACE b/NAMESPACE index bc68ccaa..c27ee5bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,7 +10,6 @@ S3method(pull,sdFrame) S3method(select,sdFrame) export(.SpatialData) export(CTplot) -export(ImageArray) export(LabelArray) export(PointFrame) export(ShapeFrame) @@ -25,6 +24,7 @@ export(readPoint) export(readShape) export(readSpatialData) export(readTable) +export(sdImage) export(select) exportClasses(SpatialData) exportMethods("$") @@ -119,6 +119,7 @@ importFrom(BiocGenerics,combine) importFrom(BiocGenerics,rownames) importFrom(DelayedArray,DelayedArray) importFrom(EBImage,rotate) +importFrom(ImageArray,ImageArray) importFrom(Matrix,sparseMatrix) importFrom(Matrix,sparseVector) importFrom(Matrix,summary) diff --git a/R/AllClasses.R b/R/AllClasses.R index e448578d..8ab794d5 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -8,10 +8,10 @@ setClassUnion( "array_OR_df", c("Array", "array", "data.frame")) -.ImageArray <- setClass( - Class="ImageArray", +.sdImage <- setClass( + Class="sdImage", contains=c("Annotated"), - slots=list(data="list", meta="Zattrs")) + slots=list(data="ImageArray", meta="Zattrs")) .LabelArray <- setClass( Class="LabelArray", @@ -45,12 +45,12 @@ setClassUnion( contains=c("Annotated"), slots=list(data="arrow_OR_df", meta="Zattrs")) -setClassUnion("sdArray", c("ImageArray", "LabelArray")) +setClassUnion("sdArray", c("sdImage", "LabelArray")) setClassUnion("sdFrame", c("PointFrame", "ShapeFrame")) setClassUnion( "SpatialDataElement", - c("ImageArray", "LabelArray", "PointFrame", "ShapeFrame")) + c("sdImage", "LabelArray", "PointFrame", "ShapeFrame")) #' @rdname SpatialData #' @export @@ -58,7 +58,7 @@ setClassUnion( Class="SpatialData", contains=c("list", "Annotated"), representation( - images="list", # 'ImageArray's + images="list", # 'sdImage's labels="list", # 'LabelArray's points="list", # 'PointFrame's shapes="list", # 'ShapeFrame's diff --git a/R/ImageArray.R b/R/ImageArray.R index 73765f47..e40ccb1a 100644 --- a/R/ImageArray.R +++ b/R/ImageArray.R @@ -1,8 +1,8 @@ -#' @name ImageArray -#' @title The `ImageArray` class +#' @name sdImage +#' @title The `sdImage` class #' @aliases channels #' -#' @param x \code{ImageArray} +#' @param x \code{sdImage} #' @param data list of \code{\link[ZarrArray]{ZarrArray}}s #' @param meta \code{\link{Zattrs}} #' @param metadata optional list of arbitrary @@ -12,7 +12,7 @@ #' @param drop ignored. #' @param ... option arguments passed to and from other methods. #' -#' @return \code{ImageArray} +#' @return \code{sdImage} #' #' @examples #' zs <- file.path("extdata", "blobs.zarr") @@ -41,18 +41,18 @@ #' @importFrom S4Vectors metadata<- #' @importFrom methods new #' @export -ImageArray <- function(data=list(), meta=Zattrs(), metadata=list(), ...) { - x <- .ImageArray(data=data, meta=meta, ...) +sdImage <- function(data=list(), meta=Zattrs(), metadata=list(), ...) { + x <- .sdImage(data=data, meta=meta, ...) metadata(x) <- metadata return(x) } #' @export -#' @rdname ImageArray -setMethod("channels", "ImageArray", \(x, ...) channels(meta(x))) +#' @rdname sdImage +setMethod("channels", "sdImage", \(x, ...) channels(meta(x))) #' @export -#' @rdname ImageArray +#' @rdname sdImage setMethod("channels", "ANY", \(x, ...) stop("only 'images' have channels")) #' @importFrom S4Vectors isSequence @@ -66,7 +66,7 @@ setMethod("channels", "ANY", \(x, ...) stop("only 'images' have channels")) if (length(ps)) { qs <- seq(min(ps), max(ps)) if (!isTRUE(all.equal(ps, qs))) - stop("ImageArray paths are ill-defined, should", + stop("sdImage paths are ill-defined, should", " be an integer sequence, e.g., 0,1,...,n") } return(ps) @@ -82,13 +82,13 @@ setMethod("channels", "ANY", \(x, ...) stop("only 'images' have channels")) # validate 'paths' ok <- vapply(ds, \(.) !is.null(.$path), logical(1)) if (!all(ok)) - stop("'ImageArray' paths are ill-defined,", + stop("'sdImage' paths are ill-defined,", " no 'path' attribute under 'multiscale-datasets'") } else stop( - "'ImageArray' paths are ill-defined,", + "'sdImage' paths are ill-defined,", " no 'datasets' attribute under 'multiscale'") } else stop( - "'ImageArray' paths are ill-defined,", + "'sdImage' paths are ill-defined,", " no 'multiscales' attribute under '.zattrs'") return(ms) } @@ -106,24 +106,36 @@ setMethod("channels", "ANY", \(x, ...) stop("only 'images' have channels")) } #' @exportMethod [ -#' @rdname ImageArray +#' @rdname sdImage #' @importFrom utils head tail -setMethod("[", "ImageArray", \(x, i, j, k, ..., drop=FALSE) { - if (missing(i)) i <- TRUE - if (missing(j)) j <- TRUE else if (isFALSE(j)) j <- 0 else .check_jk(j, "j") - if (missing(k)) k <- TRUE else if (isFALSE(k)) k <- 0 else .check_jk(k, "k") - ijk <- list(i, j, k) - n <- length(data(x, NULL)) - d <- dim(data(x)) - data(x) <- lapply(seq_len(n), \(.) { - j <- if (isTRUE(j)) seq_len(d[2]) else j - k <- if (isTRUE(k)) seq_len(d[3]) else k - jk <- lapply(list(j, k), \(jk) { - fac <- 2^(.-1) - seq(floor(head(jk, 1)/fac), - ceiling(tail(jk, 1)/fac)) - }) - data(x, .)[i, jk[[1]], jk[[2]], drop=FALSE] - }) +setMethod("[", "sdImage", \(x, i, j, k, ..., drop=FALSE) { + # if (missing(i)) i <- TRUE + # if (missing(j)) j <- TRUE else if (isFALSE(j)) j <- 0 else .check_jk(j, "j") + # if (missing(k)) k <- TRUE else if (isFALSE(k)) k <- 0 else .check_jk(k, "k") + # ijk <- list(i, j, k) + # n <- length(data(x, NULL)) + # d <- dim(data(x)) + # data(x) <- lapply(seq_len(n), \(.) { + # j <- if (isTRUE(j)) seq_len(d[2]) else j + # k <- if (isTRUE(k)) seq_len(d[3]) else k + # jk <- lapply(list(j, k), \(jk) { + # fac <- 2^(.-1) + # seq(floor(head(jk, 1)/fac), + # ceiling(tail(jk, 1)/fac)) + # }) + # data(x, .)[i, jk[[1]], jk[[2]], drop=FALSE] + # }) + # x + # temp(x,i,j,k) + data(x) <- data(x, NULL)[,1:10,1:10] x }) + +temp <- function(x,i,j,k){ + print(1) + print(1) + print(1) + print(1) + print(1) + print(1) +} diff --git a/R/SpatialData.R b/R/SpatialData.R index d8427268..21aea2db 100644 --- a/R/SpatialData.R +++ b/R/SpatialData.R @@ -3,7 +3,7 @@ #' #' @description ... #' -#' @param images list of \code{\link{ImageArray}}s +#' @param images list of \code{\link{sdImage}}s #' @param labels list of \code{\link{LabelArray}}s #' @param points list of \code{\link{PointFrame}}s #' @param shapes list of \code{\link{ShapeFrame}}s diff --git a/R/mask.R b/R/mask.R index 477e2cc7..8d88d878 100644 --- a/R/mask.R +++ b/R/mask.R @@ -97,7 +97,7 @@ setGeneric(".mask", \(i, j, ...) standardGeneric(".mask")) #' @importFrom Matrix sparseVector #' @importFrom SummarizedExperiment assayNames<- #' @importFrom SingleCellExperiment SingleCellExperiment -setMethod(".mask", c("ImageArray", "LabelArray"), \(i, j, how=NULL, ...) { +setMethod(".mask", c("sdImage", "LabelArray"), \(i, j, how=NULL, ...) { if (is.null(how)) { how <- "mean"; message("Missing 'how'; defaulting to 'mean'") } stopifnot(dim(i)[-1] == dim(j)) .j <- as(data(j), "sparseVector") diff --git a/R/methods.R b/R/methods.R index 3b0832b0..eab06cc7 100644 --- a/R/methods.R +++ b/R/methods.R @@ -258,7 +258,7 @@ for (. in all) eval(f(.), parent.env(environment())) # set one ---- typ <- c( - image="ImageArray", label="LabelArray", + image="sdImage", label="LabelArray", point="PointFrame", shape="ShapeFrame", table="SingleCellExperiment") diff --git a/R/misc.R b/R/misc.R index b20695f2..89f777cd 100644 --- a/R/misc.R +++ b/R/misc.R @@ -95,7 +95,18 @@ setMethod("show", "SpatialData", .showSpatialData) } #' @rdname misc -setMethod("show", "sdArray", .showsdArray) +setMethod("show", "LabelArray", .showsdArray) + +#' @importFrom S4Vectors coolcat +.showsdImage <- function(object) { + n.object <- length(object@data) + cat("class: ", class(object), ifelse(n.object > 1, "(MultiScale)", ""),"\n") + scales <- vapply(levels(object@data), \(x) paste0(dim(x), collapse=","), character(1)) + coolcat("Scales (%d): (%s)", scales) +} + +#' @rdname misc +setMethod("show", "sdImage", .showsdImage) #' @importFrom S4Vectors coolcat .showPointFrame <- function(object) { diff --git a/R/read.R b/R/read.R index edcefc98..a8dd67ff 100644 --- a/R/read.R +++ b/R/read.R @@ -21,7 +21,7 @@ #' @return #' \itemize{ #' \item{For \code{readSpatialData}, a \code{SpatialData}.}, -#' \item{For element readers, a \code{ImageArray}, \code{LabelArray}, +#' \item{For element readers, a \code{sdImage}, \code{LabelArray}, #' \code{PointFrame}, \code{ShapeFrame}, or \code{SingleCellExperiment}.}} #' #' @examples @@ -56,10 +56,17 @@ NULL } #' @rdname readSpatialData +#' @importFrom ImageArray ImageArray #' @export readImage <- function(x, ...) { - l <- .readArray(x, ...) - ImageArray(data=l$array, meta=Zattrs(l$md), ...) + # l <- .readArray(x, ...) + md <- read_zarr_attributes(x) + ps <- .get_multiscales_dataset_paths(md) + ps <- file.path(x, as.character(ps)) + mt <- Zattrs(md) + as <- ImageArray(levels = lapply(ps, ZarrArray), + meta = list(axes = vapply(axes(mt), \(.) .$name, character(1)))) + sdImage(data=as, meta=Zattrs(md), ...) } #' @rdname readSpatialData diff --git a/R/sdArray.R b/R/sdArray.R index 305e232f..3cbce320 100644 --- a/R/sdArray.R +++ b/R/sdArray.R @@ -1,10 +1,10 @@ #' @name sdArray -#' @title Methods for `ImageArray` and `LabelArray` class +#' @title Methods for `sdArray` and `LabelArray` class #' -#' @param x \code{ImageArray} or \code{LabelArray} +#' @param x \code{sdArray} or \code{LabelArray} #' @param k scalar index specifying which scale to extract. #' -#' @return \code{ImageArray} +#' @return \code{sdArray} #' #' @examples #' zs <- file.path("extdata", "blobs.zarr") diff --git a/R/validity.R b/R/validity.R index 7e8efdb4..6650b3ac 100644 --- a/R/validity.R +++ b/R/validity.R @@ -41,20 +41,20 @@ return(msg) } -.validateImageArray <- \(object) { +.validatesdImage <- \(object) { msg <- c() res <- length(object) for (k in seq_len(res)) { x <- data(object, k) if (length(dim(x)) != 3) msg <- c(msg, paste( - "'ImageArray' resolution", k, "is not 3D")) + "'sdImage' resolution", k, "is not 3D")) if (!type(x) %in% c("double", "integer")) msg <- c(msg, paste( - "'ImageArray' resolution", k, "is not of type double or integer")) + "'sdImage' resolution", k, "is not of type double or integer")) } return(msg) } #' @importFrom S4Vectors setValidity2 -setValidity2("ImageArray", .validateImageArray) +setValidity2("sdImage", .validatesdImage) #' @importFrom ZarrArray type .validateLabelArray <- \(object) { @@ -98,7 +98,7 @@ setValidity2("ShapeFrame", .validateShapeFrame) .validateSpatialData <- \(x) { msg <- c() typ <- c( - images="ImageArray", + images="sdImage", labels="LabelArray", points="PointFrame", shapes="ShapeFrame", @@ -108,7 +108,7 @@ setValidity2("ShapeFrame", .validateShapeFrame) msg <- c(msg, sprintf("'%s' should be a list of '%s'", ., typ[.])) # TODO: validate .zattrs across all layers for (y in labels(x)) msg <- c(msg, .validateLabelArray(y)) - for (y in images(x)) msg <- c(msg, .validateImageArray(y)) + for (y in images(x)) msg <- c(msg, .validatesdImage(y)) for (y in points(x)) msg <- c(msg, .validatePointFrame(y)) for (y in shapes(x)) msg <- c(msg, .validateShapeFrame(y)) msg <- c(msg, .validateTables(x)) diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index 4837c6ed..80f501c2 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -19,8 +19,8 @@ \alias{element,SpatialData,numeric-method} \alias{element,SpatialData,missing-method} \alias{element,SpatialData,ANY-method} -\alias{[[<-,SpatialData,numeric,ANY,ANY-method} -\alias{[[<-,SpatialData,character,ANY,ANY-method} +\alias{[[<-,SpatialData,numeric,ANY-method} +\alias{[[<-,SpatialData,character,ANY-method} \title{The `SpatialData` class} \usage{ SpatialData(images, labels, points, shapes, tables) @@ -55,12 +55,12 @@ SpatialData(images, labels, points, shapes, tables) \S4method{images}{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{ImageArray}}s} +\item{images}{list of \code{\link{sdImage}}s} \item{labels}{list of \code{\link{LabelArray}}s} diff --git a/man/misc.Rd b/man/misc.Rd index d8a21716..1d5cb53c 100644 --- a/man/misc.Rd +++ b/man/misc.Rd @@ -3,14 +3,17 @@ \name{misc} \alias{misc} \alias{show,SpatialData-method} -\alias{show,sdArray-method} +\alias{show,LabelArray-method} +\alias{show,sdImage-method} \alias{show,PointFrame-method} \alias{show,ShapeFrame-method} \title{Miscellaneous `SpatialData` methods} \usage{ \S4method{show}{SpatialData}(object) -\S4method{show}{sdArray}(object) +\S4method{show}{LabelArray}(object) + +\S4method{show}{sdImage}(object) \S4method{show}{PointFrame}(object) diff --git a/man/readSpatialData.Rd b/man/readSpatialData.Rd index 1aad3800..32e94d94 100644 --- a/man/readSpatialData.Rd +++ b/man/readSpatialData.Rd @@ -48,7 +48,7 @@ so that pythonic \code{anndata} are used.} \value{ \itemize{ \item{For \code{readSpatialData}, a \code{SpatialData}.}, -\item{For element readers, a \code{ImageArray}, \code{LabelArray}, +\item{For element readers, a \code{sdImage}, \code{LabelArray}, \code{PointFrame}, \code{ShapeFrame}, or \code{SingleCellExperiment}.}} } \description{ diff --git a/man/sdArray.Rd b/man/sdArray.Rd index e9188448..ebb1b551 100644 --- a/man/sdArray.Rd +++ b/man/sdArray.Rd @@ -7,7 +7,7 @@ \alias{length,sdArray-method} \alias{data_type,sdArray-method} \alias{data_type,DelayedArray-method} -\title{Methods for `ImageArray` and `LabelArray` class} +\title{Methods for `sdArray` and `LabelArray` class} \usage{ \S4method{data}{sdArray}(x, k = 1) @@ -20,15 +20,15 @@ \S4method{data_type}{DelayedArray}(x) } \arguments{ -\item{x}{\code{ImageArray} or \code{LabelArray}} +\item{x}{\code{sdArray} or \code{LabelArray}} \item{k}{scalar index specifying which scale to extract.} } \value{ -\code{ImageArray} +\code{sdArray} } \description{ -Methods for `ImageArray` and `LabelArray` class +Methods for `sdArray` and `LabelArray` class } \examples{ zs <- file.path("extdata", "blobs.zarr") diff --git a/man/ImageArray.Rd b/man/sdImage.Rd similarity index 73% rename from man/ImageArray.Rd rename to man/sdImage.Rd index 39c9b82b..6d2f8f05 100644 --- a/man/ImageArray.Rd +++ b/man/sdImage.Rd @@ -1,20 +1,20 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/ImageArray.R -\name{ImageArray} -\alias{ImageArray} +\name{sdImage} +\alias{sdImage} \alias{channels} -\alias{channels,ImageArray-method} +\alias{channels,sdImage-method} \alias{channels,ANY-method} -\alias{[,ImageArray,ANY,ANY,ANY-method} -\title{The `ImageArray` class} +\alias{[,sdImage,ANY,ANY,ANY-method} +\title{The `sdImage` class} \usage{ -ImageArray(data = list(), meta = Zattrs(), metadata = list(), ...) +sdImage(data = list(), meta = Zattrs(), metadata = list(), ...) -\S4method{channels}{ImageArray}(x, ...) +\S4method{channels}{sdImage}(x, ...) \S4method{channels}{ANY}(x, ...) -\S4method{[}{ImageArray,ANY,ANY,ANY}(x, i, j, k, ..., drop = FALSE) +\S4method{[}{sdImage,ANY,ANY,ANY}(x, i, j, k, ..., drop = FALSE) } \arguments{ \item{data}{list of \code{\link[ZarrArray]{ZarrArray}}s} @@ -26,7 +26,7 @@ content describing the overall object.} \item{...}{option arguments passed to and from other methods.} -\item{x}{\code{ImageArray}} +\item{x}{\code{sdImage}} \item{i, j}{indices specifying elements to extract.} @@ -35,10 +35,10 @@ content describing the overall object.} \item{drop}{ignored.} } \value{ -\code{ImageArray} +\code{sdImage} } \description{ -The `ImageArray` class +The `sdImage` class } \examples{ zs <- file.path("extdata", "blobs.zarr") diff --git a/tests/testthat/test-crop.R b/tests/testthat/test-crop.R index 07ce2da4..c07d7783 100644 --- a/tests/testthat/test-crop.R +++ b/tests/testthat/test-crop.R @@ -45,7 +45,7 @@ test_that("query,.check_pol", { for (. in q) expect_error(SpatialData:::.check_pol(.)) }) -test_that("crop,ImageArray", { +test_that("crop,sdImage", { d <- dim(i <- image(x)) # polygon query (should use bounding box) y <- matrix(c(10, 10, 20, 10, 20, 20, 10, 20), ncol=2, byrow=TRUE) diff --git a/tests/testthat/test-ctutils.R b/tests/testthat/test-ctutils.R index b649c147..6cce4527 100644 --- a/tests/testthat/test-ctutils.R +++ b/tests/testthat/test-ctutils.R @@ -113,7 +113,7 @@ test_that("addCT", { expect_silent(z <- addCT(y, ".", t, v <- 1)) .check_data(z, v) t <- "scale" - d <- ifelse(is(y, "ImageArray"), 3, 2) + d <- ifelse(is(y, "sdImage"), 3, 2) expect_error(addCT(y, ".", t, numeric(d))) # zeroes expect_error(addCT(y, ".", t, 1+numeric(d+1))) # too many expect_error(addCT(y, ".", t, character(d))) # not a number diff --git a/tests/testthat/test-imagearray.R b/tests/testthat/test-imagearray.R index ea212f90..47dc0ff7 100644 --- a/tests/testthat/test-imagearray.R +++ b/tests/testthat/test-imagearray.R @@ -1,26 +1,26 @@ rgb <- seq_len(255) -test_that("ImageArray()", { +test_that("sdImage()", { val <- sample(rgb, 3*20*20, replace=TRUE) mat <- array(val, dim=c(3, 20, 20)) # invalid - expect_error(ImageArray(mat)) - expect_error(ImageArray(mat, 1)) - expect_error(ImageArray(mat, list())) + expect_error(sdImage(mat)) + expect_error(sdImage(mat, 1)) + expect_error(sdImage(mat, list())) # single scale - expect_silent(ImageArray(list())) - expect_silent(ImageArray(list(mat))) - expect_silent(ImageArray(list(mat), Zattrs())) + expect_silent(sdImage(list())) + expect_silent(sdImage(list(mat))) + expect_silent(sdImage(list(mat), Zattrs())) # multiscale dim <- lapply(c(20, 10, 5), \(.) c(3, rep(., 2))) lys <- lapply(dim, \(.) array(sample(rgb, prod(.), replace=TRUE), dim=.)) - expect_silent(ImageArray(lys)) + expect_silent(sdImage(lys)) }) -test_that("data(),ImageArray", { +test_that("data(),sdImage", { dim <- lapply(c(8, 4, 2), \(.) c(3, rep(., 2))) lys <- lapply(dim, \(.) array(0, dim=.)) - img <- ImageArray(lys) + img <- sdImage(lys) for (. in seq_along(lys)) expect_identical(data(img, .), lys[[.]]) expect_identical(data(img, Inf), lys[[3]]) diff --git a/tests/testthat/test-mask.R b/tests/testthat/test-mask.R index f418a0f3..7085a338 100644 --- a/tests/testthat/test-mask.R +++ b/tests/testthat/test-mask.R @@ -12,7 +12,7 @@ test_that("mask,unsupported", { for (ij in nm) expect_error(mask(x, ij[1], ij[2])) }) -test_that("mask,ImageArray,LabelArray", { +test_that("mask,sdImage,LabelArray", { i <- "blobs_image" j <- "blobs_labels" # reproduce example data diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index c3150e2f..8a5d86de 100644 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -5,7 +5,7 @@ x <- readSpatialData(x) fun <- c("image", "label", "shape", "point", "table") nms <- c("blobs_image", "blobs_labels", "blobs_circles", "blobs_points", "table") -typ <- c("ImageArray", "LabelArray", "ShapeFrame", "PointFrame", "SingleCellExperiment") +typ <- c("sdImage", "LabelArray", "ShapeFrame", "PointFrame", "SingleCellExperiment") # get ---- @@ -69,7 +69,7 @@ test_that("get one", { test_that("set all", { obj <- list( - ImageArray(), LabelArray(), + sdImage(), LabelArray(), ShapeFrame(), PointFrame(), SingleCellExperiment()) names(obj) <- SpatialData:::.LAYERS @@ -98,7 +98,7 @@ test_that("set one", { } # value=in/valid obj <- list( - ImageArray(), LabelArray(), + sdImage(), LabelArray(), ShapeFrame(), PointFrame(), SingleCellExperiment()) mapply(f=fun, o=obj, t=typ, \(f, o, t) { @@ -202,7 +202,7 @@ test_that("[,LabelArray", { # TODO: multiscales }) -test_that("[,ImageArray", { +test_that("[,sdImage", { d <- \(x) { y <- data(x, NULL) vapply(y, dim, numeric(3)) diff --git a/tests/testthat/test-read.R b/tests/testthat/test-read.R index 57b7a4fe..2c1bfbd0 100644 --- a/tests/testthat/test-read.R +++ b/tests/testthat/test-read.R @@ -3,7 +3,7 @@ x <- system.file(x, package="SpatialData") test_that("readElement()", { typ <- c( - images="ImageArray", + images="sdImage", labels="LabelArray", points="PointFrame", shapes="ShapeFrame", diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index d725fc7f..6ab7cdde 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -67,7 +67,7 @@ test_that("centroids,ShapeFrame", { # extent ---- -test_that("extent,ImageArray", { +test_that("extent,sdImage", { z <- extent(y <- image(x)[,-1,-c(1,2)]) expect_is(z, "list") expect_is(unlist(z), "numeric") diff --git a/tests/testthat/test-validity.R b/tests/testthat/test-validity.R index 8e827df9..0a6c4b89 100644 --- a/tests/testthat/test-validity.R +++ b/tests/testthat/test-validity.R @@ -5,11 +5,11 @@ zs <- file.path("extdata", "blobs.zarr") zs <- system.file(zs, package="SpatialData") sd <- readSpatialData(zs) -test_that("validity,ImageArray", { - expect_error(ImageArray(list(v <- character(1)))) +test_that("validity,sdImage", { + expect_error(sdImage(list(v <- character(1)))) x <- image(sd,1); x@data[[1]][1,1,1] <- v; expect_error(validObject(x)) x <- image(sd,2); x@data[[2]][1,1,1] <- v; expect_error(validObject(x)) - expect_error(ImageArray(list(a <- array(numeric(1), c(1,1))))) + expect_error(sdImage(list(a <- array(numeric(1), c(1,1))))) x <- image(sd,1); x@data[[1]] <- a; expect_error(validObject(x)) x <- image(sd,2); x@data[[2]] <- a; expect_error(validObject(x)) }) diff --git a/vignettes/temp.Rmd b/vignettes/temp.Rmd new file mode 100644 index 00000000..0e4256f1 --- /dev/null +++ b/vignettes/temp.Rmd @@ -0,0 +1,61 @@ +--- +title: "main" +output: html_document +date: "2026-05-07" +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +# Introduction + +The `r BiocStyle::Biocpkg("SpatialData")` package provides an R interface to the +[SpatialData](https://spatialdata.scverse.org) framework, a unified ecosystem +for handling spatial omics data. Developed as part of the +[scverse](https://scverse.org) project [@Virshup2023-scverse], `SpatialData` aims to solve the +challenges of integrating diverse spatial datasets—including imaging, spatial +transcriptomics, and proteomics—by employing the +[OME-NGFF (Next Generation File Format)](https://ngff.openmicroscopy.org) +standard [@Marconato2025-SpatialData]. + +The Python implementation and core specifications can be found at the +[official SpatialData website](https://spatialdata.scverse.org). + +## Data Representation in R + +The core of the package is the `SpatialData` class, which serves as a container +for multiple layers of spatial information: + +- **Images**: Multiscale, multi-channel raster data, represented as `ZarrArray` objects via the `r BiocStyle::Biocpkg("Rarr")` and `r BiocStyle::Biocpkg("ZarrArray")` packages. +- **Labels**: Segmentation masks (e.g., cell or nuclei boundaries), also stored as `ZarrArray`s. +- **Points**: High-resolution coordinates (e.g., individual transcript molecules), handled as `r BiocStyle::CRANpkg("arrow")` tables or `r BiocStyle::CRANpkg("duckdb")`-backed data frames for efficient out-of-memory processing. +- **Shapes**: Polygonal regions of interest or circular markers, represented similarly to points but with geometric metadata. +- **Tables**: Functional annotations (e.g., gene expression counts), stored as `r BiocStyle::Biocpkg("SingleCellExperiment")` objects. + +# Getting Started + +First, we load the necessary libraries: + +```{r load-libs} +library(SpatialData) +library(SingleCellExperiment) +``` + +## Reading Data + +`SpatialData` objects are typically read from `.zarr` stores. The package provides +the `readSpatialData()` function to ingest an entire store. For this demonstration, +we use a toy dataset included in the package. + +```{r read-data} +# Path to a toy dataset included in the package +path <- system.file("extdata", "blobs.zarr", package="SpatialData") + +# Read the complete SpatialData object +# sd <- readSpatialData(path) +# sd +tm <- SpatialData::readImage(file.path(path, "images/blobs_image")) +tm +data(tm) +``` \ No newline at end of file