cerebroApp::getEnrichedPathways does not exit gracefully if marker gene sets are not empty but no enriched pathways found
Closed this issue · 2 comments
I was getting the error:
[14:39:22] Get enriched pathway for samples...
Error in UseMethod("select_") :
no applicable method for 'select_' applied to an object of class "NULL"
from the line:
results_by_sample <- do.call(rbind, results_by_sample) %>%
dplyr::select("sample", "db", dplyr::everything()) %>%
dplyr::mutate(sample = factor(.data$sample, levels = intersect(sample_names, .data$sample)), db = factor(.data$db, databases))
when results_by_sample had no rows (i.e. it was an empty list). This occurred because I had 1 marker gene for 1 sample, which obviously means no enriched pathways, and consequently returned all NULL results_by_sample lists from the previous two for loops.
I made a work-around by adding a check for an empty results_by_sample. So the code looks something like this after the two "for (i in names(results_by_sample))" loops - included here for context:
for (i in names(results_by_sample)) { ## SML: this appears only to clear out names for null lists
if (is.null(results_by_sample[[i]]))
results_by_sample[[i]] <- NULL
}
for (i in names(results_by_sample)) {
results_by_sample[[i]] <- results_by_sample[[i]] %>%
dplyr::mutate(sample = i)
}
## This if added by SML to deal with cases when no results come back
if (length(results_by_sample)==0) { ## Added by SML
results_by_sample <- "no_markers_found" ## Added by SML.. not exactly no markers but no pathways for those markers
message(paste0("[", format(Sys.time(), "%H:%M:%S"), "] 0 pathways passed the thresholds across all samples and databases.")) ## Added by SML
} else { ## Added by SML
results_by_sample <- do.call(rbind, results_by_sample) %>%
dplyr::select("sample", "db", dplyr::everything()) %>%
dplyr::mutate(sample = factor(.data$sample, levels = intersect(sample_names, .data$sample)), db = factor(.data$db, databases))
message(paste0("[", format(Sys.time(), "%H:%M:%S"),
"] ", nrow(results_by_sample), " pathways passed the thresholds across all samples and databases."))
} ## Added by SML
[the same would happen in the analogous results_by_cluster later in the code, so I made an analogous check around the corresponding results_by_cluster <- do.call.... line]
As you may have noticed, I transferred the original issue and fixed it 👍