annotate pattern_plots.r @ 31:fe44a905aee9 draft

Uploaded
author davidvanzessen
date Tue, 13 Dec 2016 10:06:49 -0500
parents 81453585dfc3
children 05c62efdc393
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="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
12
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
13 plot2.path = args[3]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
14 plot2.png = paste(plot2.path, ".png", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
15 plot2.txt = paste(plot2.path, ".txt", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
16
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
17 plot3.path = args[4]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
18 plot3.png = paste(plot3.path, ".png", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
19 plot3.txt = paste(plot3.path, ".txt", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
20
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
21 clean.output = args[5]
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
22
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
23 dat = read.table(input.file, header=F, sep=",", quote="", stringsAsFactors=F, fill=T, row.names=1)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
24
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
25
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
26
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
27 classes = c("IGA", "IGA1", "IGA2", "IGG", "IGG1", "IGG2", "IGG3", "IGG4", "IGM", "IGE")
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
28 xyz = c("x", "y", "z")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
29 new.names = c(paste(rep(classes, each=3), xyz, sep="."), paste("un", xyz, sep="."), paste("all", xyz, sep="."))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
30
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
31 names(dat) = new.names
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
32
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
33 clean.dat = dat
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
34 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
35
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
36 write.table(clean.dat, clean.output, quote=F, sep="\t", na="", row.names=T, col.names=NA)
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
37
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
38 dat["RGYW.WRCY",] = colSums(dat[c(13,14),], na.rm=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
39 dat["TW.WA",] = colSums(dat[c(15,16),], na.rm=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
40
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
41 data1 = dat[c("RGYW.WRCY", "TW.WA"),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
42
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
43 data1 = data1[,names(data1)[grepl(".z", names(data1))]]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
44 names(data1) = gsub("\\..*", "", names(data1))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
45
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
46 data1 = melt(t(data1))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
47
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
48 names(data1) = c("Class", "Type", "value")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
49
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
50 data1 = data1[order(data1$Type),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
51
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
52 write.table(data1, plot1.txt, quote=F, sep="\t", na="", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
53
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
54 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))
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
55 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
56 #p = p + scale_colour_manual(values=c("RGYW.WRCY" = "black", "TW.WA" = "blue4"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
57 png(filename=plot1.png, width=480, height=300)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
58 print(p)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
59 dev.off()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
60
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
61 data2 = dat[c(1, 5:8),]
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
62
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
63 data2 = data2[,names(data2)[grepl("\\.x", names(data2))]]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
64 names(data2) = gsub(".x", "", names(data2))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
65
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
66 data2["A/T",] = dat["Targeting of A T (%)",names(dat)[grepl("\\.z", names(dat))]]
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
67
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
68 data2["G/C transitions",] = round(data2["Transitions at G C (%)",] / data2["Number of Mutations (%)",] * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
69
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
70 data2["mutation.at.gc",] = dat["Transitions at G C (%)",names(dat)[grepl("\\.y", names(dat))]]
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
71 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
72
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
73 data2["G/C transversions",is.nan(unlist(data2["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
74 data2["G/C transversions",is.infinite(unlist(data2["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
75 data2["G/C transitions",is.nan(unlist(data2["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
76 data2["G/C transitions",is.infinite(unlist(data2["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
77
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
78 data2 = melt(t(data2[c("A/T","G/C transitions","G/C transversions"),]))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
79
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
80 names(data2) = c("Class", "Type", "value")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
81
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
82 data2 = data2[order(data2$Type),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
83
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
84 write.table(data2, plot2.txt, quote=F, sep="\t", na="", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
85
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
86 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")
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
87 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
88 #p = p + scale_colour_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "black"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
89 png(filename=plot2.png, width=480, height=300)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
90 print(p)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
91 dev.off()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
92
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
93 data3 = dat[c(5, 6, 8, 17:20),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
94 data3 = data3[,names(data3)[grepl("\\.x", names(data3))]]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
95 names(data3) = gsub(".x", "", names(data3))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
96
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
97 data3[is.na(data3)] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
98 #data3[is.infinite(data3)] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
99
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
100 data3["G/C transitions",] = round(data3["Transitions at G C (%)",] / (data3["C",] + data3["G",]) * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
101
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
102 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
103
23
81453585dfc3 Uploaded
davidvanzessen
parents: 5
diff changeset
104 data3["A/T",] = round(data3["Targeting of A T (%)",] / (data3["A",] + data3["T",]) * 100, 1)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
105
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
106 data3["G/C transitions",is.nan(unlist(data3["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
107 data3["G/C transitions",is.infinite(unlist(data3["G/C transitions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
108
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
109 data3["G/C transversions",is.nan(unlist(data3["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
110 data3["G/C transversions",is.infinite(unlist(data3["G/C transversions",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
111
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
112 data3["A/T",is.nan(unlist(data3["A/T",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
113 data3["A/T",is.infinite(unlist(data3["A/T",]))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
114
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
115 data3 = melt(t(data3[8:10,]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
116 names(data3) = c("Class", "Type", "value")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
117
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
118 data3 = data3[order(data3$Type),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
119
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
120 write.table(data3, plot3.txt, quote=F, sep="\t", na="", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
121
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
122 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))
5
012a738edf5a Uploaded
davidvanzessen
parents: 1
diff changeset
123 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
124 #p = p + scale_colour_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "black"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
125 png(filename=plot3.png, width=480, height=300)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
126 print(p)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
127 dev.off()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
128
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
129
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
130
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
131
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
132
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
133
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
134
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
135
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
136
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
137
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
138
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
139
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
140
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
141
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
142
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
143
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
144
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
145
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
146
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