annotate pattern_plots.r @ 71:2649a821162d draft

Uploaded
author davidvanzessen
date Thu, 31 Jan 2019 05:53:59 -0500
parents 1cf60ae234b4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
1 library(ggplot2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
2 library(reshape2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
3 library(scales)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
4
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
5 args <- commandArgs(trailingOnly = TRUE)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
6
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
7 input.file = args[1] #the data that's get turned into the "SHM overview" table in the html report "data_sum.txt"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
8
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
9 plot1.path = args[2]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
10 plot1.png = paste(plot1.path, ".png", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
11 plot1.txt = paste(plot1.path, ".txt", sep="")
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
12 plot1.pdf = paste(plot1.path, ".pdf", sep="")
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
13
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
14 plot2.path = args[3]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
15 plot2.png = paste(plot2.path, ".png", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
16 plot2.txt = paste(plot2.path, ".txt", sep="")
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
17 plot2.pdf = paste(plot2.path, ".pdf", sep="")
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
18
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
19 plot3.path = args[4]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
20 plot3.png = paste(plot3.path, ".png", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
21 plot3.txt = paste(plot3.path, ".txt", sep="")
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
22 plot3.pdf = paste(plot3.path, ".pdf", sep="")
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
23
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
24 clean.output = args[5]
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
25
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
26 dat = read.table(input.file, header=F, sep=",", quote="", stringsAsFactors=F, fill=T, row.names=1)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
27
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
28 classes = c("IGA", "IGA1", "IGA2", "IGG", "IGG1", "IGG2", "IGG3", "IGG4", "IGM", "IGE")
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
29 xyz = c("x", "y", "z")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
30 new.names = c(paste(rep(classes, each=3), xyz, sep="."), paste("un", xyz, sep="."), paste("all", xyz, sep="."))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
31
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
32 names(dat) = new.names
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
33
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
34 clean.dat = dat
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
35 clean.dat = clean.dat[,c(paste(rep(classes, each=3), xyz, sep="."), paste("all", xyz, sep="."), paste("un", xyz, sep="."))]
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
36
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
37 write.table(clean.dat, clean.output, quote=F, sep="\t", na="", row.names=T, col.names=NA)
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
38
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
39 dat["RGYW.WRCY",] = colSums(dat[c(13,14),], na.rm=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
40 dat["TW.WA",] = colSums(dat[c(15,16),], na.rm=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
41
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
42 data1 = dat[c("RGYW.WRCY", "TW.WA"),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
43
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
44 data1 = data1[,names(data1)[grepl(".z", names(data1))]]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
45 names(data1) = gsub("\\..*", "", names(data1))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
46
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
47 data1 = melt(t(data1))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
48
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
49 names(data1) = c("Class", "Type", "value")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
50
38
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
51 chk = is.na(data1$value)
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
52 if(any(chk)){
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
53 data1[chk, "value"] = 0
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
54 }
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
55
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
56 data1 = data1[order(data1$Type),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
57
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
58 write.table(data1, plot1.txt, quote=F, sep="\t", na="", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
59
39
a24f8c93583a Uploaded
davidvanzessen
parents: 38
diff changeset
60 p = ggplot(data1, aes(Class, value)) + geom_bar(aes(fill=Type), stat="identity", position="dodge", colour = "black") + ylab("% of mutations") + guides(fill=guide_legend(title=NULL)) + ggtitle("Percentage of mutations in AID and pol eta motives")
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
61 p = p + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1)) + scale_fill_manual(values=c("RGYW.WRCY" = "white", "TW.WA" = "blue4"))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
62 #p = p + scale_colour_manual(values=c("RGYW.WRCY" = "black", "TW.WA" = "blue4"))
39
a24f8c93583a Uploaded
davidvanzessen
parents: 38
diff changeset
63 png(filename=plot1.png, width=510, height=300)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
64 print(p)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
65 dev.off()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
66
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
67 ggsave(plot1.pdf, p)
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
68
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
69 data2 = dat[c(1, 5:8),]
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
70
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
71 data2 = data2[,names(data2)[grepl("\\.x", names(data2))]]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
72 names(data2) = gsub(".x", "", names(data2))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
73
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
74 data2["A/T",] = dat["Targeting of A T (%)",names(dat)[grepl("\\.z", names(dat))]]
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
75
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
76 data2["G/C transitions",] = round(data2["Transitions at G C (%)",] / data2["Number of Mutations (%)",] * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
77
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
78 data2["mutation.at.gc",] = dat["Transitions at G C (%)",names(dat)[grepl("\\.y", names(dat))]]
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
79 data2["G/C transversions",] = round((data2["mutation.at.gc",] - data2["Transitions at G C (%)",]) / data2["Number of Mutations (%)",] * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
80
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
81 data2["G/C transversions",is.nan(unlist(data2["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
82 data2["G/C transversions",is.infinite(unlist(data2["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
83 data2["G/C transitions",is.nan(unlist(data2["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
84 data2["G/C transitions",is.infinite(unlist(data2["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
85
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
86 data2 = melt(t(data2[c("A/T","G/C transitions","G/C transversions"),]))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
87
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
88 names(data2) = c("Class", "Type", "value")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
89
38
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
90 chk = is.na(data2$value)
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
91 if(any(chk)){
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
92 data2[chk, "value"] = 0
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
93 }
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
94
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
95 data2 = data2[order(data2$Type),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
96
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
97 write.table(data2, plot2.txt, quote=F, sep="\t", na="", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
98
39
a24f8c93583a Uploaded
davidvanzessen
parents: 38
diff changeset
99 p = ggplot(data2, aes(x=Class, y=value, fill=Type)) + geom_bar(position="fill", stat="identity", colour = "black") + scale_y_continuous(labels=percent_format()) + guides(fill=guide_legend(title=NULL)) + ylab("% of mutations") + ggtitle("Relative mutation patterns")
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
100 p = p + theme(panel.background = element_rect(fill = "white", colour="black"), text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1)) + scale_fill_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "white"))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
101 #p = p + scale_colour_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "black"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
102 png(filename=plot2.png, width=480, height=300)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
103 print(p)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
104 dev.off()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
105
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
106 ggsave(plot2.pdf, p)
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
107
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
108 data3 = dat[c(5, 6, 8, 17:20),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
109 data3 = data3[,names(data3)[grepl("\\.x", names(data3))]]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
110 names(data3) = gsub(".x", "", names(data3))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
111
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
112 data3["G/C transitions",] = round(data3["Transitions at G C (%)",] / (data3["C",] + data3["G",]) * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
113
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
114 data3["G/C transversions",] = round((data3["Targeting of G C (%)",] - data3["Transitions at G C (%)",]) / (data3["C",] + data3["G",]) * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
115
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
116 data3["A/T",] = round(data3["Targeting of A T (%)",] / (data3["A",] + data3["T",]) * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
117
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
118 data3["G/C transitions",is.nan(unlist(data3["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
119 data3["G/C transitions",is.infinite(unlist(data3["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
120
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
121 data3["G/C transversions",is.nan(unlist(data3["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
122 data3["G/C transversions",is.infinite(unlist(data3["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
123
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
124 data3["A/T",is.nan(unlist(data3["A/T",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
125 data3["A/T",is.infinite(unlist(data3["A/T",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
126
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
127 data3 = melt(t(data3[8:10,]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
128 names(data3) = c("Class", "Type", "value")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
129
39
a24f8c93583a Uploaded
davidvanzessen
parents: 38
diff changeset
130 chk = is.na(data3$value)
38
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
131 if(any(chk)){
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
132 data3[chk, "value"] = 0
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
133 }
05c62efdc393 Uploaded
davidvanzessen
parents: 23
diff changeset
134
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
135 data3 = data3[order(data3$Type),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
136
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
137 write.table(data3, plot3.txt, quote=F, sep="\t", na="", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
138
39
a24f8c93583a Uploaded
davidvanzessen
parents: 38
diff changeset
139 p = ggplot(data3, aes(Class, value)) + geom_bar(aes(fill=Type), stat="identity", position="dodge", colour = "black") + ylab("% of nucleotides") + guides(fill=guide_legend(title=NULL)) + ggtitle("Absolute mutation patterns")
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
140 p = p + theme(panel.background = element_rect(fill = "white", colour="black"), text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1)) + scale_fill_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "white"))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
141 #p = p + scale_colour_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "black"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
142 png(filename=plot3.png, width=480, height=300)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
143 print(p)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
144 dev.off()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
145
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
146 ggsave(plot3.pdf, p)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
147
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
148
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
149
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
150
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
151
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
152
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
153
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
154
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
155
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
156
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
157
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
158
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
159
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
160
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
161
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
162
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
163
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
164
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
165
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
166
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
167
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
168
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
169
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
170
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
171
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
172
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
173
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
174
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
175
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
176
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
177
42
1cf60ae234b4 Uploaded
davidvanzessen
parents: 39
diff changeset
178