lgeistlinger / EnrichmentBrowser

Seamless navigation through combined results of set-based and network-based enrichment analysis
20 stars 11 forks source link

error in ebrowser when a dplyr library is loaded #12

Closed olkap closed 6 years ago

olkap commented 6 years ago

Hi, The function ebrowser does not work correctly, when a dplyr library is loaded. The code below works correctly when a dplyr library is not loaded, and it gives an error when the dplyr is loaded. I know that I can reload my R session and load only the minimal number of packages before running the ebrowser, but it is not an elegant solution.

#_________________
# Load packages
library("EnrichmentBrowser")
library("ALL")
library("hgu95av2.db")
library("dplyr")

#________________
# Load the ALL dataset

data(ALL)

#select B-cell ALL patients with and without the BCR/ABL fusion
ind.bs <- grep("^B", ALL$BT)  
ind.mut <- which(ALL$mol.biol %in% c("BCR/ABL", "NEG"))
sset <- intersect(ind.bs, ind.mut)
all.eset <- ALL[, sset]

#We compute gene expression values as the average of the corresponding probe values.
allSE <- probe2gene(all.eset) 

#______________________
# Create GROUP variable (the GROUP variable indicates whether the BCR-ABL gene fusion is present (1) or not (0).)
allSE$GROUP <- ifelse(allSE$mol.biol == "BCR/ABL", 1, 0)

#_____________________
# Gene sets
gs_kegg <- getGenesets(org="hsa", db="kegg")

# combining results from multiple analysis methods
ebrowser( meth=c("ora"),
          exprs = allSE, 
          org="hsa", 
          data.type = "ma",
          norm.method = "none",
          gs=gs_kegg, 
          comb=TRUE, 
          nr.show=-1)

The messages that appear after running ebrowser:

DE analysis ...
Execute ORA ...
100 permutations completed
200 permutations completed
300 permutations completed
400 permutations completed
500 permutations completed
600 permutations completed
700 permutations completed
800 permutations completed
900 permutations completed
1000 permutations completed
Creating gene report ...
Creating set view ...
Creating kegg view ...
Error in UseMethod("select_") : 
  no applicable method for 'select_' applied to an object of class "c('OrgDb', 'AnnotationDb', 'envRefClass', '.environment', 'refClass', 'environment', 'refObject', 'AssayData')"
Error in UseMethod("select_") : 
  no applicable method for 'select_' applied to an object of class "c('OrgDb', 'AnnotationDb', 'envRefClass', '.environment', 'refClass', 'environment', 'refObject', 'AssayData')"
Error in `$<-.data.frame`(`*tmp*`, "labels", value = c("", "", "", "",  : 
  replacement has 45 rows, data has 55

sessionInfo():

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] pathview_1.20.0             bindrcpp_0.2.2              dplyr_0.7.6                 hgu95av2.db_3.2.3          
 [5] org.Hs.eg.db_3.6.0          AnnotationDbi_1.42.1        ALL_1.22.0                  EnrichmentBrowser_2.10.9   
 [9] graph_1.58.0                SummarizedExperiment_1.10.1 DelayedArray_0.6.4          BiocParallel_1.14.2        
[13] matrixStats_0.54.0          Biobase_2.40.0              GenomicRanges_1.32.6        GenomeInfoDb_1.16.0        
[17] IRanges_2.14.10             S4Vectors_0.18.3            BiocGenerics_0.26.0        

loaded via a namespace (and not attached):

  [1] backports_1.1.2          GOstats_2.46.0           Hmisc_4.1-1              fastmatch_1.1-0         
  [5] BiocFileCache_1.4.0      plyr_1.8.4               igraph_1.2.2             lazyeval_0.2.1          
  [9] GSEABase_1.42.0          splines_3.5.1            ggplot2_3.0.0            digest_0.6.15           
 [13] BiocInstaller_1.30.0     ensembldb_2.4.1          htmltools_0.3.6          GOSemSim_2.6.0          
 [17] viridis_0.5.1            GO.db_3.6.0              magrittr_1.5             checkmate_1.8.5         
 [21] memoise_1.1.0            BSgenome_1.48.0          cluster_2.0.7-1          limma_3.36.2            
 [25] Biostrings_2.48.0        annotate_1.58.0          R.utils_2.6.0            ggbio_1.28.4            
 [29] prettyunits_1.0.2        enrichplot_1.0.2         colorspace_1.3-2         blob_1.1.1              
 [33] rappdirs_0.3.1           ggrepel_0.8.0            crayon_1.3.4             RCurl_1.95-4.11         
 [37] genefilter_1.62.0        bindr_0.1.1              VariantAnnotation_1.26.1 survival_2.42-6         
 [41] glue_1.3.0               gtable_0.2.0             zlibbioc_1.26.0          XVector_0.20.0          
 [45] UpSetR_1.3.3             graphite_1.26.1          Rgraphviz_2.24.0         SparseM_1.77            
 [49] scales_0.5.0             DOSE_3.6.1               DBI_1.0.0                GGally_1.4.0            
 [53] edgeR_3.22.3             Rcpp_0.12.18             progress_1.2.0           viridisLite_0.3.0       
 [57] xtable_1.8-2             htmlTable_1.12           units_0.6-0              foreign_0.8-71          
 [61] bit_1.1-14               reactome.db_1.64.0       OrganismDbi_1.22.0       Formula_1.2-3           
 [65] AnnotationForge_1.22.2   htmlwidgets_1.2          httr_1.3.1               fgsea_1.6.0             
 [69] RColorBrewer_1.1-2       acepack_1.4.1            R.methodsS3_1.7.1        reshape_0.8.7           
 [73] pkgconfig_2.0.1          XML_3.98-1.13            nnet_7.3-12              dbplyr_1.2.2            
 [77] locfit_1.5-9.1           tidyselect_0.2.4         rlang_0.2.1              reshape2_1.4.3          
 [81] munsell_0.5.0            tools_3.5.1              RSQLite_2.1.1            ggridges_0.5.0          
 [85] stringr_1.3.1            knitr_1.20               bit64_0.9-7              purrr_0.2.5             
 [89] AnnotationFilter_1.4.0   KEGGREST_1.20.1          ggraph_1.0.2             ReactomePA_1.24.0       
 [93] RBGL_1.56.0              R.oo_1.22.0              KEGGgraph_1.40.0         DO.db_2.9               
 [97] biomaRt_2.36.1           compiler_3.5.1           rstudioapi_0.7           curl_3.2                
[101] png_0.1-7                PFAM.db_3.6.0            tibble_1.4.2             tweenr_0.1.5            
[105] geneplotter_1.58.0       stringi_1.1.7            GenomicFeatures_1.32.0   lattice_0.20-35         
[109] ProtGenerics_1.12.0      Matrix_1.2-14            pillar_1.3.0             data.table_1.11.4       
[113] cowplot_0.9.3            bitops_1.0-6             rtracklayer_1.40.3       qvalue_2.12.0           
[117] hwriter_1.3.2            R6_2.2.2                 latticeExtra_0.6-28      gridExtra_2.3           
[121] dichromat_2.0-0          MASS_7.3-50              assertthat_0.2.0         DESeq2_1.20.0           
[125] Category_2.46.0          ReportingTools_2.20.0    safe_3.20.0              GenomicAlignments_1.16.0
[129] Rsamtools_1.32.2         GenomeInfoDbData_1.1.0   hms_0.4.2                grid_3.5.1              
[133] rpart_4.1-13             biovizBase_1.28.1        ggforce_0.1.3            base64enc_0.1-3  
lgeistlinger commented 6 years ago

Such namespace conflicts are a general problem in R. The demonstrated instance of AnnotationDbi::select clashing with dplyr::select is well reported:

https://support.bioconductor.org/p/101902/ https://stackoverflow.com/questions/24202120/dplyrselect-function-clashes-with-massselect (this time clashing with MASS::select)

and in this case again a problem within the pathview package as it does not explicitly define in its code which select is uses via the fully qualified name AnnotationDbi::select:

https://www.biostars.org/p/242157/

As long as the pathview maintainer does not change the code you have the following two options to work around that:

  1. Do not load dplyr when carrying out the analysis.
  2. Use the strategy suggested by the conflicted package which has been developed exactly for detecting such namespace conflicts:

https://github.com/r-lib/conflicted

Following this approach you would need to define for your working session which select you want to use via:

library("EnrichmentBrowser")
library("ALL")
library("hgu95av2.db")
library("dplyr")

...

select <- AnnotationDbi::select

# call ebrowser
ebrowser(...
lgeistlinger commented 6 years ago

Note further:

  1. Using perm=0 when meth="ora" invokes the typical (and much faster) over-representation analysis based on the hypergeometric distribution
  2. comb=TRUE is only effective when providing more than one enrichment method, eg meth=c("ora", "gsea") - otherwise this is ignored as there is nothing to combine if just a single method is carried out.