Skip to content

Commit 12fdc09

Browse files
committed
doc missing singlists
1 parent a4b07b3 commit 12fdc09

12 files changed

Lines changed: 138 additions & 58 deletions

R/CTutils.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,21 @@ setMethod("CTname", "SpatialDataAttrs", \(x, ...) {
103103

104104
# SpatialDataElement ----
105105

106-
.SDE_METS <- c("axes", "CTlist", "CTtype", "CTname")
107-
for (. in .SDE_METS) {
108-
setMethod(., "SpatialDataElement",
109-
eval(parse(text=sprintf("\\(x, ...) %s(meta(x), ...)", .))))
110-
}
106+
#' @rdname CTutils
107+
#' @export
108+
setMethod("axes", "SpatialDataElement", \(x, ...) axes(meta(x), ...))
109+
110+
#' @rdname CTutils
111+
#' @export
112+
setMethod("CTlist", "SpatialDataElement", \(x, ...) CTlist(meta(x), ...))
113+
114+
#' @rdname CTutils
115+
#' @export
116+
setMethod("CTtype", "SpatialDataElement", \(x, ...) CTtype(meta(x), ...))
117+
118+
#' @rdname CTutils
119+
#' @export
120+
setMethod("CTname", "SpatialDataElement", \(x, ...) CTname(meta(x), ...))
111121

112122
#' @rdname CTutils
113123
#' @export
@@ -185,7 +195,6 @@ setMethod("addCT", "SpatialDataElement",
185195
#' @rdname CTutils
186196
#' @export
187197
setMethod("addCT", "SpatialDataAttrs", \(x, name, type="identity", data=NULL) {
188-
#x <- meta(image(sd, 2)); name <- "lowres"; type="identity"; data=NULL
189198
stopifnot(
190199
is.character(name), length(name) == 1,
191200
is.character(type), length(type) == 1)

R/SDattrs.R

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
#' @param x element or list extracted from a OME-NGFF compliant .zattrs file.
55
#' @param name character string for extraction (see ?base::`$`).
66
#' @param type character string; either "array" (image/label) or "frame" (point/shape).
7-
#' @param axes list of axes; if NULL, defaults to cyx (array) or xy (frame).
8-
#' @param transformations list of transformations; if NULL, defaults to global identity.
7+
#' @param label flag; when \code{type="frame"}, should attributes be for a label?
8+
#' @param trans list of coordinate transformations; defaults to identity only.
9+
#' @param value character string (for one \code{region} and \code{_key}s),
10+
#' or vector (for many \code{region}s, \code{instances} and \code{regions}).
11+
#' @param ver character string; specified the .zarr version to comply with.
12+
#' @param nch scalar integer; how many channels should there be?
13+
#' (ignored unless \code{type="frame"} and \code{label=FALSE}).
914
#' @param ... additional attributes (e.g., version, feature_key).
1015
#'
1116
#' @details
@@ -42,12 +47,12 @@
4247
#' # constructor
4348
#' SpatialDataAttrs(type="frame")
4449
#' SpatialDataAttrs(type="array")
45-
#' SpatialDataAttrs(type="array", n=7)
50+
#' SpatialDataAttrs(type="array", nch=7)
4651
#' SpatialDataAttrs(type="array", label=TRUE)
4752
#'
4853
#' @export
4954
SpatialDataAttrs <- \(x, type=c("array", "frame"),
50-
label=FALSE, trans=NULL, ver="0.4", n=3, ...)
55+
label=FALSE, trans=NULL, ver="0.4", nch=3, ...)
5156
{
5257
if (!missing(x)) return(.SpatialDataAttrs(x))
5358
type <- match.arg(type)
@@ -68,7 +73,7 @@ SpatialDataAttrs <- \(x, type=c("array", "frame"),
6873
if (type == "array") {
6974
# default structure
7075
res <- list(
71-
omero=list(channels=list(label=letters[seq_len(n)])),
76+
omero=list(channels=list(label=letters[seq_len(nch)])),
7277
multiscales=list(list(
7378
axes=ax,
7479
version="0.4",
@@ -126,20 +131,10 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]])
126131
#' @noRd
127132
.ms <- \(x) switch(.zv(x), "0.3"=x$ome$multiscales, x$multiscales)
128133

129-
# internal use only!
130-
#' @noRd
131-
.ch <- \(x) {
132-
if (.zv(x) == "0.3") x <- x$ome
133-
unlist(x$omero$channels)
134-
}
135-
136134
# internal use only!
137135
#' @noRd
138136
setMethod("multiscales", "list", .ms)
139137

140-
#' @export
141-
setMethod("channels", "SpatialDataAttrs", \(x, ...) .ch(x))
142-
143138
# features ----
144139

145140
#' @export

R/methods.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,24 @@ setMethod("element", c("SpatialData", "ANY"), \(x, i)
144144

145145
# get all ----
146146

147-
#' @name SpatialData
148-
#' @exportMethod images labels points shapes tables
147+
#' @export
148+
#' @rdname SpatialData
149149
setMethod("images", "SpatialData", \(x) x$images)
150+
151+
#' @export
152+
#' @rdname SpatialData
150153
setMethod("labels", "SpatialData", \(x) x$labels)
154+
155+
#' @export
156+
#' @rdname SpatialData
151157
setMethod("points", "SpatialData", \(x) x$points)
158+
159+
#' @export
160+
#' @rdname SpatialData
152161
setMethod("shapes", "SpatialData", \(x) x$shapes)
162+
163+
#' @export
164+
#' @rdname SpatialData
153165
setMethod("tables", "SpatialData", \(x) x$tables)
154166

155167
# get nms ----

R/sdArray.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#'
1717
#' (x <- readImage(pa[2]))
1818
#'
19-
#' channels(x)
2019
#' data_type(x)
2120
#' dim(data(x, 1)) # highest res.
2221
#' dim(data(x, Inf)) # lowest res.

R/sdImage.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#' # multi-scale
2929
#' (x <- readImage(pa[2]))
3030
#'
31+
#' channels(x)
3132
#' dim(data(x, 1)) # highest res.
3233
#' dim(data(x, Inf)) # lowest res.
3334
#'
@@ -37,23 +38,36 @@
3738
#' plot(
3839
#' row(rgb), col(rgb), col=rgb,
3940
#' pch=15, asp=1, ylim=c(ncol(rgb), 0))
40-
#'
41-
#' @importFrom S4Vectors metadata<-
42-
#' @importFrom methods new
41+
NULL
42+
4343
#' @export
44+
#' @rdname SpatialDataImage
45+
#' @importFrom methods new
46+
#' @importFrom S4Vectors metadata<-
4447
SpatialDataImage <- function(data=list(), meta=SpatialDataAttrs(), metadata=list(), ...) {
4548
x <- .SpatialDataImage(data=data, meta=meta, ...)
4649
metadata(x) <- metadata
4750
return(x)
4851
}
4952

53+
# internal use only!
54+
#' @noRd
55+
.ch <- \(x) {
56+
if (.zv(x) == "0.3") x <- x$ome
57+
unlist(x$omero$channels)
58+
}
59+
60+
#' @export
61+
#' @rdname SpatialDataImage
62+
setMethod("channels", "SpatialDataAttrs", \(x, ...) .ch(x))
63+
5064
#' @export
5165
#' @rdname SpatialDataImage
5266
setMethod("channels", "SpatialDataImage", \(x, ...) channels(meta(x)))
5367

5468
#' @export
5569
#' @rdname SpatialDataImage
56-
setMethod("channels", "ANY", \(x, ...) stop("only 'images' have channels"))
70+
setMethod("channels", "SpatialDataElement", \(x, ...) stop("only 'images' have channels"))
5771

5872
#' @importFrom S4Vectors isSequence
5973
.get_multiscales_paths <- function(x) {

R/trans.R

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#' @aliases transform scale rotate translation flip flop mirror sequence
55
#'
66
#' @param x \code{SpatialData} element.
7+
#' @param i scalar integer or string; target coordinate space.
78
#' @param t transformation data; exceptions: for \code{mirror}, controls
89
#' whether to perform \bold{v}ertical or \bold{h}orizontal reflection;
910
#' no data is needed for \code{flip} (\bold{v}) and \code{flop} (\bold{h}).
1011
#' @param k scalar index specifying which scale to use;
1112
#' \code{Inf} to use lowest available resolution;
1213
#' only applies to \code{SpatialDataArray}s (images, labels).
1314
#' @param ... option arguments passed to and from other methods.
15+
#' @param rev flag; should transformation(s) be reversed?
1416
#'
1517
#' @returns \code{SpatialData} element with transformation(s) applied.
1618
#'
@@ -48,11 +50,15 @@ NULL
4850

4951
#' @export
5052
#' @rdname trans
51-
setMethod("transform", c("SpatialDataElement", "missing"), \(x, i, ...) transform(x, 1, ...))
53+
setMethod("transform",
54+
c("SpatialDataElement", "missing"),
55+
\(x, i, ...) transform(x, 1, ...))
5256

5357
#' @export
5458
#' @rdname trans
55-
setMethod("transform", c("SpatialDataElement", "numeric"), \(x, i, ...) transform(x, CTname(x)[i], ...))
59+
setMethod("transform",
60+
c("SpatialDataElement", "numeric"),
61+
\(x, i, ...) transform(x, CTname(x)[i], ...))
5662

5763
#' @export
5864
#' @rdname trans
@@ -100,30 +106,26 @@ setMethod("flip", "SpatialDataArray", \(x, k=1, ...) .mirror(x, -90, k))
100106
#' @rdname trans
101107
setMethod("flop", "SpatialDataArray", \(x, k=1, ...) .mirror(x, 90, k))
102108

103-
#' @importFrom methods as
104-
#' @importFrom S4Vectors metadata<-
105-
.trans_a. <- \(x, f, k=1) {
106-
a <- f(aperm(as.array(data(x, k))))
107-
metadata(x)$data_type <- data_type(x)
108-
data(x) <- list(as(aperm(a), "SparseArray"))
109-
return(x)
110-
}
111-
112109
# rotation matrix to rotate points counter-clockwise through an angle 't'
113110
.R <- \(t) matrix(c(cos(t), -sin(t), sin(t), cos(t)), 2, 2)
114111

115112
#' @export
116113
#' @rdname trans
114+
#' @importFrom methods as
117115
#' @importFrom EBImage rotate
116+
#' @importFrom S4Vectors metadata<-
118117
setMethod("rotate", c("SpatialDataArray", "numeric"), \(x, t, k=1, ..., rev=FALSE) {
119118
# negate angle since 'EBImage' rotates clockwise
120119
stopifnot(length(t) == 1, is.finite(t))
121120
if (t %% 360 == 0) return(x)
122121
if (rev) t <- -t
123-
f <- \(.) EBImage::rotate(., -t)
124122
if (length(d <- dim(data(x, k))) == 3) d <- d[-1]
125123
metadata(x)$wh <- lapply(rev(d), \(.) c(c(0, .) %*% .R(t*pi/180)))
126-
.trans_a.(x, f, k)
124+
f <- \(.) EBImage::rotate(., -t)
125+
a <- f(aperm(as.array(data(x, k))))
126+
metadata(x)$data_type <- data_type(x)
127+
data(x) <- list(as(aperm(a), "SparseArray"))
128+
return(x)
127129
})
128130

129131
.trans_a <- \(x, t, f=c("scale", "translation"), k=1, rev=FALSE) {
@@ -153,25 +155,30 @@ setMethod("rotate", c("SpatialDataArray", "numeric"), \(x, t, k=1, ..., rev=FALS
153155

154156
#' @export
155157
#' @rdname trans
156-
setMethod("scale", c("SpatialDataArray", "numeric"), \(x, t, ...) .trans_a(x, t, "scale", ...))
158+
setMethod("scale",
159+
c("SpatialDataArray", "numeric"),
160+
\(x, t, ...) .trans_a(x, t, "scale", ...))
157161

158162
#' @export
159163
#' @rdname trans
160-
setMethod("translation", c("SpatialDataArray", "numeric"), \(x, t, ...) .trans_a(x, t, "translation", ...))
164+
setMethod("translation",
165+
c("SpatialDataArray", "numeric"),
166+
\(x, t, ...) .trans_a(x, t, "translation", ...))
161167

162168
# point/shape ----
163169

164170
#' @importFrom dplyr mutate
165171
#' @importFrom rlang call2 !!
166172
.trans_f <- \(x, t, f=c("scale", "rotate", "translation"), rev=FALSE) {
173+
ST_Scale <- ST_Rotate <- ST_Translate <- radius <- NULL # R CMD check
174+
167175
f <- match.arg(f)
168176
n <- length(axes(x))
169-
ST_Scale <- ST_Rotate <- ST_Translate <- NULL # R CMD check
170177

171178
# setup: length, identity, function
172179
map <- list(
173-
len=c(scale=n, translation=n, rotate=1),
174-
ids=c(scale=1, translation=0, rotate=0),
180+
len=c(scale=n, rotate=1, translation=n),
181+
ids=c(scale=1, rotate=0, translation=0),
175182
fns=c(scale="ST_Scale", rotate="ST_Rotate", translation="ST_Translate"))
176183

177184
# validation
@@ -202,12 +209,17 @@ setMethod("translation", c("SpatialDataArray", "numeric"), \(x, t, ...) .trans_a
202209
#' @export
203210
#' @rdname trans
204211
setMethod("rotate",
205-
c("SpatialDataFrame", "numeric"), \(x, t, ...) .trans_f(x, t, "rotate", ...))
212+
c("SpatialDataFrame", "numeric"),
213+
\(x, t, ...) .trans_f(x, t, "rotate", ...))
206214

207215
#' @export
208216
#' @rdname trans
209-
setMethod("scale", c("SpatialDataFrame", "numeric"), \(x, t, ...) .trans_f(x, t, "scale", ...))
217+
setMethod("scale",
218+
c("SpatialDataFrame", "numeric"),
219+
\(x, t, ...) .trans_f(x, t, "scale", ...))
210220

211221
#' @export
212222
#' @rdname trans
213-
setMethod("translation", c("SpatialDataFrame", "numeric"), \(x, t, ...) .trans_f(x, t, "translation", ...))
223+
setMethod("translation",
224+
c("SpatialDataFrame", "numeric"),
225+
\(x, t, ...) .trans_f(x, t, "translation", ...))

man/CTutils.Rd

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/SpatialData.Rd

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/SpatialDataArray.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)