Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust relocation of on-disk layers #169

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SeuratObject
Type: Package
Title: Data Structures for Single Cell Data
Version: 5.0.0.9002
Version: 5.0.0.9003
Authors@R: c(
person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
person(given = 'Paul', family = 'Hoffman', email = 'seurat@nygenome.org', role = c('aut', 'cre'), comment = c(ORCID = '0000-0002-7693-8957')),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Changes:
- Update internal calls to `GetAssayData()` to use `layer` instead of `slot` (#160)
- Change layer-saving in `SaveSeuratRds()` to move all layers instead of just those in `tempdir()` (#169)

# SeuratObject 5.0.0
## Added
Expand Down
66 changes: 37 additions & 29 deletions R/seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ RenameAssays <- function(
#' @param object A \code{\link{Seurat}} object
#' @param file Path to save \code{object} to; defaults to
#' \code{file.path(getwd(), paste0(Project(object), ".Rds"))}
#' @param destdir Destination directory for on-disk layers saved in
#' \dQuote{\code{\Sexpr[stage=render]{tempdir()}}}
#' @param move Move on-disk layers into \code(dirname(file))
#' @param destdir \Sexpr[stage=build,results=rd]{lifecycle::badge("deprecated")}
#' @param relative Save relative paths instead of absolute ones
#' @inheritDotParams base::saveRDS
#'
Expand Down Expand Up @@ -685,12 +685,28 @@ RenameAssays <- function(
SaveSeuratRds <- function(
object,
file = NULL,
destdir = NULL,
move = TRUE,
destdir = deprecated(),
relative = FALSE,
...
) {
file <- file %||% file.path(getwd(), paste0(Project(object = object), '.Rds'))
file <- normalizePath(path = file, winslash = '/', mustWork = FALSE)
if (is_present(arg = destdir)) {
.Deprecate(
when = '5.0.1',
what = 'SaveSeuratRds(destdir = )',
with = 'SaveSeuratRds(move = )',
details = paste(
"Specifying a directory to move on-disk layers stored in",
sQuote(x = normalizePath(path = tempdir(), winslash = '/', mustWork = FALSE)),
"is deprecated; now, specify `move = TRUE` either move all on-disk layers to",
sQuote(x = dirname(path = file)),
"or `move = FALSE` leave them as-is"
)
)
move <- is_bare_character(x = destdir, n = 1L) || is.null(x = destdir)
}
# Cache v5 assays
assays <- .FilterObjects(object = object, classes.keep = 'StdAssay')
p <- progressor(along = assays, auto_finish = TRUE)
Expand All @@ -706,13 +722,9 @@ SaveSeuratRds <- function(
)
cache <- vector(mode = 'list', length = length(x = assays))
names(x = cache) <- assays
tdir <- normalizePath(path = tempdir(), winslash = '/') # because macOS is weird
destdir <- destdir %||% dirname(path = file)
if (!is_na(x = destdir) || isTRUE(x = relative)) {
check_installed(
pkg = 'fs',
reason = 'for moving on-disk matrices'
)
destdir <- dirname(path = file)
if (isTRUE(x = move)) {
check_installed(pkg = 'fs', reason = 'for moving on-disk matrices')
}
for (assay in assays) {
p(
Expand Down Expand Up @@ -746,27 +758,23 @@ SaveSeuratRds <- function(
p(message = "No on-disk layers found", class = 'sticky', amount = 0)
next
}
if (!is_na(x = destdir)) {
if (isTRUE(x = move)) {
for (i in seq_len(length.out = nrow(x = df))) {
pth <- df$path[i]
mv <- substr(x = pth, start = 1L, stop = nchar(x = tdir)) == tdir ||
isTRUE(x = relative)
if (isTRUE(x = mv)) {
p(
message = paste(
"Moving layer",
sQuote(x = df$layer[i]),
"to",
sQuote(x = destdir)
),
class = 'sticky',
amount = 0
)
df[i, 'path'] <- as.character(x = .FileMove(
path = pth,
new_path = destdir
))
}
p(
message = paste(
"Moving layer",
sQuote(x = df$layer[i]),
"to",
sQuote(x = destdir)
),
class = 'sticky',
amount = 0
)
df[i, 'path'] <- as.character(x = .FileMove(
path = pth,
new_path = destdir
))
}
}
if (isTRUE(x = relative)) {
Expand Down
17 changes: 12 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,11 @@ StitchMatrix.matrix <- function(x, y, rowmap, colmap, ...) {
new_path <- fs::path_expand(path = new_path)
new_path <- fs::dir_create(path = new_path)
dest <- tryCatch(
expr = fs::dir_copy(path = path, new_path = new_path, overwrite = overwrite),
expr = fs::dir_copy(
path = path,
new_path = new_path,
overwrite = overwrite
),
EEXIST = eexist,
error = hndlr
)
Expand All @@ -2292,10 +2296,13 @@ StitchMatrix.matrix <- function(x, y, rowmap, colmap, ...) {
)
} else {
abort(
message = paste0(
"Can't find path: ",
sQuote(x = path),
"; if path is relative, change working directory."
message = paste(
strwrap(x = paste0(
"Can't find path: ",
sQuote(x = path),
"; if path is relative, change working directory"
)),
sep = '\n'
),
call = caller_env(n = 1L + n)
)
Expand Down
14 changes: 11 additions & 3 deletions man/SaveSeuratRds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.