annotate [APliBio]Nebula tools suite/Nebula/MakeStatsCHiPSeq/makeStatsChIPSeq.R @ 3:1c699789d6d3 draft

Uploaded
author alermine
date Wed, 14 Nov 2012 06:02:48 -0500
parents 2ec3ba0e9e70
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
1 #usage $0 minValue maxValue chip.peaks control.peaks outputFile.png output.txt
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
2 args <- commandArgs()
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
3 minValue <- type.convert(args[4])
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
4 maxValue <- type.convert(args[5])
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
5 dataTable <-read.table(args[6], header=FALSE);
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
6 chip<-data.frame(dataTable)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
7 dataTable <-read.table(args[7], header=FALSE);
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
8 control<-data.frame(dataTable)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
9 x <-c((minValue-0.5):(maxValue+0.5))
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
10 breaks <- c(0,x,1000)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
11 controlHist <-hist(control$V6, breaks=breaks, right=FALSE, plot=FALSE )
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
12 chipHist <-hist(chip$V6, breaks=breaks, right=FALSE, plot=FALSE )
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
13
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
14 ifPDF <- 0
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
15 if (length(args)>=10) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
16 ifPDF=args[10]
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
17 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
18 if (ifPDF==1) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
19 pdf(file = args[8], width = 8, height = 7, pointsize = 20, bg = "white")
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
20 } else {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
21 png(filename = args[8], width = 580, height = 580, units = "px", pointsize = 20, bg = "white", res = NA)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
22 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
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")
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
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")
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
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))
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
26
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
27 #library(Hmisc)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
28 #minor.tick(nx=10, tick.ratio=0.5)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
29
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
30 dev.off()
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
31
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
32 sink(args[9], append=FALSE, split=FALSE)
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
33 cat (paste("peak height","# peaks in ChIP","# peaks in Control","#control/chip","\n",sep='\t'))
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
34 for (xval in c(minValue:maxValue)) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
35 for (i in (1:length(chipHist$mids))) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
36 if (xval==chipHist$mids[i]) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
37 ychip <- chipHist$counts[i]
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
38 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
39 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
40 for (i in (1:length(controlHist$mids))) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
41 if (xval==controlHist$mids[i]) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
42 ycontrol <- controlHist$counts[i]
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
43 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
44 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
45 cat (paste(xval,ychip,ycontrol,ycontrol/ychip,"\n",sep='\t'))
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
46 }