diff --git a/DESCRIPTION b/DESCRIPTION index add5c001..2dd7a6b8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,12 +46,12 @@ Imports: ZarrArray, RBGL, reticulate, + anndataR, sf, S4Arrays, S4Vectors, SingleCellExperiment, - SummarizedExperiment, - zellkonverter + SummarizedExperiment Suggests: BiocStyle, ggnewscale, @@ -63,11 +63,7 @@ Suggests: SpatialData.plot, testthat, DT -Enhances: - anndataR, - pizzarr Remotes: - keller-mark/pizzarr, keller-mark/anndataR@spatialdata, HelenaLC/SpatialData.data, HelenaLC/SpatialData.plot, diff --git a/NAMESPACE b/NAMESPACE index a090f831..7dacaede 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -80,6 +80,7 @@ exportMethods(tableNames) exportMethods(tables) exportMethods(translation) exportMethods(valTable) +import(anndataR) import(geoarrow) importClassesFrom(S4Arrays,Array) importClassesFrom(S4Vectors,DFrame) @@ -149,4 +150,3 @@ importFrom(sf,st_sfc) importFrom(utils,.DollarNames) importFrom(utils,head) importFrom(utils,tail) -importFrom(zellkonverter,AnnData2SCE) diff --git a/R/read.R b/R/read.R index 25bd8430..7f64e2ba 100644 --- a/R/read.R +++ b/R/read.R @@ -27,10 +27,10 @@ # "zarr==2.18.4", "zict==3.0.0") allp = c("zarr==3.1.5", "spatialdata==0.7.0", "spatialdata_io==0.6.0", "spatialdata_plot==0.2.14", "setuptools==75.8.0") -# notes from VJC -- readSpatialData was modified below so -# that if anndataR = FALSE, spatialdata.read_zarr is used +# notes from VJC/AM -- readSpatialData was modified below so +# that if anndataR = FALSE, anndata.read_zarr is used # to get the whole zarr store, and then the tables are -# transformed via zellkonverter. this gives a 10x speedup +# transformed via anndataR. This gives a 10x speedup # for ingesting the visium_hd_3.0.0 example but fails on # the blobs dataset in example("table-utils") because # of matters related to metadata/hasTable behavior @@ -51,9 +51,9 @@ allp = c("zarr==3.1.5", "spatialdata==0.7.0", "spatialdata_io==0.6.0", #' The default, NULL, reads all elements; alternatively, may be FALSE #' to skip a layer, or a integer vector specifying which elements to read. #' @param anndataR logical specifying whether -#' to use \code{anndataR} to read tables; defaults to FALSE in `readSpatialData`, -#' and `readTable`, -#' so that pythonic \code{spatialdata} and \code{zellkonverter} are used. +#' to use \code{anndataR} to read tables; +#' defaults to FALSE in `readSpatialData`, and `readTable`, +#' so that pythonic \code{anndata} are used. #' @param ... option arguments passed to and from other methods. #' #' @return @@ -67,6 +67,9 @@ allp = c("zarr==3.1.5", "spatialdata==0.7.0", "spatialdata_io==0.6.0", #' dir.create(tf <- tempfile()) #' base <- SpatialData.data:::.unzip_merfish_demo(tf) #' (x <- readSpatialData(base)) +#' +#' # import tables using anndataR +#' (x <- readSpatialData(base, anndataR=TRUE)) NULL #' @importFrom ZarrArray ZarrArray @@ -123,9 +126,9 @@ readShape <- function(x, ...) { packages=c( "python==3.13.0"), pip=allp) +#' @import anndataR #' @importFrom reticulate import #' @importFrom S4Vectors metadata -#' @importFrom zellkonverter AnnData2SCE #' @importFrom SingleCellExperiment int_metadata #' @importFrom basilisk basiliskStart basiliskStop basiliskRun .readTables_basilisk <- function(x) { @@ -141,7 +144,7 @@ readShape <- function(x, ...) { full.names = FALSE) lapply(ts, \(z) { zs <- sd$read_zarr(file.path(x, "tables", z)) - se <- AnnData2SCE(zs) + se <- zs$as_SingleCellExperiment() nm <- "spatialdata_attrs" md <- metadata(se)[[nm]] int_metadata(se)[[nm]] <- md @@ -152,16 +155,12 @@ readShape <- function(x, ...) { } .readTable_anndataR <- function(x) { if (!requireNamespace('anndataR', quietly=TRUE)) { - stop("To use this function, install the 'anndataR' package via\n", - "`BiocManager::install(\"keller-mark/anndataR\", ref=\"spatialdata\")`") - } - if (!requireNamespace('pizzarr', quietly=TRUE)) { - stop("To use this function, install the 'pizzarr' package via\n", - "`BiocManager::install(\"keller-mark/pizzarr\")`") + message("To make sure 'anndataR' package works as intended, ", + "install the development version via\n", + "`BiocManager::install(\"keller-mark/anndataR\", ref=\"spatialdata\")`") } suppressWarnings({ # suppress warnings related to hidden files - adata <- anndataR::read_zarr(x) - anndataR::to_SingleCellExperiment(adata) + anndataR::read_zarr(x, as="SingleCellExperiment") }) } diff --git a/inst/NEWS b/inst/NEWS index d61edd0f..d7033001 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,3 +1,11 @@ +changes in version 0.99.24 + +- ZarrArray imported by Bioconductor/ZarrArray +- Rarr replaces pizzarr for importing tables via anndataR +- anndataR replaces zellkonverter +- update basilisk env to spatialdata==0.7.0 +- replace spatialdata.read with anndata.read_zarr to read tables + changes in version 0.99.22 - split off 'SpatialData.data' diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index e760cfd6..9521d85c 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -50,8 +50,8 @@ \alias{element,SpatialData,ANY,numeric-method} \alias{element,SpatialData,ANY,missing-method} \alias{element,SpatialData,ANY,ANY-method} -\alias{[[<-,SpatialData,numeric,ANY-method} -\alias{[[<-,SpatialData,character,ANY-method} +\alias{[[<-,SpatialData,numeric,ANY,ANY-method} +\alias{[[<-,SpatialData,character,ANY,ANY-method} \title{The `SpatialData` class} \usage{ SpatialData(images, labels, points, shapes, tables) @@ -88,9 +88,9 @@ SpatialData(images, labels, points, shapes, tables) \S4method{element}{SpatialData,ANY,ANY}(x, i, j) -\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{ImageArray}}s} diff --git a/man/readSpatialData.Rd b/man/readSpatialData.Rd index 000ed434..fdb1dcc3 100644 --- a/man/readSpatialData.Rd +++ b/man/readSpatialData.Rd @@ -42,9 +42,9 @@ The default, NULL, reads all elements; alternatively, may be FALSE to skip a layer, or a integer vector specifying which elements to read.} \item{anndataR}{logical specifying whether -to use \code{anndataR} to read tables; defaults to FALSE in `readSpatialData`, -and `readTable`, -so that pythonic \code{spatialdata} and \code{zellkonverter} are used.} +to use \code{anndataR} to read tables; +defaults to FALSE in `readSpatialData`, and `readTable`, +so that pythonic \code{anndata} are used.} } \value{ \itemize{ @@ -60,4 +60,7 @@ library(SpatialData.data) dir.create(tf <- tempfile()) base <- SpatialData.data:::.unzip_merfish_demo(tf) (x <- readSpatialData(base)) + +# import tables using anndataR +(x <- readSpatialData(base, anndataR=TRUE)) }