0
|
1 #usage $0 minValue maxValue chip.peaks control.peaks outputFile.png output.txt
|
|
2 args <- commandArgs()
|
|
3 minValue <- type.convert(args[4])
|
|
4 maxValue <- type.convert(args[5])
|
|
5 dataTable <-read.table(args[6], header=FALSE);
|
|
6 chip<-data.frame(dataTable)
|
|
7 dataTable <-read.table(args[7], header=FALSE);
|
|
8 control<-data.frame(dataTable)
|
|
9 x <-c((minValue-0.5):(maxValue+0.5))
|
|
10 breaks <- c(0,x,1000)
|
|
11 controlHist <-hist(control$V6, breaks=breaks, right=FALSE, plot=FALSE )
|
|
12 chipHist <-hist(chip$V6, breaks=breaks, right=FALSE, plot=FALSE )
|
|
13
|
|
14 ifPDF <- 0
|
|
15 if (length(args)>=10) {
|
|
16 ifPDF=args[10]
|
|
17 }
|
|
18 if (ifPDF==1) {
|
|
19 pdf(file = args[8], width = 8, height = 7, pointsize = 20, bg = "white")
|
|
20 } else {
|
|
21 png(filename = args[8], width = 580, height = 580, units = "px", pointsize = 20, bg = "white", res = NA)
|
|
22 }
|
|
23 plot(controlHist$mids,controlHist$counts,xlab = "Peak height",xlim=c(minValue-0.5,maxValue+0.5), ylab = "Peak count",pch=17, col = colors()[328], log = "y")
|
|
24 points(chipHist$mids,chipHist$counts,xlab = "peak height",xlim=c(minValue-0.5,maxValue+0.5),ylab = "peak count",pch=15, col = colors()[131], log = "y")
|
|
25 legend(maxValue*0.7,y = max(chipHist$counts)*0.7, bty="n",c("ChIP","Control"), cex=1, col = c(colors()[131],colors()[328]), lty = c(-1, -1), pch = c(15, 17))
|
|
26
|
|
27 #library(Hmisc)
|
|
28 #minor.tick(nx=10, tick.ratio=0.5)
|
|
29
|
|
30 dev.off()
|
|
31
|
|
32 sink(args[9], append=FALSE, split=FALSE)
|
|
33 cat (paste("peak height","# peaks in ChIP","# peaks in Control","#control/chip","\n",sep='\t'))
|
|
34 for (xval in c(minValue:maxValue)) {
|
|
35 for (i in (1:length(chipHist$mids))) {
|
|
36 if (xval==chipHist$mids[i]) {
|
|
37 ychip <- chipHist$counts[i]
|
|
38 }
|
|
39 }
|
|
40 for (i in (1:length(controlHist$mids))) {
|
|
41 if (xval==controlHist$mids[i]) {
|
|
42 ycontrol <- controlHist$counts[i]
|
|
43 }
|
|
44 }
|
|
45 cat (paste(xval,ychip,ycontrol,ycontrol/ychip,"\n",sep='\t'))
|
|
46 }
|