Skip to content

Commit 3fb397f

Browse files
authored
read AnnData-zarr tables directly (#130)
read AnnData-zarr tables directly Former-commit-id: b7a6daa Former-commit-id: 4790f871c6158ff37df2eb5427ad74e5635a29a2
2 parents d34092f + 9299a3c commit 3fb397f

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

R/read.R

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,24 @@ readShape <- function(x, ...) {
132132
proc <- basiliskStart(.env)
133133
on.exit(basiliskStop(proc))
134134
basiliskRun(proc, x=x, \(x) {
135-
# read in 'SpatialData' from .zarr store
136-
sd <- import("spatialdata")
137-
zs <- sd$read_zarr(x)
138-
# return (named) list of SCEs
139-
names(ts) <- ts <- names(zs$tables$data)
140-
lapply(ts, \(z) {
141-
se <- AnnData2SCE(zs$tables[z])
142-
nm <- "spatialdata_attrs"
143-
md <- metadata(se)[[nm]]
144-
int_metadata(se)[[nm]] <- md
145-
metadata(se)[[nm]] <- NULL
146-
se
147-
})
135+
# read in 'AnnData' tables from .zarr store
136+
sd <- import("anndata")
137+
za <- import("zarr")
138+
# return (named) list of SCEs
139+
names(ts) <- ts <- list.dirs(file.path(x,"tables/"),
140+
recursive = FALSE,
141+
full.names = FALSE)
142+
lapply(ts, \(z) {
143+
zs <- sd$read_zarr(file.path(x, "tables", z))
144+
se <- AnnData2SCE(zs)
145+
nm <- "spatialdata_attrs"
146+
md <- metadata(se)[[nm]]
147+
int_metadata(se)[[nm]] <- md
148+
metadata(se)[[nm]] <- NULL
149+
se
150+
})
148151
})
149152
}
150-
151153
.readTable_anndataR <- function(x) {
152154
if (!requireNamespace('anndataR', quietly=TRUE)) {
153155
stop("To use this function, install the 'anndataR' package via\n",

0 commit comments

Comments
 (0)