Skip to content

Commit

Permalink
Bugfix to MergeSeurat
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Jan 31, 2025
1 parent 3843ffe commit cc57c13
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions singlecell/resources/chunks/MergeSeurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if (!doDiet && length(seuratObjects) > 20 && !disableAutoDietSeurat) {
filesToDelete <- c()

mergeBatchInMemory <- function(datasetIdToFilePath, saveFile) {
if (all(is.null(names(datasetIdToFilePath)))) {
stop('No names provided on datasetIdToFilePath')
}

toMerge <- list()
for (datasetId in names(datasetIdToFilePath)) {
print(paste0('Loading: ', datasetId))
Expand Down Expand Up @@ -43,7 +47,7 @@ mergeBatchInMemory <- function(datasetIdToFilePath, saveFile) {
saveRDS(seuratObj, file = saveFile)
filesToDelete <<- c(filesToDelete, saveFile)

return(fn)
return(saveFile)
}

mergeBatch <- function(seuratObjects, outerBatchIdx, maxBatchSize = 20, maxInputFileSizeMb = maxAllowableInputFileSizeMb) {
Expand Down Expand Up @@ -89,8 +93,9 @@ mergeBatch <- function(seuratObjects, outerBatchIdx, maxBatchSize = 20, maxInput
activeBatch <- batchList[[i]]
logger::log_info(paste0('Merging inner batch ', i, ' of ', length(batchList), ' with ', length(activeBatch), ' files'))

saveFile <- paste0('merge.', outerBatchIdx, '.', i, '.rds')
mergedObjectFiles[[i]] <- mergeBatchInMemory(activeBatch, saveFile = saveFile)
batchName <- paste0('merge.', outerBatchIdx, '.', i)
saveFile <- paste0(batchName, '.rds')
mergedObjectFiles[[batchName]] <- mergeBatchInMemory(activeBatch, saveFile = saveFile)

logger::log_info(paste0('mem used: ', R.utils::hsize(as.numeric(pryr::mem_used()))))
gc()
Expand Down

0 comments on commit cc57c13

Please sign in to comment.