Skip to content

Commit 83b8238

Browse files
committed
Add loom2sce and sce2loom
1 parent 7f49f6a commit 83b8238

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Depends:
1111
reticulate
1212
Imports:
1313
Seurat (>= 3.0.1),
14-
SingleCellExperiment (>= 1.4.0)
14+
SingleCellExperiment (>= 1.4.0),
15+
LoomExperiment (>= 1.1.5)
1516
License: GPL-3
1617
LazyDate: true

R/functions.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,11 @@ loom2anndata <- function(
122122

123123
adata
124124
}
125+
126+
sce2loom <- function(obj, outFile, main_layer = NULL, ...) {
127+
writeExchangeableLoom(obj, outFile, main_layer = main_layer, ...)
128+
}
129+
130+
loom2sce <- function(inFile, outFile = NULL, main_layer = NULL, ...) {
131+
readExchangeableLoom(inFile, backed = FALSE, ...)
132+
}

R/methods.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
convertFormat <- function(
2-
obj, from = c('seurat', 'sce', 'loom'), to = c('anndata'), outFile = NULL,
2+
obj, from = c('seurat', 'sce', 'loom'), to = c('anndata', 'loom', 'sce'), outFile = NULL,
33
main_layer = NULL, ...
44
) {
55
from <- match.arg(from)
66
to <- match.arg(to)
77

8-
func <- eval(parse(text=paste(from, to, sep='2')))
8+
tryCatch({
9+
func <- eval(parse(text = paste(from, to, sep='2')))
10+
}, error = function(e) {
11+
stop(paste0('Unsupported conversion from "', from, '" to "', to, '"'), call. = FALSE)
12+
}, finally = {})
913

1014
return(func(obj, outFile = outFile, main_layer = main_layer, ...))
1115
}

0 commit comments

Comments
 (0)