romanhaa / cerebroApp

R package containing the Cerebro application.
https://romanhaa.github.io/cerebroApp/
Other
40 stars 16 forks source link

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

Closed turkeyri closed 4 years ago

turkeyri commented 4 years ago

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]

aoumess commented 4 years ago

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.

turkeyri commented 4 years ago

maybe you could insert some dummy genes in the object in for the markers for the empties and then ignore results for those groups??

On Tue, May 19, 2020 at 9:17 AM Bastien Job notifications@github.com wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/romanhaa/Cerebro/issues/23#issuecomment-630890773, or unsubscribe https://github.com/notifications/unsubscribe-auth/APAMFT7LJXRS7YUMXGGSTCTRSKPH7ANCNFSM4LZH3KXA .

romanhaa commented 4 years ago

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 ;)

romanhaa commented 4 years ago

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