|
0
|
1 #usage $0 STEP RIGHT chipPeaks outputFile.png output.txt [controlPeaks]
|
|
|
2 args <- commandArgs()
|
|
|
3 input <- args[4]
|
|
|
4 pngFile <- args[5]
|
|
|
5 dataTable <-read.table(file=input, header=TRUE);
|
|
|
6 chip.data<-data.frame(dataTable)
|
|
|
7 ifReg <- 0
|
|
|
8 if (length(unique(chip.data$Reg))>1) {
|
|
|
9 ifReg <- 1
|
|
|
10 }
|
|
|
11
|
|
|
12 ifPDF <- 0
|
|
|
13 if (length(args)>=7) {
|
|
|
14 ifPDF=args[7]
|
|
|
15 }
|
|
|
16 if (length(args)==6 & args[6]==1) {
|
|
|
17 ifPDF=1
|
|
|
18 }
|
|
|
19
|
|
|
20 ifControl <- 0
|
|
|
21 if (length(args)>=6 & args[6]!=1 & args[6]!=0) {
|
|
|
22 dataTable <-read.table(file=args[6], header=TRUE);
|
|
|
23 control.data<-data.frame(dataTable)
|
|
|
24 ifControl <- 1
|
|
|
25 }
|
|
|
26 if (ifReg & ifControl) {
|
|
|
27
|
|
|
28 if (ifPDF==1) {
|
|
|
29 pdf(file = pngFile, width = 14, height = 13, pointsize = 20, bg = "white")
|
|
|
30 } else {
|
|
|
31 png(filename = pngFile, width = 1440, height = 1040, units = "px", pointsize = 20, bg = "white", res = NA)
|
|
|
32 plot(1:10)
|
|
|
33 }
|
|
|
34 op <- par(mfrow = c(3,2))
|
|
|
35 } else {
|
|
|
36
|
|
|
37 if (ifPDF==1) {
|
|
|
38 pdf(file = pngFile, width = 22, height = 8, pointsize = 20, bg = "white")
|
|
|
39 } else {
|
|
|
40 png(filename = pngFile, width = 1580, height = 530, units = "px", pointsize = 20, bg = "white", res = NA)
|
|
|
41 plot(1:10)
|
|
|
42 }
|
|
|
43 op <- par(mfrow = c(1,2))
|
|
|
44 }
|
|
|
45 myColor <- 1
|
|
|
46 myColor[1] <- colors()[131]
|
|
|
47 myColor[2] <- colors()[59]
|
|
|
48 myColor[3] <- colors()[76]
|
|
|
49 myColor[4] <- colors()[88]
|
|
|
50 myColor[5] <- colors()[17]
|
|
|
51 myColor[6] <- colors()[565]
|
|
|
52 myColorControl <- 1
|
|
|
53 myColorControl[1] <- colors()[24]
|
|
|
54 myColorControl[2] <- colors()[278]
|
|
|
55 myColorControl[3] <- colors()[305]
|
|
|
56 myColorControl[4] <- colors()[219]
|
|
|
57 myColorControl[5] <- colors()[343]
|
|
|
58 myColorControl[6] <- colors()[245]
|
|
|
59 myLevels <- 0
|
|
|
60 if (ifReg) {
|
|
|
61 if (ifControl) {
|
|
|
62 #control vs real:
|
|
|
63
|
|
|
64 countTotal <- length(chip.data$Reg)
|
|
|
65 totalChIP <- summary(chip.data$Type)/countTotal
|
|
|
66 tt <- which(chip.data$Type=="intragenic")
|
|
|
67 subset.chip <- chip.data[tt,]
|
|
|
68 countIntra <- length(subset.chip$Reg)
|
|
|
69 intraChip<- summary(subset.chip$TypeIntra)/countTotal
|
|
|
70 nlev <- length(levels(chip.data$Type))
|
|
|
71 countTotalCont <- length(control.data$Reg)
|
|
|
72 totalContr <- summary(control.data$Type)/countTotalCont
|
|
|
73 tt <- which(control.data$Type=="intragenic")
|
|
|
74 subset.control <- control.data[tt,]
|
|
|
75 countIntraCont <- length(subset.control$Reg)
|
|
|
76 intraControl<- summary(subset.control$TypeIntra)/countTotalCont
|
|
|
77 cum = matrix( 0, nrow=2, ncol=nlev, byrow = TRUE)
|
|
|
78 for (i in c(1:nlev)) {
|
|
|
79 cum[1,i] <- totalChIP[i]
|
|
|
80 cum[2,i] <- totalContr[i]
|
|
|
81 }
|
|
|
82
|
|
|
83 labels<-c("GeneDown.", "Enh.", "Imm.Down.", "Interg.", "Intrag.", "Prom.")
|
|
|
84 if (length(labels)==length(levels(chip.data$Type))) {
|
|
|
85 barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],colors()[328]), names.arg=labels,ylab="Proportion of peaks")
|
|
|
86 } else {
|
|
|
87 barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],colors()[328]), names.arg=c(levels(chip.data$Type)),ylab="Proportion of peaks")
|
|
|
88 }
|
|
|
89
|
|
|
90 position <- 'topleft'
|
|
|
91 inset <- c(0.1, 0)
|
|
|
92 legend(position, c("ChIP","Control"), bty="n",fill=c(myColor[1],colors()[328]), inset=inset)
|
|
|
93
|
|
|
94 nlev <- length(levels(subset.chip$TypeIntra))
|
|
|
95 cum = matrix( 0, nrow=2, ncol=nlev, byrow = TRUE)
|
|
|
96 for (i in c(1:nlev)) {
|
|
|
97 cum[1,i] <- intraChip[i]
|
|
|
98 cum[2,i] <- intraControl[i]
|
|
|
99 }
|
|
|
100 barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],colors()[328]), names.arg=c(levels(subset.chip$TypeIntra)),ylab="Proportion of peaks")
|
|
|
101
|
|
|
102 position <- 'topleft'
|
|
|
103 inset <- c(0.1, 0)
|
|
|
104 legend(position, c("ChIP","Control"), bty="n",fill=c(myColor[1],colors()[328]), inset=inset)
|
|
|
105 }
|
|
|
106 n.types <- length(levels(chip.data$Reg))
|
|
|
107 myLevels <- levels(chip.data$Reg)
|
|
|
108 nlev <- length(levels(chip.data$Type))
|
|
|
109 cum = matrix( 0, nrow=length(myLevels), ncol=nlev, byrow = TRUE)
|
|
|
110 countTotal <- length(chip.data$Reg)
|
|
|
111 colReg <-NULL
|
|
|
112 for (r in c(1:length(myLevels))) {
|
|
|
113 tt <- which(chip.data$Reg==myLevels[r])
|
|
|
114 totalChIP <- summary(chip.data$Type[tt])/countTotal
|
|
|
115 for (i in c(1:nlev)) {
|
|
|
116 cum[r,i] <- totalChIP[i]
|
|
|
117 }
|
|
|
118 colReg[r]<-myColor[r+3]
|
|
|
119 }
|
|
|
120
|
|
|
121 labels<-c("GeneDown.", "Enh.", "Imm.Down.", "Interg.", "Intrag.", "Prom.")
|
|
|
122 if (length(labels)==length(levels(chip.data$Type))) {
|
|
|
123 #barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],myColor[5]), names.arg=labels,ylab="Proportion of peaks")
|
|
|
124 barplot(cum,xlab="",beside=TRUE, col=c(colReg), names.arg=labels,ylab="Proportion of peaks")
|
|
|
125 } else {
|
|
|
126 barplot(cum,xlab="",beside=TRUE, col=c(colReg), names.arg=c(levels(chip.data$Type)),ylab="Proportion of peaks")
|
|
|
127 }
|
|
|
128
|
|
|
129 position <- 'topleft'
|
|
|
130 inset <- c(0.1, 0)
|
|
|
131 legend(position, c(myLevels), bty="n",fill=c(colReg), inset=inset)
|
|
|
132
|
|
|
133
|
|
|
134 nlev <- length(levels(chip.data$TypeIntra))
|
|
|
135 cum = matrix( 0, nrow=length(myLevels), ncol=nlev, byrow = TRUE)
|
|
|
136 for (r in c(1:length(myLevels))) {
|
|
|
137 tt <- which(chip.data$Reg==myLevels[r]&chip.data$Type=="intragenic")
|
|
|
138 totalChIP <- summary(chip.data$TypeIntra[tt])/countTotal
|
|
|
139 for (i in c(1:nlev)) {
|
|
|
140 cum[r,i] <- totalChIP[i]
|
|
|
141 }
|
|
|
142 }
|
|
|
143 barplot(cum,xlab="",beside=TRUE, col=c(colReg), names.arg=c(levels(chip.data$TypeIntra)),ylab="Proportion of peaks")
|
|
|
144 position <- 'topleft'
|
|
|
145 inset <- c(0.1, 0)
|
|
|
146 legend(position, c(myLevels), bty="n",fill=c(colReg), inset=inset)
|
|
|
147
|
|
|
148
|
|
|
149 if (ifControl) {
|
|
|
150 nlev <- length(levels(control.data$Type))
|
|
|
151 cum = matrix( 0, nrow=length(myLevels), ncol=nlev, byrow = TRUE)
|
|
|
152 countTotal <- length(control.data$Reg)
|
|
|
153 colReg <-NULL
|
|
|
154 for (r in c(1:length(myLevels))) {
|
|
|
155 tt <- which(control.data$Reg==myLevels[r])
|
|
|
156 totalcontrol <- summary(control.data$Type[tt])/countTotal
|
|
|
157 for (i in c(1:nlev)) {
|
|
|
158 cum[r,i] <- totalcontrol[i]
|
|
|
159 }
|
|
|
160 colReg[r]<-myColorControl[r+3]
|
|
|
161 }
|
|
|
162 labels<-c("GeneDown.", "Enh.", "Imm.Down.", "Interg.", "Intrag.", "Prom.")
|
|
|
163 if (length(labels)==length(levels(chip.data$Type))) {
|
|
|
164 barplot(cum,xlab="",beside=TRUE, col=c(colReg), names.arg=labels,ylab="Proportion of peaks")
|
|
|
165 } else {
|
|
|
166 barplot(cum,xlab="",beside=TRUE, col=c(colReg), names.arg=c(levels(control.data$Type)),ylab="Proportion of peaks")
|
|
|
167 }
|
|
|
168 position <- 'topleft'
|
|
|
169 inset <- c(0.1, 0)
|
|
|
170 legend(position, c(myLevels), bty="n",fill=c(colReg), inset=inset)
|
|
|
171
|
|
|
172 nlev <- length(levels(control.data$TypeIntra))
|
|
|
173 cum = matrix( 0, nrow=length(myLevels), ncol=nlev, byrow = TRUE)
|
|
|
174 for (r in c(1:length(myLevels))) {
|
|
|
175 tt <- which(control.data$Reg==myLevels[r]&control.data$Type=="intragenic")
|
|
|
176 totalcontrol <- summary(control.data$TypeIntra[tt])/countTotal
|
|
|
177 for (i in c(1:nlev)) {
|
|
|
178 cum[r,i] <- totalcontrol[i]
|
|
|
179 }
|
|
|
180 }
|
|
|
181 barplot(cum,xlab="",beside=TRUE, col=c(colReg), names.arg=c(levels(control.data$TypeIntra)),ylab="Proportion of peaks")
|
|
|
182 position <- 'topleft'
|
|
|
183 inset <- c(0.1, 0)
|
|
|
184 legend(position, c(myLevels), bty="n",fill=c(colReg), inset=inset)
|
|
|
185 }
|
|
|
186 } else {
|
|
|
187 countTotal <- length(chip.data$Reg)
|
|
|
188 totalChIP <- summary(chip.data$Type)/countTotal
|
|
|
189 tt <- which(chip.data$Type=="intragenic")
|
|
|
190 subset.chip <- chip.data[tt,]
|
|
|
191 countIntra <- length(subset.chip$Reg)
|
|
|
192 intraChip<- summary(subset.chip$TypeIntra)/countTotal
|
|
|
193 nlev <- length(levels(chip.data$Type))
|
|
|
194 if (ifControl) {
|
|
|
195 countTotalCont <- length(control.data$Reg)
|
|
|
196 totalContr <- summary(control.data$Type)/countTotalCont
|
|
|
197 tt <- which(control.data$Type=="intragenic")
|
|
|
198 subset.control <- control.data[tt,]
|
|
|
199 countIntraCont <- length(subset.control$Reg)
|
|
|
200 intraControl<- summary(subset.control$TypeIntra)/countTotalCont
|
|
|
201 cum = matrix( 0, nrow=2, ncol=nlev, byrow = TRUE)
|
|
|
202 for (i in c(1:nlev)) {
|
|
|
203 cum[1,i] <- totalChIP[i]
|
|
|
204 cum[2,i] <- totalContr[i]
|
|
|
205 }
|
|
|
206
|
|
|
207 labels<-c("GeneDown.", "Enh.", "Imm.Down.", "Interg.", "Intrag.", "Prom.")
|
|
|
208 if (length(labels)==length(levels(chip.data$Type))) {
|
|
|
209 #barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],myColor[5]), names.arg=labels,ylab="Proportion of peaks")
|
|
|
210 barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],colors()[328]), names.arg=labels,ylab="Proportion of peaks")
|
|
|
211 } else {
|
|
|
212 barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],colors()[328]), names.arg=c(levels(chip.data$Type)),ylab="Proportion of peaks")
|
|
|
213 }
|
|
|
214
|
|
|
215 position <- 'topleft'
|
|
|
216 inset <- c(0.1, 0)
|
|
|
217 legend(position,c("ChIP","Control"), bty="n",fill=c(myColor[1],colors()[328]), inset=inset)
|
|
|
218
|
|
|
219 nlev <- length(levels(subset.chip$TypeIntra))
|
|
|
220 cum = matrix( 0, nrow=2, ncol=nlev, byrow = TRUE)
|
|
|
221 for (i in c(1:nlev)) {
|
|
|
222 cum[1,i] <- intraChip[i]
|
|
|
223 cum[2,i] <- intraControl[i]
|
|
|
224 }
|
|
|
225 barplot(cum,xlab="",beside=TRUE, col=c(myColor[1],colors()[328]), names.arg=c(levels(subset.chip$TypeIntra)),ylab="Proportion of peaks")
|
|
|
226 position <- 'topleft'
|
|
|
227 inset <- c(0.1, 0)
|
|
|
228 legend(position,c("ChIP","Control"), bty="n",fill=c(myColor[1],colors()[328]), inset=inset)
|
|
|
229
|
|
|
230 } else {
|
|
|
231 labels<-c("GeneDown.", "Enh.", "Imm.Down.", "Interg.", "Intrag.", "Prom.")
|
|
|
232 if (length(labels)==length(levels(chip.data$Type))) {
|
|
|
233 barplot(totalChIP,xlab="", col=myColor, names.arg=labels,ylab="Proportion of peaks")
|
|
|
234 } else {
|
|
|
235 barplot(totalChIP,xlab="", col=myColor,ylab="Proportion of peaks")
|
|
|
236 }
|
|
|
237 barplot(intraChip,xlab="", col=myColor,ylab="Proportion of peaks")
|
|
|
238 }
|
|
|
239 }
|
|
|
240 dev.off()
|