romanhaa/cerebroApp

cerebroApp::getEnrichedPathways does not exit gracefully if marker gene sets are not empty but no enriched pathways found

Closed this issue · 4 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]

Thanks for this post, I just got the same error here !
Without editing the source code, is there a way to bypass the problematic part (no marker for sample) and get results for the clusters (or vice-verse) ?
If not, I have to make a check to just bypass the call to getEnrichedPathways in my scripts, which would be sad.

Hi there! Thank you for bringing this up. You're right, the scenario is not handled very well. It's on the list of things that will be fixed as soon as possible.

Btw, next time please consider opening an issue in the cerebroApp repo: https://github.com/romanhaa/cerebroApp That way I can link the fix to issue.

Thanks ;)

I fixed it in the develop branch so it will go in the next release. Thanks again for the contribution!