diff annotate_peak/annotatePeak.R @ 19:741b192da59c draft

Uploaded
author testtool
date Mon, 20 Mar 2017 07:19:42 -0400
parents 6a9b9694acbf
children 2044ad2c1c93
line wrap: on
line diff
--- a/annotate_peak/annotatePeak.R	Mon Mar 20 06:51:22 2017 -0400
+++ b/annotate_peak/annotatePeak.R	Mon Mar 20 07:19:42 2017 -0400
@@ -1,16 +1,22 @@
 require("ChIPseeker", quietly = TRUE)
 require("ChIPpeakAnno", quietly = TRUE)
 require("EnsDb.Hsapiens.v75", quietly = TRUE)
-require("data.table", quietly = TRUE)
+require("EnsDb.Mmusculus.v75", quietly = TRUE)
 
 options(warn = -1)
 options("download.file.method"="wget")
 
-args <- commandArgs(trailingOnly = TRUE)
+args <- commandArgs(trailingOnly = TRUE) 
 DMR = args[1]
-annoPeakTable = args[2]
+annoData = args[2]
+bindingType = args[3]
+upstream = as.numeric(args[4])
+downstream = as.numeric(args[5])
+ignore = args[6]
+annoPeakTable = args[7]
 
-DMRInfo = fread(
+#DMR <- ("test-data/DMR.bed")
+DMRInfo = read.table(
   DMR,
   header = FALSE,
   sep = "\t",
@@ -22,9 +28,28 @@
                     ranges = IRanges
                     (start = DMRInfo[, 2], end = DMRInfo[, 3]))
 
-annoData <- toGRanges(EnsDb.Hsapiens.v75)
+
+if (annoData == "human"){
+  annoData <- toGRanges(EnsDb.Hsapiens.v75)
+} else {
+  annoData <- toGRanges(EnsDb.Mmusculus.v75)
+}
 seqlevelsStyle(peaks) <- seqlevelsStyle(annoData)
 
-anno <- annoPeaks(peaks, annoData=annoData,bindingType ="startSite")
+if (ignore == "true"){
+  x <- TRUE
+} else {
+  x <- FALSE
+  }
+
 
-write.table(anno, annoPeakTable, row.names = FALSE)
\ No newline at end of file
+if (bindingType =="startSite"){
+anno <- annoPeaks(peaks, annoData=annoData, bindingType =c("startSite"), bindingRegion=c(upstream, downstream), ignore.peak.strand = x)
+} else if (bindingType =="endSite"){
+  anno <- annoPeaks(peaks, annoData=annoData, bindingType =c("endSite"),  bindingRegion=c(upstream, downstream), ignore.peak.strand = x)  
+} else {
+  anno <- annoPeaks(peaks, annoData=annoData, bindingType =c("fullRange"),  bindingRegion=c(upstream, downstream), ignore.peak.strand = x)  
+}
+  
+
+write.table(anno, annoPeakTable, row.names = FALSE)