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
32 changes: 12 additions & 20 deletions R/ZarrArraySeed-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ setMethod("chunkdim", "ZarrArraySeed", function(x) x@chunkdim)
setMethod("extract_array", "ZarrArraySeed",
function(x, index)
{
ans <- Rarr::read_zarr_array(x@zarr_path, index, x@s3_client)
## Temporary fix.
## See https://github.com/Huber-group-EMBL/Rarr/issues/137
if (typeof(ans) != x@type)
storage.mode(ans) <- x@type
ans
Rarr::read_zarr_array(x@zarr_path, index, x@s3_client)
}
)

Expand Down Expand Up @@ -95,20 +90,17 @@ setMethod("show", "ZarrArraySeed",
.extract_chunkdim_from_metadata <- function(metadata)
{
stopifnot(is.list(metadata), !is.null(names(metadata)))
chunkdim <- metadata$chunks # only in Zarr v2
if (is.null(chunkdim)) {
chunk_grid <- metadata$chunk_grid # only in Zarr v3
if (is.null(chunk_grid))
stop(wmsg("unable to determine the chunk dimensions ",
"for this Zarr dataset"))
if (!identical(chunk_grid$name, "regular"))
stop(wmsg("only Zarr datasets with a regular chunk ",
"grid are supported at the moment"))
chunkdim <- chunk_grid$configuration$chunk_shape
if (is.null(chunkdim))
stop(wmsg("unable to determine the chunk dimensions ",
"for this Zarr dataset"))
}
chunk_grid <- metadata$chunk_grid # only in Zarr v3
if (is.null(chunk_grid))
stop(wmsg("unable to determine the chunk dimensions ",
"for this Zarr dataset"))
if (!identical(chunk_grid$name, "regular"))
stop(wmsg("only Zarr datasets with a regular chunk ",
"grid are supported at the moment"))
chunkdim <- chunk_grid$configuration$chunk_shape
if (is.null(chunkdim))
stop(wmsg("unable to determine the chunk dimensions ",
"for this Zarr dataset"))
if (is.list(chunkdim))
chunkdim <- unlist(chunkdim, use.names=FALSE)
if (!is.numeric(chunkdim))
Expand Down
45 changes: 4 additions & 41 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 All @@ -76,7 +43,7 @@ zarrtype2Rtype <- function(base_type)
float="double",
#complex="complex",
string=, unicode="character",
stop(wmsg("unreocgnized Zarr base type: ", base_type)))
stop(wmsg("unrecognized Zarr base type: ", base_type)))
}


Expand Down Expand Up @@ -105,11 +72,7 @@ compute_max_string_size <- function(x, keepNA=FALSE)

.normarg_fill_value <- function(fill_value, type, nchar=NULL)
{
if (is.null(fill_value)) {
dt <- Rarr:::.check_datatype(type, nchar=nchar)
} else {
dt <- Rarr:::.check_datatype(type, fill_value, nchar=nchar)
}
dt <- Rarr:::.check_datatype(type, fill_value, nchar=nchar)
stopifnot(identical(names(dt), c("data_type", "fill_value")))
dt$fill_value
}
Expand Down