From d349d51cbf3b229bfe574c418e0c334daf03dc06 Mon Sep 17 00:00:00 2001 From: Hugo Gruson Date: Fri, 15 May 2026 16:03:33 +0200 Subject: [PATCH] Use new simpler Rarr:::.read_array_metadata() interface --- DESCRIPTION | 2 +- R/utils.R | 37 ++----------------------------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ec16449..dc43628 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Authors@R: c( comment=c(ORCID="0000-0003-2725-0694"))) Depends: R (>= 3.4), methods, SparseArray, DelayedArray Imports: stats, tools, BiocGenerics, S4Vectors, IRanges, S4Arrays, - Rarr (>= 1.11.33) + Rarr (>= 2.1.9) Suggests: paws.storage, HDF5Array, testthat, knitr, rmarkdown, BiocStyle VignetteBuilder: knitr Collate: diff --git a/R/utils.R b/R/utils.R index ca02a6a..455d89e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -17,50 +17,17 @@ trim_trailing_slashes <- function(x) ### get_zarr_metadata() ### -.ZARR_V2_METADATA_FILE <- ".zarray" -.ZARR_V3_METADATA_FILE <- "zarr.json" - -.get_zarr_metadata_file <- function(zarr_path, s3_client=NULL) -{ - stopifnot(S4Vectors:::has_suffix(zarr_path, "/")) - metadata_files <- c(.ZARR_V2_METADATA_FILE, .ZARR_V3_METADATA_FILE) - ok <- Rarr:::.file_or_blob_exists(zarr_path, s3_client, metadata_files) - if (!any(ok)) - stop(wmsg("No Zarr metadata file ('", .ZARR_V2_METADATA_FILE, "' ", - "or '", .ZARR_V3_METADATA_FILE, "') found in: ", zarr_path), - "\n ", - wmsg("Are you sure this is the path to a Zarr dataset?")) - if (all(ok)) - stop(wmsg("Invalid Zarr dataset at: ", zarr_path), - "\n ", - wmsg("Directory contains Zarr metadata files ", - "'", .ZARR_V2_METADATA_FILE, "' and ", - "'", .ZARR_V3_METADATA_FILE, "'. Should contain one ", - "or the other, but not both.")) - names(ok)[ok] -} - ### Only used in the unit tests at the moment. get_zarr_format <- function(zarr_path, s3_client=NULL) { - stopifnot(isSingleString(zarr_path)) - metadata_file <- .get_zarr_metadata_file(zarr_path, s3_client=s3_client) - if (metadata_file == .ZARR_V3_METADATA_FILE) 3L else 2L + get_zarr_metadata(zarr_path, s3_client=s3_client)$zarr_format } ### Returns the metadata in a named list. -### IMPORTANT NOTE: The exact components of the named list and their names -### depend on the Zarr version (a.k.a. Zarr format) of the Zarr dataset, -### which can be 2 or 3. However, the Rarr package has -### Rarr:::.convert_metadata_version() for converting the metadata -### to a given version. This is something that we could use in -### get_zarr_metadata() to always return the metadata in the same -### form e.g. in the form that corresponds to Zarr v3. get_zarr_metadata <- function(zarr_path, s3_client=NULL) { stopifnot(isSingleString(zarr_path)) - metadata_file <- .get_zarr_metadata_file(zarr_path, s3_client=s3_client) - Rarr:::.read_array_metadata(zarr_path, metadata_file, s3_client=s3_client) + Rarr:::.read_array_metadata(zarr_path, s3_client=s3_client) }