Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Imports:
sf,
S4Arrays,
S4Vectors,
SparseArray,
SingleCellExperiment,
SummarizedExperiment
Suggests:
Expand All @@ -63,8 +62,7 @@ Suggests:
Rgraphviz,
SpatialData.data,
SpatialData.plot,
testthat,
DT
testthat
Remotes:
keller-mark/anndataR@spatialdata,
HelenaLC/SpatialData.data,
Expand Down
4 changes: 1 addition & 3 deletions R/ShapeFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ setMethod("names", "ShapeFrame", \(x) names(data(x)))
#' @export
#' @rdname ShapeFrame
#' @importFrom utils .DollarNames
.DollarNames.ShapeFrame <- \(x, pattern="") {
grep(pattern, names(x), value=TRUE)
}
.DollarNames.ShapeFrame <- \(x) grep("", names(x), value=TRUE)

#' @rdname ShapeFrame
#' @exportMethod $
Expand Down
2 changes: 2 additions & 0 deletions R/SpatialData.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' image images image<- images<- imageNames
#' shape shapes shape<- shapes<- shapeNames
#' table tables table<- tables<- tableNames
#' [[<-,SpatialData,character,ANY-method
#' [[<-,SpatialData,numeric,ANY-method
#'
#' @description ...
#'
Expand Down
36 changes: 34 additions & 2 deletions R/Zattrs.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#' @name Zattrs
#' @title The `Zattrs` class
#'
#' @aliases feature_key
#'
#' @param x list extracted from a OME-NGFF compliant .zattrs file.
#' @param name character string for extraction (see ?base::`$`).
#'
Expand Down Expand Up @@ -80,22 +78,56 @@ setMethod("$", "Zattrs", \(x, name) x[[name]])
}
setMethod("show", "Zattrs", .showZattrs)

#' @name SDattrs
#' @title \code{SpatialData} attributes
#'
#' @aliases
#' region
#' region_key
#' feature_key
#' instance_key
#'
#' @param x depends on which attributes are available;
#' specifically, \code{PointFrame} (\code{feature/instance_key}), or
#' \code{SingleCellExperiment} (\code{region}, \code{region/instance_key}),
#'
#' @return character string
#'
#' @examples
#' x <- file.path("extdata", "blobs.zarr")
#' x <- system.file(x, package="SpatialData")
#' x <- readSpatialData(x, anndataR=TRUE)
#'
#' region(table(x))
#' region_key(table(x))
#'
#' instance_key(point(x))
#' fk <- feature_key(point(x))
#' base::table(point(x)[[fk]])
NULL

# TODO: only points can have this?
#' @export
#' @rdname SDattrs
setMethod("feature_key", "list", \(x) x$spatialdata_attrs$feature_key)
#' @export
setMethod("feature_key", "PointFrame", \(x) feature_key(meta(x)))

# TODO: only tables can have this?
#' @export
#' @rdname SDattrs
setMethod("region_key", "SingleCellExperiment", \(x) meta(x)$region_key)
#' @export
#' @rdname SDattrs
setMethod("region", "SingleCellExperiment", \(x) meta(x)[[region_key(x)]])

# TODO: only tables and points can have this?
#' @export
#' @rdname SDattrs
setMethod("instance_key", "list", \(x) x$instance_key)
#' @export
#' @rdname SDattrs
setMethod("instance_key", "PointFrame", \(x) instance_key(meta(x)$spatialdata_attrs))
#' @export
#' @rdname SDattrs
setMethod("instance_key", "SingleCellExperiment", \(x) instance_key(meta(x)))
4 changes: 2 additions & 2 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#'
#' @param x \code{SpatialData} element.
#' @param y query specification;
#' bounding box: length-4 numeric list with names 'xmin/xmax/ymin/ymax'
#' (order is irrelevant); polygon: numeric matrix with 3 rows and 2 columns.
#' bounding box: length-4 numeric list with names 'xmin/xmax/ymin/ymax';
#' polygon: numeric matrix with at least 3 rows and exactly 2 columns.
#' @param i for \code{SpatialData}, index or name of table to query.
#' @param ... optional arguments passed to and from other methods.
#'
Expand Down
17 changes: 8 additions & 9 deletions R/sdArray.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#' @name Array-methods
#' @name sdArray
#' @title Methods for `ImageArray` and `LabelArray` class
#'
#' @aliases
#' data_type
#' data,ImageArray-method
#' data,LabelArray-method
#' dim,ImageArray-method
#' dim,LabelArray-method
#' length,ImageArray-method
#' length,LabelArray-method
#' data_type,ImageArray-method
#' data_type,LabelArray-method
#'
#' @param x \code{ImageArray} or \code{LabelArray}
#' @param k scalar index specifying which scale to extract.
Expand All @@ -30,7 +29,7 @@
#' @importFrom methods new
NULL

#' @rdname Array-methods
#' @rdname sdArray
#' @export
setMethod("data", "sdArray", \(x, k=1) {
if (is.null(k)) return(x@data)
Expand All @@ -41,25 +40,25 @@ setMethod("data", "sdArray", \(x, k=1) {
stop("'k=", k, "' but only ", n, " resolution(s) available")
})

#' @rdname Array-methods
#' @rdname sdArray
#' @export
setMethod("dim", "sdArray", \(x) dim(data(x)))

#' @rdname Array-methods
#' @rdname sdArray
#' @export
setMethod("length", "sdArray", \(x) length(data(x, NULL)))

#' @export
#' @rdname Array-methods
#' @rdname sdArray
#' @importFrom S4Vectors metadata
setMethod("data_type", "sdArray", \(x) {
if (is(y <- data(x), "DelayedArray"))
data_type(y) else metadata(x)$data_type
})

#' @rdname Array-methods
#' @export
#' @rdname sdArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom Rarr zarr_overview
#' @importFrom ZarrArray path
#' @export
setMethod("data_type", "DelayedArray", \(x) zarr_overview(path(x), as_data_frame=TRUE)$data_type)
6 changes: 3 additions & 3 deletions R/trans.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#' @title Transformations
#' @aliases scale rotate translation flip flop mirror
#'
#' @param x \code{SpatialData} element
#' @param j scalar character or numeric;
#' name or index of coordinate space.
#' @param x \code{SpatialData} element.
#' @param t transformation data; exceptions: for \code{mirror}, controls
#' whether to perform \bold{v}ertical or \bold{h}orizontal reflection;
#' no data is needed for \code{flip} (\bold{v}) and \code{flop} (\bold{h}).
Expand Down Expand Up @@ -106,6 +104,8 @@ setMethod("rotate", c("sdArray", "numeric"), \(x, t, k=1,...) {
.trans_a(x, f, k)
})

#' @export
#' @rdname trans
#' @importFrom EBImage translate
setMethod("translation", c("sdArray", "numeric"), \(x, t, k=1, ...) {
stopifnot(length(t) == length(dim(x)), is.finite(t))
Expand Down
5 changes: 3 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#' @title Utilities
#' @aliases centroids extent
#'
#' @param x a \code{SpatialData} element (any but image)
#' @param as determines how results will be returned
#' @param x a \code{SpatialData} element (any but image).
#' @param as character string; how results should be returned.
#' @param ... optional arguments passed to and from other methods.
#'
#' @examples
#' x <- file.path("extdata", "blobs.zarr")
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# `SpatialData`

[![x](https://github.com/HelenaLC/SpatialData/actions/workflows/check-bioc.yml/badge.svg?branch=main)](https://github.com/HelenaLC/SpatialData/actions/workflows/check-bioc.yml)

[![x](https://github.com/HelenaLC/SpatialData/actions/workflows/check-bioc.yml/badge.svg?branch=main&event=push)](https://github.com/HelenaLC/SpatialData/actions/workflows/check-bioc.yml)

> for a demo of the class, see the [vignette](https://htmlpreview.github.io/?https://github.com/HelenaLC/SpatialData/blob/main/vignettes/SpatialData.html)
Expand Down
51 changes: 51 additions & 0 deletions man/SDattrs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ShapeFrame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/SpatialData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/Zattrs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/Array-methods.Rd → man/sdArray.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/trans.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/utils.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading