knitr::opts_chunk$set(
    fig.align = "center",
    fig.width = 3,
    fig.height = 3,
    collapse = TRUE,
    comment = "#>",
    warning = FALSE,
    message = FALSE
)
library(grid)
library(plotgardener)
library(plotgardenerData)

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:

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

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


PhanstielLab/BentoBox documentation built on May 11, 2024, 6:19 a.m.