plotgardener handles a wide array of genomic data types in various formats and file types. Not only does it work with data.frames, data.tables, tibbles, and Bioconductor GRanges and GInteractions objects, but it can also read in common genomic file types like BED, BEDPE, bigWig, and .hic files. While files can be read directly into plotgardener plotting functions, plotgardener also provides functions for reading in these large genomic data sets to work with them within the R environment:

  • readBigwig(): Read in entire bigWig files, or read in specific genomic regions or strands of bigWig data. Please note that this function does not work on Windows.
bwFile <- system.file("extdata/test.bw", package="plotgardenerData")

## Read in entire file
bwFileData <- readBigwig(file = bwFile)

## Read in specified region
bwRegion <- readBigwig(file = bwFile,
                        chrom = "chr2",
                        chromstart = 1,
                        chromend = 1500)
     
## Read in specified region on "+" strand
bwRegionPlus <- readBigwig(file = bwFile,
                            chrom = "chr2",
                            chromstart = 1, 
                            chromend = 1500,
                            strand = "+")

The resulting file will contain seqnames, start, end, width, strand, and score columns:

head(bwRegion)
#>   seqnames start  end width strand score
#> 1     chr2     1  300   300      * -1.00
#> 2     chr2   301  600   300      * -0.75
#> 3     chr2   601  900   300      * -0.50
#> 4     chr2   901 1200   300      * -0.25
#> 5     chr2  1201 1500   300      *  0.00
  • readHic(): Read in genomic regions of .hic files with various data resolutions and normalizations.
hicFile <- system.file("extdata/test_chr22.hic", package="plotgardenerData")

hicDataChrom <- readHic(file = hicFile,
    chrom = "22", assembly = "hg19",
    resolution = 250000, res_scale = "BP", norm = "NONE"
)

hicDataChromRegion <- readHic(file = hicFile,
    chrom = "22", assembly = "hg19",
    chromstart = 20000000, chromend = 47500000,
    resolution = 100000, res_scale = "BP", norm = "KR"
)

These data will be output in 3-column dataframe in sparse upper triangular matrix format:

head(hicDataChromRegion)
#>       22_A     22_B    counts
#> 1 20000000 20000000 55.390347
#> 2 20000000 20100000  6.737655
#> 3 20100000 20100000 31.963037
#> 4 20000000 20200000  3.204865
#> 5 20100000 20200000 12.864663
#> 6 20200000 20200000 37.828201

It is also possible to use readHic for interchromosomal Hi-C data:

twoChroms <- readHic(file = "/path/to/hic",
    chrom = "chr1", altchrom = "chr2",
    resolution = 250000, res_scale = "BP"
)

For other filetypes, we recommend reading in files with data.table or rtracklayer.

library(data.table)
data <- data.table::fread("/path/to/file")

library(rtracklayer)
data <- rtracklayer::import(con = "/path/to/file", format = "fileFormat")

Session Info

sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur/Monterey 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] grid      stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#> [1] plotgardenerData_1.1.0 plotgardener_1.2.0    
#> 
#> loaded via a namespace (and not attached):
#>  [1] MatrixGenerics_1.8.0        Biobase_2.56.0             
#>  [3] sass_0.4.1                  jsonlite_1.8.0             
#>  [5] bslib_0.3.1                 assertthat_0.2.1           
#>  [7] stats4_4.2.0                yulab.utils_0.0.4          
#>  [9] GenomeInfoDbData_1.2.8      Rsamtools_2.12.0           
#> [11] yaml_2.3.5                  pillar_1.7.0               
#> [13] lattice_0.20-45             glue_1.6.2                 
#> [15] digest_0.6.29               GenomicRanges_1.48.0       
#> [17] RColorBrewer_1.1-3          XVector_0.36.0             
#> [19] colorspace_2.0-3            htmltools_0.5.2            
#> [21] Matrix_1.4-1                strawr_0.0.9               
#> [23] XML_3.99-0.9                pkgconfig_2.0.3            
#> [25] zlibbioc_1.42.0             purrr_0.3.4                
#> [27] scales_1.2.0                ggplotify_0.1.0            
#> [29] BiocParallel_1.30.0         tibble_3.1.6               
#> [31] generics_0.1.2              IRanges_2.30.0             
#> [33] ggplot2_3.3.5               ellipsis_0.3.2             
#> [35] cachem_1.0.6                SummarizedExperiment_1.26.0
#> [37] BiocGenerics_0.42.0         cli_3.3.0                  
#> [39] magrittr_2.0.3              crayon_1.5.1               
#> [41] memoise_2.0.1               evaluate_0.15              
#> [43] fs_1.5.2                    fansi_1.0.3                
#> [45] textshaping_0.3.6           tools_4.2.0                
#> [47] data.table_1.14.2           BiocIO_1.6.0               
#> [49] lifecycle_1.0.1             matrixStats_0.62.0         
#> [51] stringr_1.4.0               plyranges_1.16.0           
#> [53] S4Vectors_0.34.0            munsell_0.5.0              
#> [55] DelayedArray_0.22.0         Biostrings_2.64.0          
#> [57] compiler_4.2.0              pkgdown_2.0.3              
#> [59] jquerylib_0.1.4             GenomeInfoDb_1.32.0        
#> [61] gridGraphics_0.5-1          systemfonts_1.0.4          
#> [63] rlang_1.0.2                 RCurl_1.98-1.6             
#> [65] rstudioapi_0.13             rjson_0.2.21               
#> [67] bitops_1.0-7                rmarkdown_2.14             
#> [69] restfulr_0.0.13             gtable_0.3.0               
#> [71] DBI_1.1.2                   curl_4.3.2                 
#> [73] R6_2.5.1                    GenomicAlignments_1.32.0   
#> [75] knitr_1.39                  dplyr_1.0.9                
#> [77] rtracklayer_1.56.0          fastmap_1.1.0              
#> [79] utf8_1.2.2                  rprojroot_2.0.3            
#> [81] ragg_1.2.2                  desc_1.4.1                 
#> [83] stringi_1.7.6               parallel_4.2.0             
#> [85] Rcpp_1.0.8.3                vctrs_0.4.1                
#> [87] tidyselect_1.1.2            xfun_0.30