annotate pattern_plots.r @ 18:949a30f04d9b draft

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