Last active
April 24, 2024 00:10
-
-
Save mojaveazure/63f68262b692fccfdafd801f256ab207 to your computer and use it in GitHub Desktop.
Ingest a `Seurat`, `SingleCellExperiment`, or `SummarizedExperiment` object to a SOMA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
suppressPackageStartupMessages(library(tiledbsoma)) | |
suppressPackageStartupMessages(library(argparser)) | |
parser <- argparser::arg_parser("", hide.opts = TRUE) | |
parser <- argparser::add_argument( | |
parser = parser, | |
arg = '--input', | |
help = "Input Seurat, SingleCellExperiment, or SummarizedExperiment object as Rds", | |
type = "character", | |
nargs = 1L | |
) | |
parser <- argparser::add_argument( | |
parser = parser, | |
arg = '--output', | |
help = "URI for output SOMA", | |
type = "character", | |
nargs = 1L | |
) | |
parser <- argparser::add_argument( | |
parser = parser, | |
arg = '--verbosity', | |
help = "spdl verbosity level", | |
default = "info", | |
type = "character", | |
nargs = 1L | |
) | |
parser <- argparser::add_argument( | |
parser = parser, | |
arg = '--resume', | |
help = "Ingest in resume-mode", | |
flag = TRUE | |
) | |
argv <- commandArgs(trailingOnly = TRUE) | |
if (!length(argv)) { | |
print(parser) | |
stop("No arguments provided", call. = FALSE) | |
} | |
args <- argparser::parse_args(parser = parser, argv = argv) | |
if (any(is.na(c(args$input, args$output)))) { | |
stop("'--input' and '--output' are required", call. = FALSE) | |
} | |
spdl::set_level(args$verbosity) | |
if (!file.exists(args$input) || tolower(tools::file_ext(args$input)) != 'rds') { | |
stop("'--input' must be an Rds file") | |
} | |
message("Reading input object from Rds") | |
obj <- readRDS(args$input) | |
if (!inherits(obj, c('Seurat', 'SingleCellExperiment', 'SummarizedExperiment'))) { | |
stop("'--input' must be a `Seurat`, `SingleCellExperiment`, or `SummarizedExperiment` object") | |
} | |
uri <- tiledbsoma::write_soma( | |
x = obj, | |
uri = args$output, | |
ingest_mode = ifelse(args$resume, yes = "resume", no = "write") | |
) | |
cat(uri, "\n", file = stdout()) | |
message("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment