@@ -50,6 +50,26 @@ test_that("reading varm works", {
5050 )
5151})
5252
53+ # trackstatus: class=HDF5AnnData, feature=test_get_obsp, status=done
54+ test_that(" reading obsp works" , {
55+ obsp <- adata $ obsp
56+ expect_true(is.list(obsp ), " list" )
57+ expect_equal(
58+ names(obsp ),
59+ c(" connectivities" , " distances" )
60+ )
61+ })
62+
63+ # trackstatus: class=HDF5AnnData, feature=test_get_varp, status=done
64+ test_that(" reading varp works" , {
65+ varp <- adata $ varp
66+ expect_true(is.list(varp ), " list" )
67+ expect_equal(
68+ names(varp ),
69+ c(" test_varp" )
70+ )
71+ })
72+
5373# trackstatus: class=HDF5AnnData, feature=test_get_obs, status=done
5474test_that(" reading obs works" , {
5575 obs <- adata $ obs
@@ -187,3 +207,71 @@ test_that("writing var names works", {
187207 h5ad $ var_names <- LETTERS [1 : 20 ]
188208 expect_identical(h5ad $ var_names , LETTERS [1 : 20 ])
189209})
210+
211+ # trackstatus: class=HDF5AnnData, feature=test_set_obsm, status=done
212+ test_that(" writing obsm works" , {
213+ h5ad_file <- withr :: local_tempfile(fileext = " .h5ad" )
214+ obs <- data.frame (row.names = 1 : 10 )
215+ var <- data.frame (row.names = 1 : 20 )
216+ h5ad <- HDF5AnnData $ new(h5ad_file , obs = obs , var = var )
217+
218+ obsm_x <- matrix (rnorm(10 * 5 ), nrow = 10 , ncol = 5 )
219+ h5ad $ obsm <- list (X = obsm_x )
220+ expect_identical(h5ad $ obsm $ X , obsm_x )
221+ })
222+
223+ # trackstatus: class=HDF5AnnData, feature=test_set_varm, status=done
224+ test_that(" writing varm works" , {
225+ h5ad_file <- withr :: local_tempfile(fileext = " .h5ad" )
226+ obs <- data.frame (row.names = 1 : 10 )
227+ var <- data.frame (row.names = 1 : 20 )
228+ h5ad <- HDF5AnnData $ new(h5ad_file , obs = obs , var = var )
229+ varm_x <- matrix (rnorm(20 * 5 ), nrow = 20 , ncol = 5 )
230+ h5ad $ varm <- list (PCs = varm_x )
231+ expect_identical(h5ad $ varm $ PCs , varm_x )
232+ })
233+
234+ # trackstatus: class=HDF5AnnData, feature=test_set_obsp, status=done
235+ test_that(" writing obsp works" , {
236+ h5ad_file <- withr :: local_tempfile(fileext = " .h5ad" )
237+ obs <- data.frame (row.names = 1 : 10 )
238+ var <- data.frame (row.names = 1 : 20 )
239+ h5ad <- HDF5AnnData $ new(h5ad_file , obs = obs , var = var )
240+
241+ obsp_x <- matrix (rnorm(10 * 10 ), nrow = 10 , ncol = 10 )
242+ h5ad $ obsp <- list (connectivities = obsp_x )
243+ expect_identical(h5ad $ obsp $ connectivities , obsp_x )
244+ })
245+
246+ # trackstatus: class=HDF5AnnData, feature=test_set_varp, status=done
247+ test_that(" writing varp works" , {
248+ h5ad_file <- withr :: local_tempfile(fileext = " .h5ad" )
249+ obs <- data.frame (row.names = 1 : 10 )
250+ var <- data.frame (row.names = 1 : 20 )
251+ h5ad <- HDF5AnnData $ new(h5ad_file , obs = obs , var = var )
252+
253+ varp_x <- matrix (rnorm(20 * 20 ), nrow = 20 , ncol = 20 )
254+ h5ad $ varp <- list (connectivities = varp_x )
255+ expect_identical(h5ad $ varp $ connectivities , varp_x )
256+ })
257+
258+ # trackstatus: class=HDF5AnnData, feature=test_set_uns, status=done
259+ test_that(" writing uns works" , {
260+ h5ad_file <- withr :: local_tempfile(fileext = " .h5ad" )
261+ obs <- data.frame (row.names = 1 : 10 )
262+ var <- data.frame (row.names = 1 : 20 )
263+ h5ad <- HDF5AnnData $ new(h5ad_file , obs = obs , var = var )
264+
265+ h5ad $ uns <- list (
266+ foo = " bar" ,
267+ baz = c(1 , 2 , 3 ),
268+ nested = list (
269+ nested_foo = " nested_bar" ,
270+ nested_baz = c(4L , 5L , 6L )
271+ )
272+ )
273+ expect_identical(h5ad $ uns $ foo , " bar" )
274+ expect_equal(h5ad $ uns $ baz , c(1 , 2 , 3 ), ignore_attr = TRUE )
275+ expect_identical(h5ad $ uns $ nested $ nested_foo , " nested_bar" )
276+ expect_equal(h5ad $ uns $ nested $ nested_baz , c(4L , 5L , 6L ), ignore_attr = TRUE )
277+ })
0 commit comments