From 0d1a8b3a644a40f8f07408b11aa6a082b6a77acc Mon Sep 17 00:00:00 2001 From: Artur-man Date: Sun, 23 Mar 2025 21:43:29 +0100 Subject: [PATCH 1/6] show method for Zattr #83 --- R/Zattrs.R | 8 ++++++++ R/misc.R | 16 +++++++++++++++- .../blobs.zarr/images/blobs_image/.zattrs | 2 +- man/SpatialData.Rd | 8 ++++---- man/Zattrs.Rd | 3 +++ man/misc.Rd | 3 +++ 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/R/Zattrs.R b/R/Zattrs.R index 854443c..2c2ffc3 100644 --- a/R/Zattrs.R +++ b/R/Zattrs.R @@ -33,3 +33,11 @@ Zattrs <- \(x=list()) { #' @rdname Zattrs #' @exportMethod $ setMethod("$", "Zattrs", \(x, name) x[[name]]) + +#' @rdname Zattrs +#' @export +setMethod("channels", "Zattrs", \(x) { + if (!is.null(o <- x$omero)) x <- o + if (!is.null(c <- x$channel)) x <- c + x$label +}) \ No newline at end of file diff --git a/R/misc.R b/R/misc.R index f208609..075ca7b 100644 --- a/R/misc.R +++ b/R/misc.R @@ -110,4 +110,18 @@ setMethod("show", "PointFrame", .showPointFrame) } #' @rdname misc -setMethod("show", "ShapeFrame", .showShapeFrame) \ No newline at end of file +setMethod("show", "ShapeFrame", .showShapeFrame) + +#' @importFrom S4Vectors coolcat +.showZattrs <- function(object) { + cat("class: Zattrs\n") + # axes + coolcat("axes(%d): %s\n", axes(object)[["name"]]) + # channel if exists + c <- channels(object) + if(!is.null(c)) + coolcat("channels(%d): %s\n", channels(object)) +} + +#' @rdname misc +setMethod("show", "Zattrs", .showZattrs) \ No newline at end of file diff --git a/inst/extdata/blobs.zarr/images/blobs_image/.zattrs b/inst/extdata/blobs.zarr/images/blobs_image/.zattrs index dbf8218..b84e2b5 100644 --- a/inst/extdata/blobs.zarr/images/blobs_image/.zattrs +++ b/inst/extdata/blobs.zarr/images/blobs_image/.zattrs @@ -108,4 +108,4 @@ "spatialdata_attrs": { "version": "0.1" } -} \ No newline at end of file +} diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index 9521d85..e760cfd 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -50,8 +50,8 @@ \alias{element,SpatialData,ANY,numeric-method} \alias{element,SpatialData,ANY,missing-method} \alias{element,SpatialData,ANY,ANY-method} -\alias{[[<-,SpatialData,numeric,ANY,ANY-method} -\alias{[[<-,SpatialData,character,ANY,ANY-method} +\alias{[[<-,SpatialData,numeric,ANY-method} +\alias{[[<-,SpatialData,character,ANY-method} \title{The `SpatialData` class} \usage{ SpatialData(images, labels, points, shapes, tables) @@ -88,9 +88,9 @@ SpatialData(images, labels, points, shapes, tables) \S4method{element}{SpatialData,ANY,ANY}(x, i, j) -\S4method{[[}{SpatialData,numeric,ANY,ANY}(x, i) <- value +\S4method{[[}{SpatialData,numeric,ANY}(x, i) <- value -\S4method{[[}{SpatialData,character,ANY,ANY}(x, i) <- value +\S4method{[[}{SpatialData,character,ANY}(x, i) <- value } \arguments{ \item{images}{list of \code{\link{ImageArray}}s} diff --git a/man/Zattrs.Rd b/man/Zattrs.Rd index b736e2e..864d4d2 100644 --- a/man/Zattrs.Rd +++ b/man/Zattrs.Rd @@ -3,11 +3,14 @@ \name{Zattrs} \alias{Zattrs} \alias{$,Zattrs-method} +\alias{channels,Zattrs-method} \title{The `Zattrs` class} \usage{ Zattrs(x = list()) \S4method{$}{Zattrs}(x, name) + +\S4method{channels}{Zattrs}(x) } \arguments{ \item{x}{list extracted from a OME-NGFF compliant .zattrs file.} diff --git a/man/misc.Rd b/man/misc.Rd index b63a1e8..a867419 100644 --- a/man/misc.Rd +++ b/man/misc.Rd @@ -7,6 +7,7 @@ \alias{show,LabelArray-method} \alias{show,PointFrame-method} \alias{show,ShapeFrame-method} +\alias{show,Zattrs-method} \title{Miscellaneous `Miro` methods} \usage{ \S4method{show}{SpatialData}(object) @@ -18,6 +19,8 @@ \S4method{show}{PointFrame}(object) \S4method{show}{ShapeFrame}(object) + +\S4method{show}{Zattrs}(object) } \arguments{ \item{object}{\code{\link{SpatialData}} object or one of its From 82458f10bde0e251bf3475a312384c19c8df1d96 Mon Sep 17 00:00:00 2001 From: Artur-man Date: Mon, 31 Mar 2025 00:54:58 +0200 Subject: [PATCH 2/6] added additional methods for Zattrs show method --- NAMESPACE | 1 + R/AllGenerics.R | 1 + R/ImageArray.R | 2 +- R/Zattrs.R | 14 +++++++++++++- R/coord_utils.R | 12 +++++++++--- R/methods.R | 7 +++++++ R/misc.R | 10 +++++++--- man/SpatialData.Rd | 4 ++++ man/Zattrs.Rd | 3 +++ man/coord-utils.Rd | 4 +++- tests/testthat/test-zattrs.R | 3 +++ 11 files changed, 52 insertions(+), 9 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index d91581e..75ddaa8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -49,6 +49,7 @@ exportMethods(axes) exportMethods(channels) exportMethods(colnames) exportMethods(data) +exportMethods(datasets) exportMethods(dim) exportMethods(element) exportMethods(getTable) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 6e0a948..2ceafa2 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -80,6 +80,7 @@ setGeneric("query", \(x, ...) standardGeneric("query")) setGeneric("mask", \(x, i, j, ...) standardGeneric("mask")) setGeneric("channels", \(x, ...) standardGeneric("channels")) +setGeneric("datasets", \(x, ...) standardGeneric("datasets")) # tbl ---- diff --git a/R/ImageArray.R b/R/ImageArray.R index e582239..4c67e44 100644 --- a/R/ImageArray.R +++ b/R/ImageArray.R @@ -32,7 +32,7 @@ ImageArray <- function(data=list(), meta=Zattrs(), metadata=list(), ...) { #' @rdname ImageArray #' @aliases channels #' @export -setMethod("channels", "ImageArray", \(x, ...) meta(x)$omero$channels$label) +setMethod("channels", "ImageArray", \(x, ...) channels(meta(x))) #' @rdname ImageArray #' @export diff --git a/R/Zattrs.R b/R/Zattrs.R index 2c2ffc3..e78d18f 100644 --- a/R/Zattrs.R +++ b/R/Zattrs.R @@ -40,4 +40,16 @@ setMethod("channels", "Zattrs", \(x) { if (!is.null(o <- x$omero)) x <- o if (!is.null(c <- x$channel)) x <- c x$label -}) \ No newline at end of file +}) + +#' @rdname Zattrs +#' @export +setMethod("datasets", "Zattrs", \(x) { + if (!is.null(ms <- x$multiscales)) x <- ms + if (!is.null(d <- x$datasets)) x <- d[[1]] + x$path +}) + +#' @aliases datasets +#' @export +setMethod("datasets", "ANY", \(x, ...) datasets(meta(x))) \ No newline at end of file diff --git a/R/coord_utils.R b/R/coord_utils.R index 4dbe2c4..732b79b 100644 --- a/R/coord_utils.R +++ b/R/coord_utils.R @@ -51,16 +51,22 @@ NULL # axes() ---- #' @rdname coord-utils +#' @param simple if TRUE, axes data.frame is simplified #' @export -setMethod("axes", "Zattrs", \(x, ...) { +setMethod("axes", "Zattrs", \(x, simple = FALSE, ...) { if (!is.null(ms <- x$multiscales)) x <- ms if (is.null(x <- x$axes)) stop("couldn't find 'axes'") - if (is.character(x)) x else x[[1]] + if (is.character(x)){ + return(x) + } else { + x <- x[[1]] + return(if(simple) paste(x$name,x$type, sep = ":") else x) + } }) #' @rdname coord-utils #' @export -setMethod("axes", "SpatialDataElement", \(x, ...) axes(meta(x))) +setMethod("axes", "SpatialDataElement", \(x, ...) axes(meta(x), ...)) # CTdata/type/name() ---- diff --git a/R/methods.R b/R/methods.R index eaf7dc4..14ef197 100644 --- a/R/methods.R +++ b/R/methods.R @@ -71,6 +71,13 @@ setMethod("data", "SpatialDataElement", \(x) x@data) #' @export setMethod("meta", "SpatialDataElement", \(x) x@meta) +# datasets ---- + +#' @rdname SpatialData +#' @aliases datasets +#' @export +setMethod("datasets", "SpatialDataElement", \(x, ...) datasets(meta(x))) + # row/colnms ---- #' @rdname SpatialData diff --git a/R/misc.R b/R/misc.R index 075ca7b..64ed016 100644 --- a/R/misc.R +++ b/R/misc.R @@ -116,11 +116,15 @@ setMethod("show", "ShapeFrame", .showShapeFrame) .showZattrs <- function(object) { cat("class: Zattrs\n") # axes - coolcat("axes(%d): %s\n", axes(object)[["name"]]) + coolcat("axes(%d): %s\n", axes(object, simple = TRUE)) # channel if exists - c <- channels(object) - if(!is.null(c)) + if(!is.null(c <- channels(object))) coolcat("channels(%d): %s\n", channels(object)) + # transformations + coolcat("transformations(%d): %s\n", CTname(object)) + # datasets + if(!is.null(c <- datasets(object))) + coolcat("datasets(%d): %s\n", datasets(object)) } #' @rdname misc diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index e760cfd..9b71d53 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -40,6 +40,8 @@ \alias{[,SpatialData,ANY,ANY,ANY-method} \alias{data,SpatialDataElement-method} \alias{meta,SpatialDataElement-method} +\alias{datasets,SpatialDataElement-method} +\alias{datasets} \alias{rownames,SpatialData-method} \alias{colnames,SpatialData-method} \alias{layer,SpatialData,character-method} @@ -68,6 +70,8 @@ SpatialData(images, labels, points, shapes, tables) \S4method{meta}{SpatialDataElement}(x) +\S4method{datasets}{SpatialDataElement}(x, ...) + \S4method{rownames}{SpatialData}(x) \S4method{colnames}{SpatialData}(x) diff --git a/man/Zattrs.Rd b/man/Zattrs.Rd index 864d4d2..43f223c 100644 --- a/man/Zattrs.Rd +++ b/man/Zattrs.Rd @@ -4,6 +4,7 @@ \alias{Zattrs} \alias{$,Zattrs-method} \alias{channels,Zattrs-method} +\alias{datasets,Zattrs-method} \title{The `Zattrs` class} \usage{ Zattrs(x = list()) @@ -11,6 +12,8 @@ Zattrs(x = list()) \S4method{$}{Zattrs}(x, name) \S4method{channels}{Zattrs}(x) + +\S4method{datasets}{Zattrs}(x) } \arguments{ \item{x}{list extracted from a OME-NGFF compliant .zattrs file.} diff --git a/man/coord-utils.Rd b/man/coord-utils.Rd index a321588..c8cc75f 100644 --- a/man/coord-utils.Rd +++ b/man/coord-utils.Rd @@ -30,7 +30,7 @@ \alias{addCT,Zattrs-method} \title{Coordinate transformations} \usage{ -\S4method{axes}{Zattrs}(x, ...) +\S4method{axes}{Zattrs}(x, simple = FALSE, ...) \S4method{axes}{SpatialDataElement}(x, ...) @@ -69,6 +69,8 @@ \arguments{ \item{x}{\code{SpatialData}, an element, or \code{Zattrs}.} +\item{simple}{if TRUE, axes data.frame is simplified} + \item{...}{option arguments passed to and from other methods.} \item{i}{for \code{CTpath}, source node label; else, string or diff --git a/tests/testthat/test-zattrs.R b/tests/testthat/test-zattrs.R index c618854..14138a4 100644 --- a/tests/testthat/test-zattrs.R +++ b/tests/testthat/test-zattrs.R @@ -7,6 +7,9 @@ test_that("axes", { y <- axes(image(x)) expect_is(y, "data.frame") expect_equal(dim(y), c(3, 2)) + y <- axes(image(x), simple = TRUE) + expect_is(y, "character") + expect_equal(length(y), 3) # label y <- axes(label(x)) expect_is(y, "data.frame") From e4f1991a78f90deaf3d091eaea8ca4ea64dcca0c Mon Sep 17 00:00:00 2001 From: Artur-man Date: Mon, 31 Mar 2025 09:55:28 +0200 Subject: [PATCH 3/6] remove redundant method definitions --- R/Zattrs.R | 6 +----- inst/extdata/blobs.zarr/images/blobs_image/.zattrs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/R/Zattrs.R b/R/Zattrs.R index e78d18f..3d52bc6 100644 --- a/R/Zattrs.R +++ b/R/Zattrs.R @@ -48,8 +48,4 @@ setMethod("datasets", "Zattrs", \(x) { if (!is.null(ms <- x$multiscales)) x <- ms if (!is.null(d <- x$datasets)) x <- d[[1]] x$path -}) - -#' @aliases datasets -#' @export -setMethod("datasets", "ANY", \(x, ...) datasets(meta(x))) \ No newline at end of file +}) \ No newline at end of file diff --git a/inst/extdata/blobs.zarr/images/blobs_image/.zattrs b/inst/extdata/blobs.zarr/images/blobs_image/.zattrs index b84e2b5..dbf8218 100644 --- a/inst/extdata/blobs.zarr/images/blobs_image/.zattrs +++ b/inst/extdata/blobs.zarr/images/blobs_image/.zattrs @@ -108,4 +108,4 @@ "spatialdata_attrs": { "version": "0.1" } -} +} \ No newline at end of file From ec2d26001e8e65679fadbfc0ed87603b73022677 Mon Sep 17 00:00:00 2001 From: Artur-man Date: Sat, 3 May 2025 23:24:53 +0200 Subject: [PATCH 4/6] improve zattrs datasets show method --- R/Zattrs.R | 3 ++- R/misc.R | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/R/Zattrs.R b/R/Zattrs.R index 3d52bc6..3bc481c 100644 --- a/R/Zattrs.R +++ b/R/Zattrs.R @@ -47,5 +47,6 @@ setMethod("channels", "Zattrs", \(x) { setMethod("datasets", "Zattrs", \(x) { if (!is.null(ms <- x$multiscales)) x <- ms if (!is.null(d <- x$datasets)) x <- d[[1]] - x$path + # x$path + x }) \ No newline at end of file diff --git a/R/misc.R b/R/misc.R index 64ed016..7c03603 100644 --- a/R/misc.R +++ b/R/misc.R @@ -116,15 +116,23 @@ setMethod("show", "ShapeFrame", .showShapeFrame) .showZattrs <- function(object) { cat("class: Zattrs\n") # axes - coolcat("axes(%d): %s\n", axes(object, simple = TRUE)) - # channel if exists - if(!is.null(c <- channels(object))) - coolcat("channels(%d): %s\n", channels(object)) + coolcat("axes(%d): %s\n", paste0(axes(object, simple = TRUE))) # transformations coolcat("transformations(%d): %s\n", CTname(object)) # datasets - if(!is.null(c <- datasets(object))) - coolcat("datasets(%d): %s\n", datasets(object)) + if(!is.null(d <- datasets(object))){ + cat(sprintf("datasets(%d): \n", nrow(d))) + coolcat("- path(%d): %s\n", d$path) + ct <- d$coordinateTransformations + coolcat("- type(%d): %s\n", vapply(ct, \(x) x$type, character(1))) + coolcat("- cTrans(%d): %s\n", + vapply(ct, + \(x) paste0("(", paste(x[[x$type]][[1]], collapse = ","), ")"), + character(1))) + } + # channel + if(!is.null(c <- channels(object))) + coolcat("channels(%d): %s\n", channels(object)) } #' @rdname misc From ad5bb744e52e5f4ecf2061ef57b43bbe27ccd163 Mon Sep 17 00:00:00 2001 From: Artur-man Date: Sun, 4 May 2025 11:59:16 +0200 Subject: [PATCH 5/6] list dataset transformations in zattrs show method --- R/Zattrs.R | 8 +++++--- R/coord_utils.R | 6 ++---- R/misc.R | 33 ++++++++++++++++++++++++--------- tests/testthat/test-zattrs.R | 3 --- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/R/Zattrs.R b/R/Zattrs.R index 3bc481c..5c2a1fe 100644 --- a/R/Zattrs.R +++ b/R/Zattrs.R @@ -46,7 +46,9 @@ setMethod("channels", "Zattrs", \(x) { #' @export setMethod("datasets", "Zattrs", \(x) { if (!is.null(ms <- x$multiscales)) x <- ms - if (!is.null(d <- x$datasets)) x <- d[[1]] - # x$path - x + if (!is.null(d <- x$datasets)){ + d[[1]] + } else { + NULL + } }) \ No newline at end of file diff --git a/R/coord_utils.R b/R/coord_utils.R index 732b79b..8641764 100644 --- a/R/coord_utils.R +++ b/R/coord_utils.R @@ -51,16 +51,14 @@ NULL # axes() ---- #' @rdname coord-utils -#' @param simple if TRUE, axes data.frame is simplified #' @export -setMethod("axes", "Zattrs", \(x, simple = FALSE, ...) { +setMethod("axes", "Zattrs", \(x, ...) { if (!is.null(ms <- x$multiscales)) x <- ms if (is.null(x <- x$axes)) stop("couldn't find 'axes'") if (is.character(x)){ return(x) } else { - x <- x[[1]] - return(if(simple) paste(x$name,x$type, sep = ":") else x) + x[[1]] } }) diff --git a/R/misc.R b/R/misc.R index 7c03603..fe707ce 100644 --- a/R/misc.R +++ b/R/misc.R @@ -115,21 +115,36 @@ setMethod("show", "ShapeFrame", .showShapeFrame) #' @importFrom S4Vectors coolcat .showZattrs <- function(object) { cat("class: Zattrs\n") + # axes - coolcat("axes(%d): %s\n", paste0(axes(object, simple = TRUE))) + ax <- axes(object) + if(!is(ax, "data.frame")) + ax <- data.frame(name = ax) + cat(sprintf("axes(%d): \n", nrow(ax))) + for(. in seq_along(ax)){ + coolcat(paste0("- ", names(ax)[[.]], "(%d): %s\n"), ax[[.]]) + } + # transformations coolcat("transformations(%d): %s\n", CTname(object)) + # datasets if(!is.null(d <- datasets(object))){ - cat(sprintf("datasets(%d): \n", nrow(d))) - coolcat("- path(%d): %s\n", d$path) - ct <- d$coordinateTransformations - coolcat("- type(%d): %s\n", vapply(ct, \(x) x$type, character(1))) - coolcat("- cTrans(%d): %s\n", - vapply(ct, - \(x) paste0("(", paste(x[[x$type]][[1]], collapse = ","), ")"), - character(1))) + coolcat("datasets(%d): %s\n", d$path) + ct <- vapply(d$coordinateTransformations, \(x) + paste( + apply(x, 1, \(y) + paste0("(", x$type, ":", + paste(x[[x$type]][[1]], collapse = ","), + ")") + ), collapse = ", " + ), + character(1)) + for(. in seq_along(ct)){ + cat(sprintf("- %s: %s", d$path[.], ct[.]), "\n") + } } + # channel if(!is.null(c <- channels(object))) coolcat("channels(%d): %s\n", channels(object)) diff --git a/tests/testthat/test-zattrs.R b/tests/testthat/test-zattrs.R index 14138a4..c618854 100644 --- a/tests/testthat/test-zattrs.R +++ b/tests/testthat/test-zattrs.R @@ -7,9 +7,6 @@ test_that("axes", { y <- axes(image(x)) expect_is(y, "data.frame") expect_equal(dim(y), c(3, 2)) - y <- axes(image(x), simple = TRUE) - expect_is(y, "character") - expect_equal(length(y), 3) # label y <- axes(label(x)) expect_is(y, "data.frame") From 022402fecc18c033ed76ea0c34a9e4ad2646c105 Mon Sep 17 00:00:00 2001 From: Artur-man Date: Fri, 9 May 2025 23:39:55 +0200 Subject: [PATCH 6/6] update Zattrs show method for transformations --- R/coord_utils.R | 12 ++++++ R/misc.R | 71 +++++++++++++++++++++++++++++------- man/SpatialData.Rd | 8 ++-- man/coord-utils.Rd | 10 +++-- tests/testthat/test-zattrs.R | 11 ++++++ 5 files changed, 92 insertions(+), 20 deletions(-) diff --git a/R/coord_utils.R b/R/coord_utils.R index 8641764..68f6c41 100644 --- a/R/coord_utils.R +++ b/R/coord_utils.R @@ -123,6 +123,11 @@ setMethod("CTgraph", "SpatialData", \(x) { setMethod("CTgraph", "SpatialDataElement", \(x) .make_g(list("mock"=list("self"=meta(x))))) +#' @rdname coord-utils +#' @export +setMethod("CTgraph", "Zattrs", \(x) + .make_g(list("mock"=list("self"=x)))) + #' @rdname coord-utils #' @export setMethod("CTgraph", "ANY", \(x) stop("'x' should be a", @@ -200,6 +205,13 @@ setMethod("CTpath", "SpatialDataElement", \(x, j) { .path_ij(g, "self", j) }) +#' @rdname coord-utils +#' @export +setMethod("CTpath", "Zattrs", \(x, j) { + g <- CTgraph(x) + .path_ij(g, "self", j) +}) + #' @importFrom graph edgeData #' @importFrom RBGL sp.between .path_ij <- \(g, i, j) { diff --git a/R/misc.R b/R/misc.R index fe707ce..d480dbb 100644 --- a/R/misc.R +++ b/R/misc.R @@ -112,31 +112,26 @@ setMethod("show", "PointFrame", .showPointFrame) #' @rdname misc setMethod("show", "ShapeFrame", .showShapeFrame) -#' @importFrom S4Vectors coolcat -.showZattrs <- function(object) { - cat("class: Zattrs\n") - - # axes +.showZattrsAxes <- function(object){ ax <- axes(object) if(!is(ax, "data.frame")) ax <- data.frame(name = ax) cat(sprintf("axes(%d): \n", nrow(ax))) for(. in seq_along(ax)){ - coolcat(paste0("- ", names(ax)[[.]], "(%d): %s\n"), ax[[.]]) + cat(sprintf(paste0("- ", names(ax)[[.]], ": %s\n"), + paste(ax[[.]], collapse = " "))) } - - # transformations - coolcat("transformations(%d): %s\n", CTname(object)) - - # datasets +} + +.showZattrsDatasets <- function(object){ if(!is.null(d <- datasets(object))){ coolcat("datasets(%d): %s\n", d$path) ct <- vapply(d$coordinateTransformations, \(x) paste( apply(x, 1, \(y) - paste0("(", x$type, ":", + paste0("(", x$type, ":", "[", paste(x[[x$type]][[1]], collapse = ","), - ")") + "]", ")") ), collapse = ", " ), character(1)) @@ -144,7 +139,57 @@ setMethod("show", "ShapeFrame", .showShapeFrame) cat(sprintf("- %s: %s", d$path[.], ct[.]), "\n") } } +} + +.collapse_trans_data <- function(data){ + if(is.null(data)){ + return(NULL) + } else if(is.matrix(data)){ + return( + paste0("[", + paste( + apply(data, 1, \(x){ + paste0("[", + paste(x, collapse = ","), + "]") + }), + collapse = ","), + "]") + ) + } else{ + return(paste0("[",paste(data, collapse = ","), "]")) + } +} +.showZattrsTransformations <- function(object){ + ctdata.name <- CTname(object) + cat(sprintf("coordTrans(%d):\n", length(ctdata.name))) + for(. in seq_along(ctdata.name)){ + ct <- CTpath(object, ctdata.name[[.]]) + cat(sprintf(paste0("- ", ctdata.name[[.]],": ", + paste( + vapply(ct, \(x) { + paste0("(", + x$type, + if(!is.null(x$data)) + paste0(":", .collapse_trans_data(x$data)), + ")") + }, character(1)), + collapse = ", "), + "\n"))) + } +} + +#' @importFrom S4Vectors coolcat +.showZattrs <- function(object) { + cat("class: Zattrs\n") + # axes + .showZattrsAxes(object) + # transformations + # coolcat("transformations(%d): %s\n", CTname(object)) + .showZattrsTransformations(object) + # datasets + .showZattrsDatasets(object) # channel if(!is.null(c <- channels(object))) coolcat("channels(%d): %s\n", channels(object)) diff --git a/man/SpatialData.Rd b/man/SpatialData.Rd index 9b71d53..623ae19 100644 --- a/man/SpatialData.Rd +++ b/man/SpatialData.Rd @@ -52,8 +52,8 @@ \alias{element,SpatialData,ANY,numeric-method} \alias{element,SpatialData,ANY,missing-method} \alias{element,SpatialData,ANY,ANY-method} -\alias{[[<-,SpatialData,numeric,ANY-method} -\alias{[[<-,SpatialData,character,ANY-method} +\alias{[[<-,SpatialData,numeric,ANY,ANY-method} +\alias{[[<-,SpatialData,character,ANY,ANY-method} \title{The `SpatialData` class} \usage{ SpatialData(images, labels, points, shapes, tables) @@ -92,9 +92,9 @@ SpatialData(images, labels, points, shapes, tables) \S4method{element}{SpatialData,ANY,ANY}(x, i, j) -\S4method{[[}{SpatialData,numeric,ANY}(x, i) <- value +\S4method{[[}{SpatialData,numeric,ANY,ANY}(x, i) <- value -\S4method{[[}{SpatialData,character,ANY}(x, i) <- value +\S4method{[[}{SpatialData,character,ANY,ANY}(x, i) <- value } \arguments{ \item{images}{list of \code{\link{ImageArray}}s} diff --git a/man/coord-utils.Rd b/man/coord-utils.Rd index c8cc75f..a3078c9 100644 --- a/man/coord-utils.Rd +++ b/man/coord-utils.Rd @@ -21,16 +21,18 @@ \alias{CTname,SpatialData-method} \alias{CTgraph,SpatialData-method} \alias{CTgraph,SpatialDataElement-method} +\alias{CTgraph,Zattrs-method} \alias{CTgraph,ANY-method} \alias{CTpath,SpatialData-method} \alias{CTpath,SpatialDataElement-method} +\alias{CTpath,Zattrs-method} \alias{rmvCT,SpatialDataElement-method} \alias{rmvCT,Zattrs-method} \alias{addCT,SpatialDataElement-method} \alias{addCT,Zattrs-method} \title{Coordinate transformations} \usage{ -\S4method{axes}{Zattrs}(x, simple = FALSE, ...) +\S4method{axes}{Zattrs}(x, ...) \S4method{axes}{SpatialDataElement}(x, ...) @@ -52,12 +54,16 @@ \S4method{CTgraph}{SpatialDataElement}(x) +\S4method{CTgraph}{Zattrs}(x) + \S4method{CTgraph}{ANY}(x) \S4method{CTpath}{SpatialData}(x, i, j) \S4method{CTpath}{SpatialDataElement}(x, j) +\S4method{CTpath}{Zattrs}(x, j) + \S4method{rmvCT}{SpatialDataElement}(x, i) \S4method{rmvCT}{Zattrs}(x, i) @@ -69,8 +75,6 @@ \arguments{ \item{x}{\code{SpatialData}, an element, or \code{Zattrs}.} -\item{simple}{if TRUE, axes data.frame is simplified} - \item{...}{option arguments passed to and from other methods.} \item{i}{for \code{CTpath}, source node label; else, string or diff --git a/tests/testthat/test-zattrs.R b/tests/testthat/test-zattrs.R index c618854..405925c 100644 --- a/tests/testthat/test-zattrs.R +++ b/tests/testthat/test-zattrs.R @@ -132,3 +132,14 @@ test_that("plotCoordGraph", { q <- f(plotCoordGraph(g, 0.9)) expect_true(p < q) }) + +test_that("show",{ + meta(image(x,1)) + meta(image(x,2)) + meta(label(x,1)) + meta(label(x,2)) + meta(shape(x,1)) + meta(shape(x,2)) + meta(shape(x,3)) + expect_equal(1L,1L) +}) \ No newline at end of file