1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| library(ChIPseeker) library(GenomicFeatures) library(tidyverse)
txdb <- makeTxDbFromGFF('gencode.v44.annotation.gff3') saveDb(txdb, file="gencode.v44.sqlite") hg38 <- loadDb("gencode.v44.sqlite")
samplefiles <- list.files(".", pattern = ".broadPeak", full.names = T) samplefiles <- as.list(samplefiles) names(samplefiles) <- c("H3K27ac", "H3K4me3") peakAnnoList <- lapply(samplefiles, annotatePeak, TxDb=hg38, tssRegion=c(-3000, 3000), addFlankGeneInfo = TRUE, flankDistance = 5000) H3K27ac_anno <- as.data.frame(peakAnnoList[["H3K27ac"]]@anno)
tx2gene <- read.table("gene2gene.txt", header = T) tx2gene <- tx2gene %>% as.data.frame()
H3K27ac_gi <- unique(H3K27ac_anno$geneId) H3K27ac_gs <- tx2gene %>% filter(geneId %in% H3K27ac_gi) m <- match(H3K27ac_anno$geneId, H3K27ac_gs$geneId) H3K27ac_anno <- cbind(H3K27ac_anno[,1:18], geneSymbol=H3K27ac_gs$symbol[m], H3K27ac_anno[,19:21]) write.table(H3K27ac_anno, file="H3K27ac_peakAnn.txt", sep="\t", quote=F, row.names=F)
peak1 <- readPeakFile('sample1_peaks.narrowPeak') peak2 <- readPeakFile('sample2_peaks.narrowPeak') peaks <- list(sample1 = peak1, sample2 = peak2) plotPeakProf2(peaks, upstream = 3000, downstream = 3000, conf = 0.95, by = "gene", type = "start_site", TxDb = hg38, facet="row") plotPeakProf2(peaks, upstream = rel(0.2), downstream = rel(0.2), conf = 0.95, by = "gene", type = "body", nbin = 800, TxDb = hg38, facet="row") peakAnnoList <- lapply(peaks, annotatePeak, TxDb=hg38, tssRegion=c(-3000, 3000), annoDb="org.Hs.eg.db") plotAnnoBar(peakAnnoList) plotDistToTSS(peakAnnoList) upsetplot(peakAnnoList[1], vennpie=TRUE) write.table(peakAnnoList[1], file = 'sample1_peak_ann.txt', sep = '\t', quote = FALSE, row.names = FALSE)
|