Skip to content
Draft
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
9 changes: 6 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Generated by roxygen2: do not edit by hand

S3method("[",ome_zarr)
S3method(dimnames,ome_zarr)
S3method(plot,ome_zarr)
S3method(print,ome_zarr)
export(extract_levels)
export(ome_read)
export(ome_validate)
export(ome_write)
export(print.ome_zarr)
exportMethods(ome_write)
exportMethods(print)
exportMethods(show)
import(methods)
importFrom(EBImage,Image)
importFrom(EBImage,imageData)
importFrom(EBImage,resize)
importFrom(Rarr,read_zarr_array)
importFrom(Rarr,read_zarr_attributes)
importFrom(S4Vectors,SimpleList)
importFrom(ZarrArray,ZarrArray)
importFrom(cli,cli_abort)
importFrom(methods,show)
importFrom(stats,setNames)
importFrom(utils,head)
importFrom(utils,tail)
21 changes: 21 additions & 0 deletions R/AllClasses.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' @importFrom S4Vectors SimpleList
setClass(
Class = "ome_zarr",
contains = "SimpleList",
prototype = prototype(elementType = "array")
)

#' @importFrom utils head
#' @export
setMethod("print", "ome_zarr", function(x, level = 1, ...) {
cat(
"Multiscale OME-Zarr ",
x@metadata$type,
" (v",
x@metadata$version,
") object.\n",
sep = ""
)
cat(sprintf("Scale: %d/%d", level, length(x)), "\n")
print(head(x[[level]], rep_len(5, length(dim(x[[level]]))), ...))
})
39 changes: 0 additions & 39 deletions R/extract_level.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/get_dim_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

#' @export
dimnames.ome_zarr <- function(x) {
attr(x, "dim_names")
x@metadata$dim_names
}
11 changes: 9 additions & 2 deletions R/print.R → R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
print.ome_zarr <- function(x, level = 1, ...) {
cat(
"Multiscale OME-Zarr ",
attr(x, "type"),
x@metadata$type,
" (v",
attr(x, "version"),
x@metadata$version,
") object.\n",
sep = ""
)
cat(sprintf("Scale: %d/%d", level, length(x)), "\n")
print(head(x[[level]], rep_len(5, length(dim(x[[level]]))), ...))
invisible(x)
}

#' @importFrom methods show
#' @export
setMethod("show", "ome_zarr", function(object) {
print.ome_zarr(object, level = 1)
})
16 changes: 6 additions & 10 deletions R/ome_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ome_read <- function(path, s3_client = NULL, lazy = TRUE, validate = TRUE) {
img
})

x <- mapply(
mapply(
function(img, scale) {
attr(img, "scale") <- scale
img
Expand All @@ -64,13 +64,9 @@ ome_read <- function(path, s3_client = NULL, lazy = TRUE, validate = TRUE) {
unlist(x$coordinateTransformations[[1]]$scale)
}),
SIMPLIFY = FALSE
)
class(x) <- "ome_zarr"
attr(x, "type") <- type
attr(x, "version") <- ome_version
if (!is.null(dim_names)) {
attr(x, "dim_names") <- dim_names
}

x
) |>
new(
"ome_zarr",
metadata = list(version = ome_version, type = type, dim_names = dim_names)
)
}
1 change: 1 addition & 0 deletions R/romeo-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"_PACKAGE"

## usethis namespace: start
#' @import methods
## usethis namespace: end

## mockable bindings: start
Expand Down
50 changes: 0 additions & 50 deletions R/subset.R

This file was deleted.

36 changes: 0 additions & 36 deletions man/extract_levels.Rd

This file was deleted.

8 changes: 7 additions & 1 deletion man/romeo-package.Rd

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

38 changes: 0 additions & 38 deletions man/sub-.ome_zarr.Rd

This file was deleted.

10 changes: 4 additions & 6 deletions tests/testthat/test-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ test_that("parse ome version", {

# image
x <- ome_read(td)
# TODO: why S3 ?
expect_s3_class(x, "ome_zarr")
expect_equal(attr(x, "type"), "image")
expect_s4_class(x, "ome_zarr")
expect_identical(x@metadata$type, "image")

# labels
x <- ome_read(file.path(td, "labels/blobs"))
# TODO: why S3 ?
expect_s3_class(x, "ome_zarr")
expect_equal(attr(x, "type"), "label")
expect_s4_class(x, "ome_zarr")
expect_identical(x@metadata$type, "label")
}
})
2 changes: 1 addition & 1 deletion tests/testthat/test-write-image.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test_that("writing 0.4 and 0.5 works", {
)

# check type
expect_equal(attr(ome_img, "type"), "image")
expect_identical(ome_img@metadata$type, "image")

# zarr exists
expect_true(zarr_exists(td))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-write-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_that("writing 0.4 and 0.5 labels works", {
)

# check type
expect_equal(attr(ome_label, "type"), "label")
expect_identical(ome_label@metadata$type, "label")

# type is logical in this example
expect_equal(type(ome_label[[1]]), "logical")
Expand Down
Loading