diff --git a/DESCRIPTION b/DESCRIPTION index e15ffa55..a541151a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: spatialdataR Title: Representation of Python's spatialdata in R Depends: R (>= 4.6) -Version: 0.99.40 +Version: 0.99.41 Description: R interface to Python/scverse's 'spatialdata' framework for unified spatial omics data handling. Adheres to OME-NGFF standards, providing lazy, on-disk representations for multiscale images and @@ -64,6 +64,6 @@ biocViews: License: Artistic-2.0 Encoding: UTF-8 VignetteBuilder: knitr -URL: https://helenalc.github.io/SpatialData/, https://github.com/HelenaLC/SpatialData -BugReports: https://github.com/HelenaLC/SpatialData/issues +BugReports: https://github.com/HelenaLC/spatialdataR/issues +URL: https://helenalc.github.io/spatialdataR, https://github.com/HelenaLC/spatialdataR Config/roxygen2/version: 8.0.0 diff --git a/NAMESPACE b/NAMESPACE index c2b8caa0..cf5f75db 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -190,6 +190,7 @@ importFrom(graph,graph.par) importFrom(graph,graphAM) importFrom(graph,nodeData) importFrom(graph,nodes) +importFrom(methods,"slot<-") importFrom(methods,as) importFrom(methods,callNextMethod) importFrom(methods,is) @@ -199,6 +200,7 @@ importFrom(methods,setClassUnion) importFrom(methods,setMethod) importFrom(methods,setOldClass) importFrom(methods,setReplaceMethod) +importFrom(methods,slot) importFrom(rlang,"!!") importFrom(rlang,.data) importFrom(rlang,call2) diff --git a/R/SpatialData.R b/R/SpatialData.R index c490a6b6..49f1e334 100644 --- a/R/SpatialData.R +++ b/R/SpatialData.R @@ -29,6 +29,8 @@ #' @param x,object \code{SpatialData} object. #' @param i,j character string, scalar or vector of indices #' specifying the element to extract from a given layer. +#' @param k scalar index specifying which scale to use; +#' \code{Inf} to use lowest available resolution. #' @param drop ignored. #' @param name character string for extraction (see \code{?base::`$`}). #' @param value (list of) element(s) with layer-compliant object(s), diff --git a/R/methods.R b/R/methods.R index 7d4ab5e6..9c66caac 100644 --- a/R/methods.R +++ b/R/methods.R @@ -10,6 +10,7 @@ #' @exportMethod $ #' @rdname SpatialData +#' @importFrom methods slot setMethod("$", "SpatialData", \(x, name) slot(x, name)) #' @exportMethod $<- @@ -24,8 +25,9 @@ setMethod("[[", c("SpatialData", "numeric"), \(x, i, ...) { callNextMethod(x, i) }) -#' @rdname SpatialData #' @export +#' @rdname SpatialData +#' @importFrom methods slot setMethod("[[", c("SpatialData", "character"), \(x, i, ...) slot(x, i)) # data/meta ---- @@ -151,8 +153,9 @@ setMethod("layer", c("SpatialData", "ANY"), \(x, i) stop(.invalid_i)) # element ---- -#' @rdname SpatialData #' @export +#' @rdname SpatialData +#' @importFrom methods slot setMethod("element", c("SpatialData", "character"), \(x, i) slot(x, layer(x, i))[[i]]) @@ -260,6 +263,7 @@ for (e in one) eval(.set(e), parent.env(environment())) #' @exportMethod images<- labels<- points<- shapes<- tables<- NULL +#' @importFrom methods slot slot<- f <- \(l) setReplaceMethod(l, c("SpatialData", getSlots("SpatialData")[[l]]), \(x, value) { @@ -357,6 +361,7 @@ typ <- c( shape="SpatialDataShape", table="SingleCellExperiment") +#' @importFrom methods slot f <- \(e) setReplaceMethod(e, c("SpatialData", "character", typ[[e]]), \(x, i, value) { @@ -406,6 +411,7 @@ for (e in one) eval(f(e), parent.env(environment())) #' @exportMethod image<- label<- point<- shape<- table<- NULL +#' @importFrom methods slot f <- \(e) setReplaceMethod(e, c("SpatialData", "ANY", "NULL"), \(x, i, ..., value) { diff --git a/R/utils.R b/R/utils.R index f90a5b31..409f106a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -31,6 +31,7 @@ return(x) } +#' @importFrom methods slot<- .sync_tables_sdattrs <- \(x, old, new) { if (!length(ts <- tables(x))) return(x) for (i in seq_along(ts)) { @@ -73,6 +74,7 @@ return(x) } +#' @importFrom methods slot<- .sync_tables_on_drop <- \(x) { if (!length(ts <- tables(x))) return(x) all_nms <- unlist(colnames(x)[.ls]) diff --git a/R/validity.R b/R/validity.R index 14606266..818264e0 100644 --- a/R/validity.R +++ b/R/validity.R @@ -192,7 +192,6 @@ setValidity2("SpatialData", .validateSpatialData) return(msg) } .validateAttrsLabel <- \(x) { - x <- label(sd) msg <- c() za <- meta(x) msg <- .validateAttrs_multiscales(za, msg) diff --git a/inst/NEWS b/inst/NEWS index 0a6a01e9..5f9fa546 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,3 +1,8 @@ +changes in version 0.99.41 + +- fix vignette to call 'spatialdataR::transform()' explicitly +- address R CMD check warnings re: undocumented arguments, undefined functions + changes in version 0.99.40 - validty & setters now assure that each layer is a completely named list @@ -27,9 +32,12 @@ changes in version 0.99.36 changes in version 0.99.35 -- class renaming - bug fix: 'centroids,shape' was previously returning vertex coordinates for polygons +- class renaming: + sdArray/Frame > SpatialDataArray/Frame, + Image/LabelArray > SpatialDataImage/Label, + Shape/PointFrame > SpatialDataShape/Point changes in version 0.99.34 diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index f0d5acb4..94fe0d84 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -147,6 +147,9 @@ specifying the element to extract from a given layer.} \item{...}{optional arguments passed to and from other methods.} +\item{k}{scalar index specifying which scale to use; +\code{Inf} to use lowest available resolution.} + \item{drop}{ignored.} } \value{ diff --git a/vignettes/SpatialData.Rmd b/vignettes/SpatialData.Rmd index 3380a98d..739c13a6 100644 --- a/vignettes/SpatialData.Rmd +++ b/vignettes/SpatialData.Rmd @@ -8,7 +8,7 @@ output: toc_depth: 2 toc_float: true vignette: | - %\VignetteIndexEntry{Introduction to spatialdataR} + %\VignetteIndexEntry{spatialdataR} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} bibliography: "refs.bib" @@ -28,23 +28,25 @@ knitr::opts_chunk$set(cache=FALSE, message=FALSE, warning=FALSE) ## Introduction -The `r BiocStyle::Biocpkg("spatialdataR")` 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 +The `r BiocStyle::Biocpkg("spatialdataR")` package provides an R interface to +Python's [spatialdata](https://spatialdata.scverse.org) framework for unified +handling of spatial omics data, including tabular annotations, vector- and +raster-based components. Developed as part of the [scverse](https://scverse.org) +project [@Virshup2023-scverse], `spatialdata` aims to solve the challenges of +integrating diverse spatial datasets -- including -- 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). +The Python implementation and core specifications are found at the +[official `spatialdata` website](https://spatialdata.scverse.org). ## Representation The core data structure is the `SpatialData` class, which organizes data into 5 coordinated **layers: images, labels, points, shapes, and tables**. -Each layer is stored as a list of layer-specific objects that carry associated `SpatialDataAttr` (`@meta` slot), which encode `spatialdata`-specific zarr attributes (*.zattr* for Zarr v2, and *zarr.json* for Zarr v3) +Each layer is stored as a list of layer-specific objects that carry associated +`SpatialDataAttr` (`@meta` slot), which encode `spatialdata`-specific +Zarr attributes (*.zattr* for Zarr v2, and *zarr.json* for Zarr v3). Together, these layers provide a unified representation of spatial omics data, combining raster, vector, and tabular data within a single coherent framework. @@ -240,7 +242,7 @@ in the correct order (e.g., `scale()` then `translation()`). a <- label(sd) # project into 'global' -b <- transform(a, "scale") +b <- spatialdataR::transform(a, "scale") # compare XY extents do.call(rbind, c(a=extent(a), b=extent(b))) @@ -338,7 +340,7 @@ across objects via `make.names()`, appending a suffix to the element names of subsequent objects. Alternatively, names could be customize before combining. ```{r combine} -sp <- combine(sd, sd) +sp <- combine(list(foo=sd, bar=sd)) cbind( original=lengths(colnames(sd)), combined=lengths(colnames(sp)))