knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
For this vignette, we will import narrowPeak and broadPeak files. We will
then show how to annotate the results with the r Biocpkg("ChIPseeker")
package. To complete this demo, you will need the following packages:
library(peakimport) require(ChIPseeker) require(TxDb.Hsapiens.UCSC.hg19.knownGene) require(org.Hs.eg.db) require(purrr)
In this section we will show how to import both narrowPeak and broadPeak
files. We will first show how to import each type separately, and then we will
show how we can use lapply or map to import multiple files with a single
command.
narrowPeak filesThe narrowPeak file format is described on the
UCSC webpage.
It is not a valid format and cannot be directly imported using the import
function from rtracklayer.
narrowPeak_file <- get_demo_file("narrowPeak") gr_narrowPeak <- import_peaks(narrowPeak_file) gr_narrowPeak
The results is a GRanges object.
broadPeak filesThe broadPeak file format is described on the
UCSC webpage.
Similar to the narrowPeak format, it is not a valid bed file and will need
to be imported accordingly.
broadPeak_file <- get_demo_file("broadPeak") gr_broadPeak <- import_peaks(broadPeak_file) gr_broadPeak
The results is also a GRanges object.
We can use functions such as lapply or map (from the r CRANpkg("purrr")
package) to import multiple files in a single command:
multiple_files <- c(narrowPeak_file, broadPeak_file) names(multiple_files) <- c("narrowPeak", "broadPeak") grl <- lapply(multiple_files, import_peaks) # or grl <- map(multiple_files, import_peaks) grl
Both lapply and map will return the same result: a list of GRanges.
The import_peaks function will determine if the file is a bed, narrowPeak
or broadPeak file based on the file extension and will select the correct
import strategy accordingly. It is important for the file extensions to be
exactly .narrowPeak and .broadPeak.
We will use the r Biocpkg("ChIPseeker") package to annotate the results from
import_peaks:
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene anno_narrowPeak <- annotatePeak(gr_narrowPeak, TxDb = txdb, annoDb = "org.Hs.eg.db") anno_narrowPeak anno_broadPeak <- annotatePeak(gr_broadPeak, TxDb = txdb, annoDb = "org.Hs.eg.db") anno_broadPeak
The result can be converted in the GRanges format with the as.GRanges
function:
gr_anno_narrowPeak <- as.GRanges(anno_narrowPeak) gr_anno_narrowPeak gr_anno_broadPeak <- as.GRanges(anno_broadPeak) gr_anno_broadPeak
Finally, we can annotate multiple peaks in a single command with lapply or
map:
anno_grl <- map(grl, annotatePeak, TxDb = txdb, annoDb = "org.Hs.eg.db") gr_anno_grl <- map(anno_grl, as.GRanges) gr_anno_grl
sessionInfo()sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.