# Peak annotation relative to genes / TSS with ChIPseeker (thesis 4.2.1 step 8). # Usage: Rscript chipseeker_annotation.R orc2_peaks.bed zld_peaks.bed # # Install once: # install.packages("BiocManager") # BiocManager::install(c("ChIPseeker", "clusterProfiler", "org.Dm.eg.db", # "TxDb.Dmelanogaster.UCSC.dm6.ensGene")) suppressMessages({ library(ChIPseeker) library(clusterProfiler) library(org.Dm.eg.db) library(TxDb.Dmelanogaster.UCSC.dm6.ensGene) }) args <- commandArgs(trailingOnly = TRUE) if (length(args) < 1) stop("give one or more peak BED files") txdb <- TxDb.Dmelanogaster.UCSC.dm6.ensGene peaks <- lapply(args, readPeakFile) names(peaks) <- sub("\\.bed$", "", basename(args)) # Promoter window: TSS +/- 3 kb promoter <- getPromoters(TxDb = txdb, upstream = 3000, downstream = 3000) tagMatrixList <- lapply(peaks, getTagMatrix, windows = promoter) peakAnnoList <- lapply(peaks, annotatePeak, TxDb = txdb, tssRegion = c(-3000, 3000), verbose = FALSE, addFlankGeneInfo = TRUE, flankDistance = 5000, annoDb = "org.Dm.eg.db") for (n in names(peakAnnoList)) { write.csv(as.data.frame(peakAnnoList[[n]]), paste0(n, "_annotation.csv"), row.names = FALSE) } pdf("peak_annotation.pdf", width = 8, height = 5) print(plotAnnoBar(peakAnnoList)) print(plotDistToTSS(peakAnnoList, title = "Distribution of transcription factor-binding loci\nrelative to TSS")) print(plotAvgProf(tagMatrixList, xlim = c(-3000, 3000))) dev.off()