ben-laufer / DMRichR

A R package and executable for the preprocessing, statistical analysis, and downstream testing and visualization of differentially methylated regions (DMRs) from CpG count matrices (Bismark cytosine reports)
https://www.benlaufer.com/DMRichR/
MIT License
39 stars 22 forks source link

Error in h(simpleError(msg, call)) : error in evaluating the argument 'args' in selecting a method for function 'do.call': GRanges objects don't support [[, as.list(), lapply(), or unlist() at the moment #57

Closed wb-yun closed 2 years ago

wb-yun commented 3 years ago

Dear author, I got a error message when I tried to use this impressive package for WGBS analysis. I wrote R scripts like this, DMRichR::DM.R(genome=c("hg38"),testCovariate = "Diagnosis", adjustCovariate = c("Sex","Age"), sexCheck = TRUE, cores = 50, coverage = 1, perGroup = 0.8, minCpGs = 5, maxPerms = 12, maxBlockPerms = 12,cutoff = 0.05,EnsDb = TRUE, cellComposition = FALSE,GOfuncR = TRUE)

The error message in R console is,

[DMRichR] Smoothing individual methylation values        15-09-2021 03:59:41 AM 
  |==============================================================================================================================================| 100%

Extracting individual smoothed methylation values of DMRs...
Saving individual smoothed methylation values to DMRs/DMR_individual_smoothed_methylation.txt
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'args' in selecting a method for function 'do.call': GRanges objects don't support [[, as.list(), lapply(), or unlist() at the moment

I think that the error occurred at the step of "ChromHMM and Reference Epigenome Enrichments."

My data are 6 control and 6 cases CpG report files which were generated from subsampling bam files by bismark and samtools view -bs function. However, I don't think that the input files are the problem because Bismark would make intact output files.

How to solve this error?

The session info is below,

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] ensembldb_2.16.4                           AnnotationFilter_1.16.0                    org.Hs.eg.db_3.13.0                       
 [4] TxDb.Hsapiens.UCSC.hg38.knownGene_3.13.0   GenomicFeatures_1.44.2                     AnnotationDbi_1.54.1                      
 [7] BSgenome.Hsapiens.UCSC.hg38.masked_1.3.993 BSgenome.Hsapiens.UCSC.hg38_1.4.3          BSgenome_1.60.0                           
[10] rtracklayer_1.52.1                         Biostrings_2.60.2                          XVector_0.32.0                            
[13] DMRichR_1.7.2                              dmrseq_1.12.0                              bsseq_1.28.0                              
[16] SummarizedExperiment_1.22.0                Biobase_2.52.0                             MatrixGenerics_1.4.3                      
[19] matrixStats_0.60.1                         GenomicRanges_1.44.0                       GenomeInfoDb_1.28.4                       
[22] IRanges_2.26.0                             S4Vectors_0.30.0                           BiocGenerics_0.38.0                       

loaded via a namespace (and not attached):
  [1] Hmisc_4.5-0                                        ps_1.6.0                                          
  [3] class_7.3-18                                       Rsamtools_2.8.0                                   
  [5] rprojroot_2.0.2                                    foreach_1.5.1                                     
  [7] crayon_1.4.1                                       MASS_7.3-53                                       
  [9] rhdf5filters_1.4.0                                 nlme_3.1-151                                      
 [11] backports_1.2.1                                    GOSemSim_2.18.1                                   
 [13] rlang_0.4.11                                       readxl_1.3.1                                      
 [15] SparseM_1.81                                       callr_3.7.0                                       
 [17] limma_3.48.3                                       minfi_1.38.0                                      
 [19] filelock_1.0.2                                     plyranges_1.12.1                                  
 [21] BiocParallel_1.26.2                                hablar_0.3.0                                      
 [23] rjson_0.2.20                                       bit64_4.0.5                                       
 [25] glue_1.4.2                                         pheatmap_1.0.12                                   
 [27] rngtools_1.5                                       processx_3.5.2                                    
 [29] regioneR_1.24.0                                    R2HTML_2.3.2                                      
 [31] tcltk_4.1.0                                        DOSE_3.18.2                                       
 [33] tidyselect_1.1.1                                   XML_3.99-0.7                                      
 [35] tidyr_1.1.3                                        zoo_1.8-9                                         
 [37] GenomicAlignments_1.28.0                           xtable_1.8-4                                      
 [39] magrittr_2.0.1                                     PerformanceAnalytics_2.0.4                        
 [41] ggplot2_3.3.5                                      cli_3.0.1                                         
 [43] sm_2.2-5.7                                         zlibbioc_1.38.0                                   
 [45] ggbiplot_0.55                                      rstudioapi_0.13                                   
 [47] doRNG_1.8.2                                        rpart_4.1-15                                      
 [49] wordcloud_2.6                                      fastmatch_1.1-3                                   
 [51] treeio_1.16.2                                      shiny_1.6.0                                       
 [53] xfun_0.26                                          tm_0.7-8                                          
 [55] askpass_1.1                                        pkgbuild_1.2.0                                    
 [57] multtest_2.48.0                                    cluster_2.1.0                                     
 [59] caTools_1.18.2                                     tidygraph_1.2.0                                   
 [61] KEGGREST_1.32.0                                    tibble_3.1.4                                      
 [63] interactiveDisplayBase_1.30.0                      ggrepel_0.9.1                                     
 [65] base64_2.0                                         mapplots_1.5.1                                    
 [67] ape_5.5                                            scrime_1.3.5                                      
 [69] GOfuncR_1.12.0                                     png_0.1-7                                         
 [71] permute_0.9-5                                      reshape_0.8.8                                     
 [73] withr_2.4.2                                        slam_0.1-48                                       
 [75] bitops_1.0-7                                       ggforce_0.3.3                                     
 [77] RBGL_1.68.0                                        cellranger_1.1.0                                  
 [79] plyr_1.8.6                                         e1071_1.7-8                                       
 [81] LOLA_1.22.0                                        coda_0.19-4                                       
 [83] pillar_1.6.2                                       bumphunter_1.34.0                                 
 [85] biocViews_1.60.0                                   gplots_3.1.1                                      
 [87] GlobalOptions_0.1.2                                cachem_1.0.6                                      
 [89] NLP_0.2-1                                          GetoptLong_1.0.5                                  
 [91] RUnit_0.4.32                                       DelayedMatrixStats_1.14.3                         
 [93] xts_0.12.1                                         vctrs_0.3.8                                       
 [95] ellipsis_0.3.2                                     generics_0.1.0                                    
 [97] outliers_0.14                                      tools_4.1.0                                       
 [99] foreign_0.8-81                                     munsell_0.5.0                                     
[101] tweenr_1.0.2                                       proxy_0.4-26                                      
[103] fgsea_1.18.0                                       emmeans_1.6.3                                     
[105] DelayedArray_0.18.0                                fastmap_1.1.0                                     
[107] compiler_4.1.0                                     httpuv_1.6.3                                      
[109] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2            beanplot_1.2                                      
[111] gt_0.3.1                                           GenomeInfoDbData_1.2.6                            
[113] gridExtra_2.3                                      enrichR_3.0                                       
[115] edgeR_3.34.1                                       lattice_0.20-41                                   
[117] utf8_1.2.2                                         later_1.3.0                                       
[119] dplyr_1.0.7                                        BiocFileCache_2.0.0                               
[121] rrvgo_1.4.4                                        jsonlite_1.7.2                                    
[123] methylCC_1.6.0                                     scales_1.1.1                                      
[125] graph_1.70.0                                       lsmeans_2.30-0                                    
[127] tidytree_0.3.5                                     sparseMatrixStats_1.4.2                           
[129] estimability_1.3                                   genefilter_1.74.0                                 
[131] lazyeval_0.2.2                                     promises_1.2.0.1                                  
[133] latticeExtra_0.6-29                                R.utils_2.10.1                                    
[135] checkmate_2.0.0                                    openxlsx_4.2.4                                    
[137] nor1mix_1.3-0                                      cowplot_1.1.1                                     
[139] vioplot_0.3.7                                      siggenes_1.66.0                                   
[141] forcats_0.5.1                                      treemap_2.4-3                                     
[143] igraph_1.2.6                                       HDF5Array_1.20.0                                  
[145] survival_3.2-7                                     yaml_2.2.1                                        
[147] plotrix_3.8-1                                      Glimma_2.2.0                                      
[149] htmltools_0.5.2                                    memoise_2.0.0                                     
[151] BiocIO_1.2.0                                       locfit_1.5-9.4                                    
[153] graphlayouts_0.7.1                                 quadprog_1.5-8                                    
[155] viridisLite_0.4.0                                  digest_0.6.27                                     
[157] assertthat_0.2.1                                   mime_0.11                                         
[159] rappdirs_0.3.3                                     wesanderson_0.3.6                                 
[161] RSQLite_2.2.8                                      yulab.utils_0.0.2                                 
[163] remotes_2.4.0                                      data.table_1.14.0                                 
[165] blob_1.2.2                                         R.oo_1.24.0                                       
[167] preprocessCore_1.54.0                              splines_4.1.0                                     
[169] Formula_1.2-4                                      ggsci_2.9                                         
[171] Rhdf5lib_1.14.2                                    illuminaio_0.34.0                                 
[173] AnnotationHub_3.0.1                                ProtGenerics_1.24.0                               
[175] FlowSorted.Blood.450k_1.30.0                       RCurl_1.98-1.4                                    
[177] broom_0.7.9                                        hms_1.1.0                                         
[179] rhdf5_2.36.0                                       colorspace_2.0-2                                  
[181] base64enc_0.1-3                                    BiocManager_1.30.16                               
[183] Boruta_7.0.0                                       aplot_0.1.0                                       
[185] nnet_7.3-15                                        sass_0.4.0                                        
[187] GEOquery_2.60.0                                    Rcpp_1.0.7                                        
[189] mclust_5.4.7                                       mvtnorm_1.1-2                                     
[191] enrichplot_1.13.1.992                              fansi_0.5.0                                       
[193] ChIPseeker_1.29.1                                  R6_2.5.1                                          
[195] grid_4.1.0                                         lifecycle_1.0.0                                   
[197] zip_2.2.0                                          curl_4.3.2                                        
[199] DO.db_2.9                                          Matrix_1.3-2                                      
[201] qvalue_2.24.0                                      RColorBrewer_1.1-2                                
[203] iterators_1.0.13                                   stringr_1.4.0                                     
[205] IlluminaHumanMethylation450kmanifest_0.4.0         htmlwidgets_1.5.4                                 
[207] polyclip_1.10-0                                    biomaRt_2.48.3                                    
[209] purrr_0.3.4                                        shadowtext_0.0.8                                  
[211] gridGraphics_0.5-1                                 CMplot_3.6.2                                      
[213] openssl_1.4.5                                      htmlTable_2.2.1                                   
[215] patchwork_1.1.1                                    codetools_0.2-18                                  
[217] IlluminaHumanMethylation450kanno.ilmn12.hg19_0.6.0 GO.db_3.13.0                                      
[219] gtools_3.9.2                                       prettyunits_1.1.1                                 
[221] dbplyr_2.1.1                                       gridBase_0.4-7                                    
[223] R.methodsS3_1.8.1                                  gtable_0.3.0                                      
[225] DBI_1.1.1                                          ggfun_0.0.3                                       
[227] httr_1.4.2                                         KernSmooth_2.23-18                                
[229] stringi_1.7.4                                      progress_1.2.2                                    
[231] reshape2_1.4.4                                     farver_2.1.0                                      
[233] annotate_1.70.0                                    viridis_0.6.1                                     
[235] rGREAT_1.24.0                                      ggtree_3.0.4                                      
[237] xml2_1.3.2                                         boot_1.3-26                                       
[239] sigFeature_1.10.0                                  restfulr_0.0.13                                   
[241] readr_1.4.0                                        geneplotter_1.70.0                                
[243] ggplotify_0.1.0                                    BiocVersion_3.13.1                                
[245] DESeq2_1.32.0                                      bit_4.0.4                                         
[247] scatterpie_0.1.7                                   jpeg_0.1-9                                        
[249] ggraph_2.0.5                                       annotatr_1.18.1                                   
[251] pkgconfig_2.0.3                                    knitr_1.34     
ben-laufer commented 2 years ago

Hi @wb-yun, I haven't yet seen this type of error with DMRichR. Is it possible for you try running this in an earlier version of R, I haven't gotten a chance to test out DMRichR in R 4.1 yet. Also, you can probably drop the cores down to 20. If it happens again, can you give me some more details about your subsampling approach? Since we can take a look at the bsseq object.

wb-yun commented 2 years ago

Thank you for the response. I changed R version from 4.1 to 4.0.5 and dropped the cores down to 20. The process is running. I will share the result.

wb-yun commented 2 years ago

I got error messages.

First error is "DMRs can't be plotted", second error message is "undefined columns selected".

Selecting significant DMRs...
Exporting DMR and background region information...
Saving DMRs/DMRs.bed
Saving DMRs/backgroundRegions.bed
Summary: There are 31 DMRs (42% hypermethylated, 58% hypomethylated) from 482 background regions consisting of 276315 CpGs assayed at 1x coverage
DMR timing...
Saving Rdata...
Annotating DMRs and plotting...
[plotDMRs] Plotting 31 DMRs
[plotDMRs] Smoothing raw methylation values with loess for line plots
ERROR: One (or more) of your DMRs can't be plotted, try again later by manually loading R Data and subsetting sigRegions

[DMRichR] Annotating DMRs with gene symbols          24-09-2021 04:33:47 AM 

 Preparing HTML report...Annotating 31 regions from GRCh38 with gene symbols
Error in `[.data.frame`(nearestFeatures.df, , cn) : 
  undefined columns selected
In addition: There were 15 warnings (use warnings() to see them)

The process can't reach the previous stop point.

The log of the same step in first try is,

Summary: There are 30 DMRs (40% hypermethylated, 60% hypomethylated) from 482 background regions consisting of 276315 CpGs assayed at 1x coverage
DMR timing...
Saving Rdata...
Annotating DMRs and plotting...
[plotDMRs] Plotting 30 DMRs
[plotDMRs] Smoothing raw methylation values with loess for line plots
ERROR: One (or more) of your DMRs can't be plotted, try again later by manually loading R Data and subsetting sigRegions

[DMRichR] Annotating DMRs with gene symbols          15-09-2021 03:59:19 AM 

 Preparing HTML report...Annotating 30 regions from GRCh38 with gene symbols
'select()' returned 1:1 mapping between keys and columns
Done 
Annotating background regions with gene symbols...
Annotating 482 regions from GRCh38 with gene symbols
'select()' returned 1:many mapping between keys and columns

[DMRichR] Smoothing individual methylation values        15-09-2021 03:59:41 AM 
  |==============================================================================================================================================| 100%

I just know that the same plotting error was in first try.


Also, I found an additional message in middle of log

Selecting significant blocks...
Exporting block and background information...
Saving Blocks/backgroundBlocks.bed
Blocks timing...
Annotating background blocks with gene symbols...
Annotating 4 regions from GRCh38 with gene symbols
Block analysis has produced an error
ben-laufer commented 2 years ago

Hi @wb-yun, thanks for sharing the logs. The error you're running into this time is related to ensembldb and the workaround for this would be setting EnsDb = FALSE. I added that option in for non-model organisms, so I'd recommend the default UCSC annotations for the human genome. DMRichR will convert the sequence levels automatically for you, so this will still work even if you aligned to GRCh38.

The other two errors you get are more so warnings. Some DMRs can't be plotted, so the program will skip that step instead of stopping and then you can manually plot any of interest that it didn't get to. The other error related to blocks can happen when no significant blocks are detected.

wb-yun commented 2 years ago

Everything is working well without errors. Thank you so much.

One more question, I want to get the input data file for heatmap.pdf file in DMRs directory, how do I have the file?

ben-laufer commented 2 years ago

Glad to hear and you're welcome.

To answer the other question, you'd have to load the RData from its folder and then run the first few lines of code from smoothPheatmap():

  bsseq::getMeth(BSseq = bs.filtered.bsseq,
                 regions = sigRegions,
                 type = "smooth",
                 what = "perRegion") %>% 
    na.omit() %>% 
    as.matrix()

Finally, here's a link to some code showing an example of how to further customize your pheatmap with ComplexHeatmap: https://github.com/ben-laufer/PCB-Placenta-and-Brain/blob/main/ComplexHeatmap.R