Skip to content

Commit

Permalink
remove references to rhdf5
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Jul 10, 2024
1 parent 0b264fe commit 31e7886
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions R/write_h5ad_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,46 +252,6 @@ write_h5ad_nullable_boolean <- function(value, file, name, compression, version
write_h5ad_encoding(file, name, "nullable-boolean", version)
}

#' Write H5AD boolean array
#'
#' Write a boolean array to an H5AD file as a custom ENUM dataset
#'
#' @noRd
#'
#' @param value Value to write
#' @param file Path to a H5AD file or an open H5AD handle
#' @param name Name of the element within the H5AD file
write_h5ad_boolean_array <- function(value, file, name) {
# Based on https://stackoverflow.com/a/74653515/4384120

h5file <- rhdf5::H5Fopen(file)
on.exit(rhdf5::H5Fclose(h5file))

value <- as.integer(value)
if (!is.null(dim(value))) {
dims <- dim(value)
} else {
dims <- length(value)
}

# Create the dataspace for the data to write
h5space <- rhdf5::H5Screate_simple(dims = dims, NULL, native = TRUE)
on.exit(rhdf5::H5Sclose(h5space), add = TRUE)

# Create the Boolean ENUM datatype (TRUE = 1 FALSE = 0)
tid <- rhdf5::H5Tenum_create(dtype_id = "H5T_NATIVE_UCHAR")
rhdf5::H5Tenum_insert(tid, name = "TRUE", value = 1L)
rhdf5::H5Tenum_insert(tid, name = "FALSE", value = 0L)

# Create the dataset with this new datatype
h5dataset <- rhdf5::H5Dcreate(h5file, name, tid, h5space)
on.exit(rhdf5::H5Dclose(h5dataset), add = TRUE)

# Write the data. We have to use as.raw() because our base type is 8-bit and
# R integers are 32-bit
rhdf5::H5Dwrite(h5dataset, as.raw(value), h5type = tid)
}


#' Write H5AD nullable integer
#'
Expand Down Expand Up @@ -520,8 +480,8 @@ write_h5ad_data_frame <- function(value, file, name, compression, index = NULL,
#' one of `"none"`, `"gzip"` or `"lzf"`. Defaults to `"none"`.
#' @param version The H5AD version to write
write_empty_h5ad <- function(file, obs, var, compression, version = "0.1.0") {
h5file <- rhdf5::H5Fcreate(file)
rhdf5::H5Fclose(h5file)
# h5file <- rhdf5::H5Fcreate(file)

Check warning on line 483 in R/write_h5ad_helpers.R

View workflow job for this annotation

GitHub Actions / lint

file=R/write_h5ad_helpers.R,line=483,col=5,[commented_code_linter] Commented code should be removed.
# rhdf5::H5Fclose(h5file)

Check warning on line 484 in R/write_h5ad_helpers.R

View workflow job for this annotation

GitHub Actions / lint

file=R/write_h5ad_helpers.R,line=484,col=5,[commented_code_linter] Commented code should be removed.

write_h5ad_encoding(file, "/", "anndata", "0.1.0")

Expand Down

0 comments on commit 31e7886

Please sign in to comment.