@@ -74,6 +74,8 @@ saveData <- function(seuratObj, datasetId) {
7474 print(paste0('Saving dataset: ', datasetId))
7575 print(seuratObj)
7676
77+ seuratObj <- .TestSplitLayers(seuratObj)
78+
7779 datasetIdForFile <- makeLegalFileName(datasetId)
7880 fn <- paste0(outputPrefix, '.', datasetIdForFile, '.seurat.rds')
7981 message(paste0('Filename: ', fn))
@@ -128,6 +130,35 @@ addErrorMessage <- function(f) {
128130 errorMessages <<- c(errorMessages, f)
129131}
130132
133+ .MergeSplitLayers <- function(seuratObj, assayName) {
134+ if (inherits(seuratObj[[assayName]], 'Assay5')) {
135+ print(paste0('Joining layers: ', assayName))
136+ seuratObj[[assayName]] <- SeuratObject::JoinLayers(seuratObj[[assayName]])
137+ print(paste0('After join: ', paste0(SeuratObject::Layers(seuratObj[[assayName]]), collapse = ',')))
138+ } else {
139+ print(paste0('Not an assay5 object, not joining layers: ', assayName))
140+ }
141+
142+ print(seuratObj)
143+ return(seuratObj)
144+ }
145+
146+ .TestSplitLayers <- function(seuratObj) {
147+ for (assayName in Seurat::Assays(seuratObj)) {
148+ if (length(suppressWarnings(SeuratObject::Layers(seuratObj, assay = assayName, search = 'counts'))) > 1) {
149+ seuratObj <- .MergeSplitLayers(seuratObj, assayName)
150+ next
151+ }
152+
153+ if (length(suppressWarnings(SeuratObject::Layers(seuratObj, assay = assayName, search = 'data'))) > 1) {
154+ seuratObj <- .MergeSplitLayers(seuratObj, assayName)
155+ next
156+ }
157+ }
158+
159+ return(seuratObj)
160+ }
161+
131162readSeuratRDS <- function(filePath) {
132163 seuratObj <- readRDS(filePath)
133164
@@ -137,6 +168,8 @@ readSeuratRDS <- function(filePath) {
137168 seuratObj <- Seurat::UpdateSeuratObject(seuratObj)
138169 }
139170
171+ seuratObj <- .TestSplitLayers(seuratObj)
172+
140173 return(seuratObj)
141174}
142175
0 commit comments