Mercurial > repos > rhpvorderman > shm_csr
annotate pattern_plots.r @ 0:64d74ba01a7c draft
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
| author | rhpvorderman |
|---|---|
| date | Wed, 27 Oct 2021 12:34:47 +0000 |
| parents | |
| children |
| rev | line source |
|---|---|
|
0
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
1 library(ggplot2) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
2 library(reshape2) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
3 library(scales) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
4 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
5 args <- commandArgs(trailingOnly = TRUE) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
6 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
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" |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
8 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
9 plot1.path = args[2] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
10 plot1.png = paste(plot1.path, ".png", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
11 plot1.txt = paste(plot1.path, ".txt", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
12 plot1.pdf = paste(plot1.path, ".pdf", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
13 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
14 plot2.path = args[3] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
15 plot2.png = paste(plot2.path, ".png", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
16 plot2.txt = paste(plot2.path, ".txt", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
17 plot2.pdf = paste(plot2.path, ".pdf", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
18 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
19 plot3.path = args[4] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
20 plot3.png = paste(plot3.path, ".png", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
21 plot3.txt = paste(plot3.path, ".txt", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
22 plot3.pdf = paste(plot3.path, ".pdf", sep="") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
23 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
24 clean.output = args[5] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
25 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
26 dat = read.table(input.file, header=F, sep=",", quote="", stringsAsFactors=F, fill=T, row.names=1) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
27 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
28 classes = c("IGA", "IGA1", "IGA2", "IGG", "IGG1", "IGG2", "IGG3", "IGG4", "IGM", "IGE") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
29 xyz = c("x", "y", "z") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
30 new.names = c(paste(rep(classes, each=3), xyz, sep="."), paste("un", xyz, sep="."), paste("all", xyz, sep=".")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
31 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
32 names(dat) = new.names |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
33 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
34 clean.dat = dat |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
35 clean.dat = clean.dat[,c(paste(rep(classes, each=3), xyz, sep="."), paste("all", xyz, sep="."), paste("un", xyz, sep="."))] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
36 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
37 write.table(clean.dat, clean.output, quote=F, sep="\t", na="", row.names=T, col.names=NA) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
38 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
39 dat["RGYW.WRCY",] = colSums(dat[c(14,15),], na.rm=T) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
40 dat["TW.WA",] = colSums(dat[c(16,17),], na.rm=T) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
41 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
42 data1 = dat[c("RGYW.WRCY", "TW.WA"),] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
43 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
44 data1 = data1[,names(data1)[grepl(".z", names(data1))]] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
45 names(data1) = gsub("\\..*", "", names(data1)) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
46 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
47 data1 = melt(t(data1)) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
48 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
49 names(data1) = c("Class", "Type", "value") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
50 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
51 chk = is.na(data1$value) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
52 if(any(chk)){ |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
53 data1[chk, "value"] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
54 } |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
55 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
56 data1 = data1[order(data1$Type),] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
57 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
58 write.table(data1, plot1.txt, quote=F, sep="\t", na="", row.names=F, col.names=T) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
59 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
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") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
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")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
62 #p = p + scale_colour_manual(values=c("RGYW.WRCY" = "black", "TW.WA" = "blue4")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
63 png(filename=plot1.png, width=510, height=300) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
64 print(p) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
65 dev.off() |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
66 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
67 ggsave(plot1.pdf, p) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
68 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
69 data2 = dat[c(1, 5:8),] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
70 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
71 data2 = data2[,names(data2)[grepl("\\.x", names(data2))]] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
72 names(data2) = gsub(".x", "", names(data2)) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
73 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
74 data2["A/T",] = dat["Targeting of A T (%)",names(dat)[grepl("\\.z", names(dat))]] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
75 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
76 data2["G/C transitions",] = round(data2["Transitions at G C (%)",] / data2["Number of Mutations (%)",] * 100, 1) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
77 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
78 data2["mutation.at.gc",] = dat["Transitions at G C (%)",names(dat)[grepl("\\.y", names(dat))]] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
79 data2["G/C transversions",] = round((data2["mutation.at.gc",] - data2["Transitions at G C (%)",]) / data2["Number of Mutations (%)",] * 100, 1) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
80 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
81 data2["G/C transversions",is.nan(unlist(data2["G/C transversions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
82 data2["G/C transversions",is.infinite(unlist(data2["G/C transversions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
83 data2["G/C transitions",is.nan(unlist(data2["G/C transitions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
84 data2["G/C transitions",is.infinite(unlist(data2["G/C transitions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
85 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
86 data2 = melt(t(data2[c("A/T","G/C transitions","G/C transversions"),])) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
87 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
88 names(data2) = c("Class", "Type", "value") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
89 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
90 chk = is.na(data2$value) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
91 if(any(chk)){ |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
92 data2[chk, "value"] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
93 } |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
94 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
95 data2 = data2[order(data2$Type),] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
96 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
97 write.table(data2, plot2.txt, quote=F, sep="\t", na="", row.names=F, col.names=T) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
98 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
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") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
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")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
101 #p = p + scale_colour_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "black")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
102 png(filename=plot2.png, width=480, height=300) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
103 print(p) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
104 dev.off() |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
105 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
106 ggsave(plot2.pdf, p) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
107 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
108 data3 = dat[c(5, 6, 8, 18:21),] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
109 data3 = data3[,names(data3)[grepl("\\.x", names(data3))]] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
110 names(data3) = gsub(".x", "", names(data3)) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
111 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
112 data3["G/C transitions",] = round(data3["Transitions at G C (%)",] / (data3["C",] + data3["G",]) * 100, 1) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
113 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
114 data3["G/C transversions",] = round((data3["Targeting of G C (%)",] - data3["Transitions at G C (%)",]) / (data3["C",] + data3["G",]) * 100, 1) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
115 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
116 data3["A/T",] = round(data3["Targeting of A T (%)",] / (data3["A",] + data3["T",]) * 100, 1) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
117 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
118 data3["G/C transitions",is.nan(unlist(data3["G/C transitions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
119 data3["G/C transitions",is.infinite(unlist(data3["G/C transitions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
120 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
121 data3["G/C transversions",is.nan(unlist(data3["G/C transversions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
122 data3["G/C transversions",is.infinite(unlist(data3["G/C transversions",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
123 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
124 data3["A/T",is.nan(unlist(data3["A/T",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
125 data3["A/T",is.infinite(unlist(data3["A/T",]))] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
126 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
127 data3 = melt(t(data3[8:10,])) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
128 names(data3) = c("Class", "Type", "value") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
129 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
130 chk = is.na(data3$value) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
131 if(any(chk)){ |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
132 data3[chk, "value"] = 0 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
133 } |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
134 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
135 data3 = data3[order(data3$Type),] |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
136 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
137 write.table(data3, plot3.txt, quote=F, sep="\t", na="", row.names=F, col.names=T) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
138 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
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") |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
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")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
141 #p = p + scale_colour_manual(values=c("A/T" = "blue4", "G/C transversions" = "gray74", "G/C transitions" = "black")) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
142 png(filename=plot3.png, width=480, height=300) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
143 print(p) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
144 dev.off() |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
145 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
146 ggsave(plot3.pdf, p) |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
147 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
148 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
149 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
150 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
151 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
152 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
153 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
154 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
155 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
156 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
157 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
158 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
159 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
160 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
161 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
162 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
163 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
164 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
165 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
166 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
167 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
168 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
169 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
170 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
171 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
172 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
173 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
174 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
175 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
176 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
177 |
|
64d74ba01a7c
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff
changeset
|
178 |
