Skip to content
Open
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 2 additions & 35 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down