Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
712ba83
add utilities for creating/writing zarr, groups and attr
Artur-man May 18, 2025
cb8de47
begin adding utilities to create/write/update metadata
Artur-man May 20, 2025
60b34fb
initial write utilities
Artur-man May 22, 2025
6d88bf8
Merge branch 'main' into write
Artur-man May 22, 2025
41112af
Merge branch 'main' into write
Artur-man May 23, 2025
e3d65cf
Merge branch 'main' into write
Artur-man May 30, 2025
000a478
move functions to zarr_utils.R
Artur-man May 30, 2025
19a3160
use read_zattrs instead
Artur-man May 30, 2025
9214401
make empty ct data
Artur-man May 30, 2025
8a796a4
update PointFrame methods for data.frame objects
Artur-man May 30, 2025
8aeb595
implement ondisk write for PointFrame objects
Artur-man May 30, 2025
4eb4fe1
move zarr functions
Artur-man May 30, 2025
78e104d
implement write utilities for shapes
Artur-man Jan 9, 2026
25555e1
implement ImageArray write utilities
Artur-man Jan 10, 2026
a347f12
single scale labelarray write support
Artur-man Jan 10, 2026
9e365d4
nearest neighbor downscale support for multiscale labels
Artur-man Jan 10, 2026
9407882
implement get_dim for spatialelements and fix tests
Artur-man Jan 11, 2026
9a1fa95
add read/write support for zarr v3
kollo97 Apr 15, 2026
5ba0488
Merge branch 'main' into issue_115
kollo97 Apr 15, 2026
1acbe7f
continue zarr v3 write, use Rarr read/write functionality when possible
kollo97 Apr 15, 2026
3ed81d5
minor clean up
kollo97 Apr 15, 2026
da7314b
add jsonlite again, update documentation
kollo97 Apr 15, 2026
42e472c
correct metadata writing in zarr.json files
kollo97 Apr 16, 2026
dd369ec
move helper to zarr_utils
kollo97 Apr 24, 2026
df4e81d
issue_115 (#2)
Artur-man Apr 27, 2026
0d61e1f
Merge branch 'main' into write_conflict
Artur-man May 5, 2026
85e816b
fix Zattrs for write testing
Artur-man May 5, 2026
1f72290
update some functions
Artur-man May 6, 2026
1a78398
adapt write tests for duckspatial
Artur-man May 6, 2026
e71593c
write versioning concept
Artur-man May 6, 2026
66cd772
update versioning functions
Artur-man May 6, 2026
4e0a713
update create_zarr
Artur-man May 6, 2026
9d562f2
test/examples pass
Artur-man May 6, 2026
f7c4daa
multiple sd versions (zarr v2 and v3) tests implemented
Artur-man May 8, 2026
d10b658
write support for tables (zarr v2)
Artur-man May 8, 2026
ecf8ccc
update formating interface
Artur-man May 8, 2026
3d406b1
fix default CT for Zattrs
Artur-man May 9, 2026
d5e6fa9
merge renaming commit
Artur-man May 9, 2026
18f44ae
resolve more conflicts from rename commit
Artur-man May 9, 2026
746d211
doc check
Artur-man May 9, 2026
56067a6
resolve more conflicts with upstream
Artur-man May 9, 2026
46deaad
fix small tests
Artur-man May 9, 2026
cf9e1c8
fix issues with dataset access, seq_along fix
Artur-man May 9, 2026
6461eb7
clean PR
Artur-man May 9, 2026
9449f67
quietly write shapes
Artur-man May 9, 2026
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
16 changes: 16 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export(SpatialDataImage)
export(SpatialDataLabel)
export(SpatialDataPoint)
export(SpatialDataShape)
export(create_zarr)
export(create_zarr_group)
export(filter)
export(mutate)
export(pull)
Expand All @@ -26,6 +28,12 @@ export(readShape)
export(readSpatialData)
export(readTable)
export(select)
export(writeImage)
export(writeLabel)
export(writePoint)
export(writeShape)
export(writeSpatialData)
export(writeTable)
exportClasses(SpatialData)
exportMethods("$")
exportMethods("[")
Expand Down Expand Up @@ -118,12 +126,15 @@ importFrom(BiocGenerics,colnames)
importFrom(BiocGenerics,combine)
importFrom(BiocGenerics,rownames)
importFrom(DelayedArray,DelayedArray)
importFrom(EBImage,resize)
importFrom(EBImage,rotate)
importFrom(Matrix,sparseMatrix)
importFrom(Matrix,sparseVector)
importFrom(Matrix,summary)
importFrom(RBGL,sp.between)
importFrom(Rarr,read_zarr_attributes)
importFrom(Rarr,write_zarr_array)
importFrom(Rarr,write_zarr_attributes)
importFrom(Rarr,zarr_overview)
importFrom(S4Vectors,"metadata<-")
importFrom(S4Vectors,coolcat)
Expand All @@ -146,8 +157,10 @@ importFrom(ZarrArray,ZarrArray)
importFrom(ZarrArray,path)
importFrom(ZarrArray,type)
importFrom(anndataR,read_zarr)
importFrom(anndataR,write_zarr)
importFrom(dplyr,all_of)
importFrom(dplyr,anti_join)
importFrom(dplyr,bind_cols)
importFrom(dplyr,coalesce)
importFrom(dplyr,collect)
importFrom(dplyr,count)
Expand All @@ -161,10 +174,12 @@ importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,sql)
importFrom(dplyr,tally)
importFrom(dplyr,tibble)
importFrom(duckspatial,as_duckspatial_df)
importFrom(duckspatial,ddbs_bbox)
importFrom(duckspatial,ddbs_intersects)
importFrom(duckspatial,ddbs_open_dataset)
importFrom(duckspatial,ddbs_write_dataset)
importFrom(graph,"edgeData<-")
importFrom(graph,"edgeDataDefaults<-")
importFrom(graph,"nodeData<-")
Expand Down Expand Up @@ -196,6 +211,7 @@ importFrom(sf,st_geometry_type)
importFrom(sf,st_polygon)
importFrom(sf,st_sf)
importFrom(sf,st_sfc)
importFrom(stats,setNames)
importFrom(utils,.DollarNames)
importFrom(utils,head)
importFrom(utils,tail)
14 changes: 14 additions & 0 deletions R/AllClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
Class="SpatialDataAttrs",
contains="list")

.sdFormat <- setClass(
Class = "sdFormat",
slots = list(
version = "character",
zarr_version = "integer",
ome_version = "character",
image = "character",
label = "character",
point = "character",
shape = "character",
table = "character"
)
)

#' @importFrom methods setClassUnion
#' @importClassesFrom S4Arrays Array
setClassUnion(
Expand Down
8 changes: 8 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ setGeneric("centroids", \(x, ...) standardGeneric("centroids"))
setGeneric("data_type", \(x, ...) standardGeneric("data_type"))
setGeneric("geom_type", \(x, ...) standardGeneric("geom_type"))
setGeneric("multiscales", \(x, ...) standardGeneric("multiscales"))
setGeneric("datasets", \(x, ...) standardGeneric("datasets"))

# tbl ----

setGeneric("hasTable", \(x, i, ...) standardGeneric("hasTable"))
setGeneric("getTable", \(x, i, ...) standardGeneric("getTable"))
setGeneric("setTable", \(x, i, ...) standardGeneric("setTable"))

# zarr ----

setGeneric("version", \(x, ...) standardGeneric("version"))
setGeneric("version<-", \(x, value) standardGeneric("version<-"))
setGeneric("zarr_version", \(x, ...) standardGeneric("zarr_version"))
setGeneric("ome_version", \(x, ...) standardGeneric("ome_version"))
11 changes: 6 additions & 5 deletions R/SpatialData.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#' @param x \code{SpatialData}
#' @param i,j character string, scalar or vector of indices
#' specifying the element to extract from a given layer.
#'
#' @param drop ignored.
#' @param name character string for extraction (see \code{?base::`$`}).
#' @param value (list of) element(s) with layer-compliant object(s),
Expand All @@ -51,11 +52,11 @@
#'
#' @export
SpatialData <- \(images, labels, points, shapes, tables) {
if (missing(images)) images <- list()
if (missing(labels)) labels <- list()
if (missing(points)) points <- list()
if (missing(shapes)) shapes <- list()
if (missing(tables)) tables <- list()
if (missing(images)) images <- setNames(list(), character(0))
if (missing(labels)) labels <- setNames(list(), character(0))
if (missing(points)) points <- setNames(list(), character(0))
if (missing(shapes)) shapes <- setNames(list(), character(0))
if (missing(tables)) tables <- setNames(list(), character(0))
.SpatialData(
images=images, labels=labels,
points=points, shapes=shapes, tables=tables)
Expand Down
49 changes: 49 additions & 0 deletions R/format.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' @name sdFormat
#' @title The `sdFormat` class
#'
#' @param version SpatialData version: 0.1 or 0.2.
#'
#' @details
#'
#' @return \code{sdFormat}
#'
#' @noRd
sdFormat <- function(version = "0.1") {
switch(as.character(version),
"0.2" = {
.sdFormat(
version = "0.2",
zarr_version = 3L,
ome_version = "0.5",
image = "0.3",
label = "0.3",
shape = "0.3",
point = "0.2",
table = "0.2"
)
},
"0.1" = {
.sdFormat(
version = "0.1",
zarr_version = 2L,
ome_version = "0.5",
image = "0.2",
label = "0.2",
shape = "0.2",
point = "0.1",
table = "0.1"
)
},
stop("Incorrect SpatialData version. Must be 0.1 or 0.2!")
)
}

setMethod("image", "sdFormat", \(x) x@image)
setMethod("label", "sdFormat", \(x) x@label)
setMethod("shape", "sdFormat", \(x) x@shape)
setMethod("point", "sdFormat", \(x) x@point)
setMethod("table", "sdFormat", \(x) x@table)
setMethod("zarr_version", "sdFormat", \(x) x@zarr_version)
setMethod("zarr_version", "character", \(x) zarr_version(sdFormat(x)))
setMethod("ome_version", "sdFormat", \(x) x@ome_version)
setMethod("version", "sdFormat", \(x) x@version)
13 changes: 8 additions & 5 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ NULL
#' @export
readImage <- function(x, ...) {
l <- .readArray(x, ...)
SpatialDataImage(data=l$array, meta=SpatialDataAttrs(l$md), ...)
SpatialDataImage(data=l$array, meta=SpatialDataAttrs(l$md),
version = version(l$md), ...)
}

#' @rdname readSpatialData
#' @export
readLabel <- function(x, ...) {
l <- .readArray(x, ...)
SpatialDataLabel(data=l$array, meta=SpatialDataAttrs(l$md), ...)
SpatialDataLabel(data=l$array, meta=SpatialDataAttrs(l$md),
version = version(l$md), ...)
}

#' @rdname readSpatialData
Expand All @@ -79,7 +81,7 @@ readPoint <- function(x, ...) {
mutate(geometry=sql(sprintf("ST_Point(%s, %s)", ax[1], ax[2]))) |>
as_duckspatial_df(crs=NA_character_) |>
select(-all_of(ax))
SpatialDataPoint(data=df, meta=SpatialDataAttrs(md))
SpatialDataPoint(data=df, meta=SpatialDataAttrs(md), version = version(md))
}

#' @rdname readSpatialData
Expand All @@ -90,7 +92,8 @@ readPoint <- function(x, ...) {
readShape <- function(x, ...) {
md <- read_zarr_attributes(x)
pq <- list.files(x, "\\.parquet$", full.names=TRUE)
SpatialDataShape(data=ddbs_open_dataset(pq), meta=SpatialDataAttrs(md))
SpatialDataShape(data=ddbs_open_dataset(pq), meta=SpatialDataAttrs(md),
version = version(md))
}

#' @export
Expand All @@ -105,7 +108,7 @@ readTable <- function(x) {
})
# move these to 'int_metadata'
nm <- "spatialdata_attrs"
md <- metadata(sce)[[nm]]
md <- read_zarr_attributes(x)
int_metadata(sce)[[nm]] <- md
metadata(sce)[[nm]] <- NULL
# move these to 'int_colData'
Expand Down
Loading
Loading