Skip to content

Commit

Permalink
update hdf5 status (#110)
Browse files Browse the repository at this point in the history
* update hdf5 status

* update testing status
  • Loading branch information
rcannood authored Sep 19, 2023
1 parent 2820ec2 commit e2cc818
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
25 changes: 12 additions & 13 deletions R/HDF5AnnData.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ HDF5AnnData <- R6::R6Class("HDF5AnnData", # nolint
#' @field X The X slot
X = function(value) {
if (missing(value)) {
# trackstatus: class=HDF5AnnData, feature=get_X, status=wip
# trackstatus: class=HDF5AnnData, feature=get_X, status=done
read_h5ad_element(private$.h5obj, "/X")
} else {
# trackstatus: class=HDF5AnnData, feature=set_X, status=wip
# trackstatus: class=HDF5AnnData, feature=set_X, status=done
value <- private$.validate_matrix(value, "X")
write_h5ad_element(value, private$.h5obj, "/X")
}
Expand All @@ -28,21 +28,21 @@ HDF5AnnData <- R6::R6Class("HDF5AnnData", # nolint
#' `obs` and `var`.
layers = function(value) {
if (missing(value)) {
# trackstatus: class=HDF5AnnData, feature=get_layers, status=wip
# trackstatus: class=HDF5AnnData, feature=get_layers, status=done
read_h5ad_element(private$.h5obj, "layers")
} else {
# trackstatus: class=HDF5AnnData, feature=set_layers, status=wip
# trackstatus: class=HDF5AnnData, feature=set_layers, status=done
value <- private$.validate_layers(value)
write_h5ad_element(value, private$.h5obj, "/layers")
}
},
#' @field obs The obs slot
obs = function(value) {
if (missing(value)) {
# trackstatus: class=HDF5AnnData, feature=get_obs, status=wip
# trackstatus: class=HDF5AnnData, feature=get_obs, status=done
read_h5ad_element(private$.h5obj, "/obs", include_index = FALSE)
} else {
# trackstatus: class=HDF5AnnData, feature=set_obs, status=wip
# trackstatus: class=HDF5AnnData, feature=set_obs, status=done
value <- private$.validate_obsvar_dataframe(value, "obs")
write_h5ad_element(
value,
Expand All @@ -55,10 +55,10 @@ HDF5AnnData <- R6::R6Class("HDF5AnnData", # nolint
#' @field var The var slot
var = function(value) {
if (missing(value)) {
# trackstatus: class=HDF5AnnData, feature=get_var, status=wip
# trackstatus: class=HDF5AnnData, feature=get_var, status=done
read_h5ad_element(private$.h5obj, "/var", include_index = FALSE)
} else {
# trackstatus: class=HDF5AnnData, feature=set_var, status=wip
# trackstatus: class=HDF5AnnData, feature=set_var, status=done
value <- private$.validate_obsvar_dataframe(value, "var")
write_h5ad_element(
value,
Expand All @@ -70,17 +70,16 @@ HDF5AnnData <- R6::R6Class("HDF5AnnData", # nolint
},
#' @field obs_names Names of observations
obs_names = function(value) {
# TODO: directly write to and read from /obs/_index
if (missing(value)) {
# trackstatus: class=HDF5AnnData, feature=get_obs_names, status=wip
# trackstatus: class=HDF5AnnData, feature=get_obs_names, status=done
# obs names are cached to avoid reading all of obs whenever they are
# accessed
if (is.null(private$.obs_names)) {
private$.obs_names <- read_h5ad_data_frame_index(private$.h5obj, "obs")
}
private$.obs_names
} else {
# trackstatus: class=HDF5AnnData, feature=set_obs_names, status=wip
# trackstatus: class=HDF5AnnData, feature=set_obs_names, status=done
value <- private$.validate_obsvar_names(value, "obs")
write_h5ad_data_frame_index(value, private$.h5obj, "obs", "_index")
private$.obs_names <- value
Expand All @@ -90,15 +89,15 @@ HDF5AnnData <- R6::R6Class("HDF5AnnData", # nolint
var_names = function(value) {
# TODO: directly write to and read from /var/_index
if (missing(value)) {
# trackstatus: class=HDF5AnnData, feature=get_var_names, status=wip
# trackstatus: class=HDF5AnnData, feature=get_var_names, status=done
# var names are cached to avoid reading all of var whenever they are
# accessed
if (is.null(private$.var_names)) {
private$.var_names <- read_h5ad_data_frame_index(private$.h5obj, "var")
}
private$.var_names
} else {
# trackstatus: class=HDF5AnnData, feature=set_var_names, status=wip
# trackstatus: class=HDF5AnnData, feature=set_var_names, status=done
value <- private$.validate_obsvar_names(value, "var")
write_h5ad_data_frame_index(value, private$.h5obj, "var", "_index")
private$.var_names <- value
Expand Down
24 changes: 12 additions & 12 deletions tests/testthat/test-HDF5AnnData.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ test_that("opening H5AD works", {
adata <- HDF5AnnData$new(file)

# GETTERS ----------------------------------------------------------------
# trackstatus: class=HDF5AnnData, feature=test_get_X, status=wip
# trackstatus: class=HDF5AnnData, feature=test_get_X, status=done
test_that("reading X works", {
X <- adata$X
expect_s4_class(X, "dgRMatrix")
expect_equal(dim(X), c(50, 100))
})

# trackstatus: class=HDF5AnnData, feature=test_get_layers, status=wip
# trackstatus: class=HDF5AnnData, feature=test_get_layers, status=done
test_that("reading layers works", {
layers <- adata$layers
expect_true(is.list(layers), "list")
Expand All @@ -27,7 +27,7 @@ test_that("reading layers works", {
)
})

# trackstatus: class=HDF5AnnData, feature=test_get_obs, status=wip
# trackstatus: class=HDF5AnnData, feature=test_get_obs, status=done
test_that("reading obs works", {
obs <- adata$obs
expect_s3_class(obs, "data.frame")
Expand All @@ -40,7 +40,7 @@ test_that("reading obs works", {
)
})

# trackstatus: class=HDF5AnnData, feature=test_get_var, status=wip
# trackstatus: class=HDF5AnnData, feature=test_get_var, status=done
test_that("reading var works", {
var <- adata$var
expect_s3_class(var, "data.frame")
Expand All @@ -54,13 +54,13 @@ test_that("reading var works", {
)
})

# trackstatus: class=HDF5AnnData, feature=test_get_obs_names, status=wip
# trackstatus: class=HDF5AnnData, feature=test_get_obs_names, status=done
test_that("reading obs names works", {
obs_names <- adata$obs_names
expect_vector(obs_names, ptype = character(), size = 50)
})

# trackstatus: class=HDF5AnnData, feature=test_get_var_names, status=wip
# trackstatus: class=HDF5AnnData, feature=test_get_var_names, status=done
test_that("reading var names works", {
var_names <- adata$var_names
expect_vector(var_names, ptype = character(), size = 100)
Expand All @@ -72,7 +72,7 @@ test_that("creating empty H5AD works", {
expect_silent(HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20))
})

# trackstatus: class=HDF5AnnData, feature=test_set_X, status=wip
# trackstatus: class=HDF5AnnData, feature=test_set_X, status=done
test_that("writing X works", {
h5ad_file <- withr::local_tempfile(fileext = ".h5ad")
h5ad <- HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20)
Expand All @@ -81,7 +81,7 @@ test_that("writing X works", {
expect_silent(h5ad$X <- X)
})

# trackstatus: class=HDF5AnnData, feature=test_set_layers, status=wip
# trackstatus: class=HDF5AnnData, feature=test_set_layers, status=done
test_that("writing layers works", {
h5ad_file <- withr::local_tempfile(fileext = ".h5ad")
h5ad <- HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20)
Expand All @@ -90,7 +90,7 @@ test_that("writing layers works", {
expect_silent(h5ad$layers <- list(layer1 = X, layer2 = X))
})

# trackstatus: class=HDF5AnnData, feature=test_set_obs, status=wip
# trackstatus: class=HDF5AnnData, feature=test_set_obs, status=done
test_that("writing obs works", {
h5ad_file <- withr::local_tempfile(fileext = ".h5ad")
h5ad <- HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20)
Expand All @@ -104,7 +104,7 @@ test_that("writing obs works", {
expect_identical(h5ad$obs_names, 1:10)
})

# trackstatus: class=HDF5AnnData, feature=test_set_var, status=wip
# trackstatus: class=HDF5AnnData, feature=test_set_var, status=done
test_that("writing var works", {
h5ad_file <- withr::local_tempfile(fileext = ".h5ad")
h5ad <- HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20)
Expand All @@ -118,7 +118,7 @@ test_that("writing var works", {
expect_identical(h5ad$var_names, 1:20)
})

# trackstatus: class=HDF5AnnData, feature=test_set_obs_names, status=wip
# trackstatus: class=HDF5AnnData, feature=test_set_obs_names, status=done
test_that("writing obs names works", {
h5ad_file <- withr::local_tempfile(fileext = ".h5ad")
h5ad <- HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20)
Expand All @@ -127,7 +127,7 @@ test_that("writing obs names works", {
expect_identical(h5ad$obs_names, LETTERS[1:10])
})

# trackstatus: class=HDF5AnnData, feature=test_set_var_names, status=wip
# trackstatus: class=HDF5AnnData, feature=test_set_var_names, status=done
test_that("writing var names works", {
h5ad_file <- withr::local_tempfile(fileext = ".h5ad")
h5ad <- HDF5AnnData$new(h5ad_file, obs_names = 1:10, var_names = 1:20)
Expand Down

0 comments on commit e2cc818

Please sign in to comment.