Introduction

Methrix provides set of function which allows easy importing of various flavors of bedgraphs generated by methylation callers, and many downstream analysis to be performed on large matrices.

This vignette describes basic usage of the package intended to process several large bedgraph files in R. In addition, a detailed exemplary complete data analysis with steps from reading in to annotation and differential methylation calling can be found in our WGBS best practices workflow

Overview and usage functions of the package

Installation

NOTE

Installation from BioConductor requires the BioC and R versions to be the newest. This arises from the restrictions imposed by BioConductor community which might cause package incompatibilities with the earlier versions of R (for e.g; R < 4.0). In that case installing from GitHub might be easier since it is much more merciful with regards to versions.

Reading bedgraph files

read_bedgraphs function is a versatile bedgraph reader intended to import bedgraph files generated virtually by any sort of methylation calling program. It requires user to provide indices for chromosome names, start position and other required fields. There are also presets available to import bedgraphs from most common programs such as Bismark, MethylDackel, and MethylcTools.

We can import bedgraph files with the function read_bedgraphs which reads in the bedgraphs, adds CpGs missing from the reference set, and creates a methylation/coverage matrices. Once the process is complete - it returns an object of class methrix which in turn inherits SummarizedExperiment class. methrix object contains ‘methylation’ and ‘coverage’ matrices (either in-memory or as on-disk HDF5 arrays) along with pheno-data and other basic info. This object can be passed to all downstream functions for various analysis.

Note: Use the argument pipeline if your bedgraphs are generated with “Bismark”, “MethylDeckal”, or “MethylcTools”. This will automatically figure out the file formats for you, and you dont have to use the arguments chr_idx start_idx and so..

HTML QC report

Get basic summary statistics of the methrix object with methrix_report function which produces an interactive html report

Click here for an example report.

Basic operations

Extract methylation/coverage matrices

SessionInfo

sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] bsseq_1.34.0                         MafDb.1Kgenomes.phase3.hs37d5_3.10.0
#>  [3] GenomicScores_2.10.0                 BSgenome.Hsapiens.UCSC.hg19_1.4.3   
#>  [5] BSgenome_1.66.0                      rtracklayer_1.58.0                  
#>  [7] Biostrings_2.66.0                    XVector_0.38.0                      
#>  [9] methrix_1.12.0                       SummarizedExperiment_1.28.0         
#> [11] Biobase_2.58.0                       GenomicRanges_1.50.0                
#> [13] GenomeInfoDb_1.34.0                  IRanges_2.32.0                      
#> [15] S4Vectors_0.36.0                     BiocGenerics_0.44.0                 
#> [17] MatrixGenerics_1.10.0                matrixStats_0.62.0                  
#> [19] data.table_1.14.4                   
#> 
#> loaded via a namespace (and not attached):
#>   [1] colorspace_2.0-3              rjson_0.2.21                 
#>   [3] ellipsis_0.3.2                farver_2.1.1                 
#>   [5] bit64_4.0.5                   interactiveDisplayBase_1.36.0
#>   [7] AnnotationDbi_1.60.0          fansi_1.0.3                  
#>   [9] codetools_0.2-18              R.methodsS3_1.8.2            
#>  [11] sparseMatrixStats_1.10.0      cachem_1.0.6                 
#>  [13] knitr_1.40                    jsonlite_1.8.3               
#>  [15] Rsamtools_2.14.0              dbplyr_2.2.1                 
#>  [17] png_0.1-7                     R.oo_1.25.0                  
#>  [19] shiny_1.7.3                   HDF5Array_1.26.0             
#>  [21] BiocManager_1.30.19           compiler_4.2.1               
#>  [23] httr_1.4.4                    assertthat_0.2.1             
#>  [25] Matrix_1.5-1                  fastmap_1.1.0                
#>  [27] limma_3.54.0                  cli_3.4.1                    
#>  [29] later_1.3.0                   htmltools_0.5.3              
#>  [31] tools_4.2.1                   gtable_0.3.1                 
#>  [33] glue_1.6.2                    GenomeInfoDbData_1.2.9       
#>  [35] dplyr_1.0.10                  rappdirs_0.3.3               
#>  [37] Rcpp_1.0.9                    jquerylib_0.1.4              
#>  [39] vctrs_0.5.0                   rhdf5filters_1.10.0          
#>  [41] DelayedMatrixStats_1.20.0     xfun_0.34                    
#>  [43] stringr_1.4.1                 mime_0.12                    
#>  [45] lifecycle_1.0.3               restfulr_0.0.15              
#>  [47] gtools_3.9.3                  XML_3.99-0.12                
#>  [49] AnnotationHub_3.6.0           zlibbioc_1.44.0              
#>  [51] scales_1.2.1                  promises_1.2.0.1             
#>  [53] parallel_4.2.1                rhdf5_2.42.0                 
#>  [55] RColorBrewer_1.1-3            yaml_2.3.6                   
#>  [57] curl_4.3.3                    memoise_2.0.1                
#>  [59] ggplot2_3.3.6                 sass_0.4.2                   
#>  [61] stringi_1.7.8                 RSQLite_2.2.18               
#>  [63] BiocVersion_3.16.0            highr_0.9                    
#>  [65] BiocIO_1.8.0                  permute_0.9-7                
#>  [67] filelock_1.0.2                BiocParallel_1.32.0          
#>  [69] rlang_1.0.6                   pkgconfig_2.0.3              
#>  [71] bitops_1.0-7                  evaluate_0.17                
#>  [73] lattice_0.20-45               Rhdf5lib_1.20.0              
#>  [75] GenomicAlignments_1.34.0      labeling_0.4.2               
#>  [77] bit_4.0.4                     tidyselect_1.2.0             
#>  [79] magrittr_2.0.3                R6_2.5.1                     
#>  [81] generics_0.1.3                DelayedArray_0.24.0          
#>  [83] DBI_1.1.3                     pillar_1.8.1                 
#>  [85] KEGGREST_1.38.0               RCurl_1.98-1.9               
#>  [87] tibble_3.1.8                  crayon_1.5.2                 
#>  [89] utf8_1.2.2                    BiocFileCache_2.6.0          
#>  [91] rmarkdown_2.17                locfit_1.5-9.6               
#>  [93] grid_4.2.1                    blob_1.2.3                   
#>  [95] digest_0.6.30                 xtable_1.8-4                 
#>  [97] httpuv_1.6.6                  R.utils_2.12.1               
#>  [99] munsell_0.5.0                 bslib_0.4.0