Skip to content

Commit 2452039

Browse files
committed
Fix crash when no warnings from bam
1 parent 4178499 commit 2452039

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

R/bambu_utilityFunctions.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,27 @@ handleWarnings <- function(readClassList, verbose){
184184
sampleNames = c()
185185
for(i in seq_along(readClassList)){
186186
readClassSe = readClassList[[i]]
187-
if (is.character(readClassSe))
188-
readClassSe <- readRDS(file = readClassSe)
189-
warnings[[i]] = metadata(readClassSe)$warnings
187+
if (is.character(readClassSe)){
188+
readClassSe <- readRDS(file = readClassSe)}
189+
warnings[[i]] = NA
190+
if(!is.null(metadata(readClassSe)$warnings)){
191+
warnings[[i]] = metadata(readClassSe)$warnings}
190192
sampleNames = c(sampleNames, colnames(readClassList[[i]]))
191193
}
192194
names(warnings) = sampleNames
193195

194-
if(verbose & any(lengths(warnings)>0)){
196+
if(verbose & any(!is.na(warnings))){
195197
message("--- per sample warnings during read class construction ---")
196-
for(i in seq_along(warnings)){
197-
if(lengths(warnings)[i]>0){
198-
message("Warnings for: ", sampleNames[i])
199-
sapply(warnings[[i]], message)
200-
}
198+
warnings.tmp = warnings[!is.na(warnings)]
199+
for(i in seq_along(warnings.tmp)){
200+
message("Warnings for: ", names(warnings.tmp)[i])
201+
sapply(warnings.tmp[[i]], message)
201202
}
202203
} else {
203-
message("Detected ", sum(lengths(warnings)), " warnings across the samples during ",
204-
"read class construction. Access warnings with metadata(bambuOutput)$warnings")
204+
warningCount = sum(lengths(warnings[!is.na(warnings)]))
205+
if(warningCount > 0){
206+
message("Detected ", warningCount, " warnings across the samples during ",
207+
"read class construction. Access warnings with metadata(bambuOutput)$warnings")}
205208
}
206209
return(warnings)
207210
}

0 commit comments

Comments
 (0)