Skip to content

Commit 498685f

Browse files
committed
use prototyped S4Vectors::SimpleList as slots
1 parent f2189ec commit 498685f

13 files changed

Lines changed: 222 additions & 125 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: spatialdataR
22
Title: Representation of Python's spatialdata in R
33
Depends: R (>= 4.6)
4-
Version: 0.99.38
4+
Version: 0.99.39
55
Description: R interface to Python/scverse's 'spatialdata' framework for
66
unified spatial omics data handling. Adheres to OME-NGFF standards,
77
providing lazy, on-disk representations for multiscale images and

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ exportMethods("instances<-")
4242
exportMethods("label<-")
4343
exportMethods("labelNames<-")
4444
exportMethods("labels<-")
45+
exportMethods("layer<-")
4546
exportMethods("point<-")
4647
exportMethods("pointNames<-")
4748
exportMethods("points<-")
@@ -133,6 +134,7 @@ importFrom(Rarr,read_zarr_attributes)
133134
importFrom(Rarr,zarr_overview)
134135
importFrom(S4Vectors,"metadata<-")
135136
importFrom(S4Vectors,DataFrame)
137+
importFrom(S4Vectors,SimpleList)
136138
importFrom(S4Vectors,coolcat)
137139
importFrom(S4Vectors,make_zero_col_DFrame)
138140
importFrom(S4Vectors,metadata)

R/AllClasses.R

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,81 @@
1+
#' @importFrom S4Vectors SimpleList
12
#' @importFrom methods setClass setClassUnion setOldClass
23

4+
.sdLayerList <- setClass(
5+
Class="sdLayerList",
6+
contains="SimpleList",
7+
slots=c(metadata="list"),
8+
prototype=prototype(metadata=list()))
9+
10+
.sdImageList <- setClass(
11+
Class="sdImageList",
12+
contains="sdLayerList",
13+
prototype=prototype(elementType="SpatialDataImage"))
14+
15+
.sdLabelList <- setClass(
16+
Class="sdLabelList",
17+
contains="sdLayerList",
18+
prototype=prototype(elementType="SpatialDataLabel"))
19+
20+
.sdPointList <- setClass(
21+
Class="sdPointList",
22+
contains="sdLayerList",
23+
prototype=prototype(elementType="SpatialDataPoint"))
24+
25+
.sdShapeList <- setClass(
26+
Class="sdShapeList",
27+
contains="sdLayerList",
28+
prototype=prototype(elementType="SpatialDataShape"))
29+
30+
.sdTableList <- setClass(
31+
Class="sdTableList",
32+
contains="sdLayerList",
33+
prototype=prototype(elementType="SingleCellExperiment"))
34+
35+
.sl <- S4Vectors:::new_SimpleList_from_list
36+
.ok <- \(x) length(x) == 1L && (is.list(x[[1L]]) || is(x[[1L]], "SimpleList"))
37+
38+
sdImageList <- \(...) {
39+
x <- list(...)
40+
if (.ok(x)) x <- x[[1L]]
41+
.sl("sdImageList", as.list(x))
42+
}
43+
44+
sdLabelList <- \(...) {
45+
x <- list(...)
46+
if (.ok(x)) x <- x[[1L]]
47+
.sl("sdLabelList", as.list(x))
48+
}
49+
50+
sdPointList <- \(...) {
51+
x <- list(...)
52+
if (.ok(x)) x <- x[[1L]]
53+
.sl("sdPointList", as.list(x))
54+
}
55+
56+
sdShapeList <- \(...) {
57+
x <- list(...)
58+
if (.ok(x)) x <- x[[1L]]
59+
.sl("sdShapeList", as.list(x))
60+
}
61+
62+
sdTableList <- \(...) {
63+
x <- list(...)
64+
if (.ok(x)) x <- x[[1L]]
65+
.sl("sdTableList", as.list(x))
66+
}
67+
368
#' @export
469
#' @rdname SpatialData
570
.SpatialData <- setClass(
671
Class="SpatialData",
772
contains=c("list", "Annotated"),
873
representation(
9-
images="list", # 'SpatialDataImage's
10-
labels="list", # 'SpatialDataLabel's
11-
points="list", # 'SpatialDataPoint's
12-
shapes="list", # 'SpatialDataShape's
13-
tables="list")) # 'SingleCellExperiment's
74+
images="sdImageList",
75+
labels="sdLabelList",
76+
points="sdPointList",
77+
shapes="sdShapeList",
78+
tables="sdTableList"))
1479

1580
.LAYERS <- `names<-`(. <- c("images","labels","points","shapes","tables"), .)
1681
.SpatialDataAttrs <- setClass("SpatialDataAttrs", contains="list")

R/AllGenerics.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ setGeneric("meta<-", \(x, ..., value) standardGeneric("meta<-"))
8484
setGeneric("data<-", \(x, ..., value) standardGeneric("data<-"))
8585

8686
setGeneric("layer", \(x, i, ...) standardGeneric("layer"))
87+
setGeneric("layer<-", \(x, i, value) standardGeneric("layer<-"))
8788
setGeneric("element", \(x, i, ...) standardGeneric("element"))
8889
setGeneric("element<-", \(x, i, value) standardGeneric("element<-"))
8990
setGeneric("elements", \(x, i, ...) standardGeneric("elements"))

R/SpatialData.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@
5353
#' x[c(1, 2), list(1, c(1, 2))] # multiple
5454
#'
5555
#' @export
56-
SpatialData <- \(images, labels, points, shapes, tables) {
57-
if (missing(images)) images <- list()
58-
if (missing(labels)) labels <- list()
59-
if (missing(points)) points <- list()
60-
if (missing(shapes)) shapes <- list()
61-
if (missing(tables)) tables <- list()
56+
SpatialData <- \(
57+
images=list(),
58+
labels=list(),
59+
points=list(),
60+
shapes=list(),
61+
tables=list())
62+
{
6263
.SpatialData(
63-
images=images, labels=labels,
64-
points=points, shapes=shapes, tables=tables)
64+
images=sdImageList(images),
65+
labels=sdLabelList(labels),
66+
points=sdPointList(points),
67+
shapes=sdShapeList(shapes),
68+
tables=sdTableList(tables))
6569
}

0 commit comments

Comments
 (0)