Skip to content

Commit a2cbcda

Browse files
authored
SimpleList, path()
* use prototyped S4Vectors::SimpleList as slots * new path() method to retrieve on-disk file paths * more tests & validity * bump to v0.99.39
1 parent f2189ec commit a2cbcda

20 files changed

Lines changed: 568 additions & 182 deletions

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ exportMethods(mask)
9191
exportMethods(meta)
9292
exportMethods(mirror)
9393
exportMethods(names)
94+
exportMethods(path)
9495
exportMethods(point)
9596
exportMethods(pointNames)
9697
exportMethods(points)
@@ -116,6 +117,7 @@ importFrom(BiocGenerics,as.data.frame)
116117
importFrom(BiocGenerics,colnames)
117118
importFrom(BiocGenerics,combine)
118119
importFrom(BiocGenerics,data)
120+
importFrom(BiocGenerics,path)
119121
importFrom(BiocGenerics,rotate)
120122
importFrom(BiocGenerics,rownames)
121123
importFrom(BiocGenerics,scale)
@@ -133,6 +135,7 @@ importFrom(Rarr,read_zarr_attributes)
133135
importFrom(Rarr,zarr_overview)
134136
importFrom(S4Vectors,"metadata<-")
135137
importFrom(S4Vectors,DataFrame)
138+
importFrom(S4Vectors,SimpleList)
136139
importFrom(S4Vectors,coolcat)
137140
importFrom(S4Vectors,make_zero_col_DFrame)
138141
importFrom(S4Vectors,metadata)
@@ -167,6 +170,7 @@ importFrom(dplyr,select)
167170
importFrom(dplyr,slice)
168171
importFrom(dplyr,sql)
169172
importFrom(dplyr,tally)
173+
importFrom(dplyr,tibble)
170174
importFrom(duckspatial,as_duckspatial_df)
171175
importFrom(duckspatial,ddbs_bbox)
172176
importFrom(duckspatial,ddbs_create_conn)

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/CTutils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ NULL
5252
#' @rdname CTutils
5353
#' @export
5454
setMethod("axes", "SpatialDataAttrs", \(x, ...) {
55-
ms <- .ms(x)
55+
ms <- multiscales(x)
5656
if (!is.null(ms)) x <- ms[[1]]
5757
if (is.null(x <- x$axes)) stop("couldn't find 'axes'")
5858
return(x)
@@ -63,7 +63,7 @@ setMethod("axes", "SpatialDataAttrs", \(x, ...) {
6363
#' @rdname CTutils
6464
#' @export
6565
setMethod("CTlist", "SpatialDataAttrs", \(x, ...) {
66-
ms <- .ms(x)
66+
ms <- multiscales(x)
6767
ct <- "coordinateTransformations"
6868
if (is.null(ms)) return(x[[ct]])
6969
ms[[1]][[ct]]

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)