49
|
1 library(data.table)
|
|
2 library(ggplot2)
|
|
3
|
0
|
4 args <- commandArgs(trailingOnly = TRUE)
|
|
5
|
|
6 input = args[1]
|
4
|
7 genes = unlist(strsplit(args[2], ","))
|
0
|
8 outputdir = args[3]
|
22
|
9 include_fr1 = ifelse(args[4] == "yes", T, F)
|
0
|
10 setwd(outputdir)
|
|
11
|
|
12 dat = read.table(input, header=T, sep="\t", fill=T, stringsAsFactors=F)
|
|
13
|
|
14 if(length(dat$Sequence.ID) == 0){
|
4
|
15 setwd(outputdir)
|
|
16 result = data.frame(x = rep(0, 5), y = rep(0, 5), z = rep(NA, 5))
|
|
17 row.names(result) = c("Number of Mutations (%)", "Transition (%)", "Transversions (%)", "Transitions at G C (%)", "Targeting of C G (%)")
|
|
18 write.table(x=result, file="mutations.txt", sep=",",quote=F,row.names=T,col.names=F)
|
|
19 transitionTable = data.frame(A=rep(0, 4),C=rep(0, 4),G=rep(0, 4),T=rep(0, 4))
|
|
20 row.names(transitionTable) = c("A", "C", "G", "T")
|
|
21 transitionTable["A","A"] = NA
|
|
22 transitionTable["C","C"] = NA
|
|
23 transitionTable["G","G"] = NA
|
|
24 transitionTable["T","T"] = NA
|
|
25 write.table(x=transitionTable, file="transitions.txt", sep=",",quote=F,row.names=T,col.names=NA)
|
|
26 cat("0", file="n.txt")
|
|
27 stop("No data")
|
0
|
28 }
|
|
29
|
|
30 cleanup_columns = c("FR1.IMGT.c.a",
|
|
31 "FR2.IMGT.g.t",
|
|
32 "CDR1.IMGT.Nb.of.nucleotides",
|
|
33 "CDR2.IMGT.t.a",
|
|
34 "FR1.IMGT.c.g",
|
|
35 "CDR1.IMGT.c.t",
|
|
36 "FR2.IMGT.a.c",
|
|
37 "FR2.IMGT.Nb.of.mutations",
|
|
38 "FR2.IMGT.g.c",
|
|
39 "FR2.IMGT.a.g",
|
|
40 "FR3.IMGT.t.a",
|
|
41 "FR3.IMGT.t.c",
|
|
42 "FR2.IMGT.g.a",
|
|
43 "FR3.IMGT.c.g",
|
|
44 "FR1.IMGT.Nb.of.mutations",
|
|
45 "CDR1.IMGT.g.a",
|
|
46 "CDR1.IMGT.t.g",
|
|
47 "CDR1.IMGT.g.c",
|
|
48 "CDR2.IMGT.Nb.of.nucleotides",
|
|
49 "FR2.IMGT.a.t",
|
|
50 "CDR1.IMGT.Nb.of.mutations",
|
71
|
51 "CDR3.IMGT.Nb.of.nucleotides",
|
0
|
52 "CDR1.IMGT.a.g",
|
|
53 "FR3.IMGT.a.c",
|
|
54 "FR1.IMGT.g.a",
|
|
55 "FR3.IMGT.a.g",
|
|
56 "FR1.IMGT.a.t",
|
|
57 "CDR2.IMGT.a.g",
|
|
58 "CDR2.IMGT.Nb.of.mutations",
|
|
59 "CDR2.IMGT.g.t",
|
|
60 "CDR2.IMGT.a.c",
|
|
61 "CDR1.IMGT.t.c",
|
|
62 "FR3.IMGT.g.c",
|
|
63 "FR1.IMGT.g.t",
|
|
64 "FR3.IMGT.g.t",
|
|
65 "CDR1.IMGT.a.t",
|
|
66 "FR1.IMGT.a.g",
|
|
67 "FR3.IMGT.a.t",
|
|
68 "FR3.IMGT.Nb.of.nucleotides",
|
|
69 "FR2.IMGT.t.c",
|
|
70 "CDR2.IMGT.g.a",
|
|
71 "FR2.IMGT.t.a",
|
|
72 "CDR1.IMGT.t.a",
|
|
73 "FR2.IMGT.t.g",
|
|
74 "FR3.IMGT.t.g",
|
|
75 "FR2.IMGT.Nb.of.nucleotides",
|
|
76 "FR1.IMGT.t.a",
|
|
77 "FR1.IMGT.t.g",
|
|
78 "FR3.IMGT.c.t",
|
|
79 "FR1.IMGT.t.c",
|
|
80 "CDR2.IMGT.a.t",
|
|
81 "FR2.IMGT.c.t",
|
|
82 "CDR1.IMGT.g.t",
|
|
83 "CDR2.IMGT.t.g",
|
|
84 "FR1.IMGT.Nb.of.nucleotides",
|
|
85 "CDR1.IMGT.c.g",
|
|
86 "CDR2.IMGT.t.c",
|
|
87 "FR3.IMGT.g.a",
|
|
88 "CDR1.IMGT.a.c",
|
|
89 "FR2.IMGT.c.a",
|
|
90 "FR3.IMGT.Nb.of.mutations",
|
|
91 "FR2.IMGT.c.g",
|
|
92 "CDR2.IMGT.g.c",
|
|
93 "FR1.IMGT.g.c",
|
|
94 "CDR2.IMGT.c.t",
|
|
95 "FR3.IMGT.c.a",
|
|
96 "CDR1.IMGT.c.a",
|
|
97 "CDR2.IMGT.c.g",
|
|
98 "CDR2.IMGT.c.a",
|
42
|
99 "FR1.IMGT.c.t",
|
|
100 "FR1.IMGT.Nb.of.silent.mutations",
|
|
101 "FR2.IMGT.Nb.of.silent.mutations",
|
|
102 "FR3.IMGT.Nb.of.silent.mutations",
|
|
103 "FR1.IMGT.Nb.of.nonsilent.mutations",
|
|
104 "FR2.IMGT.Nb.of.nonsilent.mutations",
|
|
105 "FR3.IMGT.Nb.of.nonsilent.mutations")
|
0
|
106
|
|
107 for(col in cleanup_columns){
|
|
108 dat[,col] = gsub("\\(.*\\)", "", dat[,col])
|
|
109 #dat[dat[,col] == "",] = "0"
|
|
110 dat[,col] = as.numeric(dat[,col])
|
73
|
111 dat[is.na(dat[,col]),col] = 0
|
0
|
112 }
|
|
113
|
22
|
114 regions = c("FR1", "CDR1", "FR2", "CDR2", "FR3")
|
|
115 if(!include_fr1){
|
|
116 regions = c("CDR1", "FR2", "CDR2", "FR3")
|
|
117 }
|
0
|
118
|
22
|
119 sum_by_row = function(x, columns) { sum(as.numeric(x[columns]), na.rm=T) }
|
0
|
120
|
22
|
121 VRegionMutations_columns = paste(regions, ".IMGT.Nb.of.mutations", sep="")
|
|
122 dat$VRegionMutations = apply(dat, FUN=sum_by_row, 1, columns=VRegionMutations_columns)
|
|
123
|
|
124 VRegionNucleotides_columns = paste(regions, ".IMGT.Nb.of.nucleotides", sep="")
|
|
125 dat$VRegionNucleotides = apply(dat, FUN=sum_by_row, 1, columns=VRegionNucleotides_columns)
|
|
126
|
|
127 transitionMutations_columns = paste(rep(regions, each=4), c(".IMGT.a.g", ".IMGT.g.a", ".IMGT.c.t", ".IMGT.t.c"), sep="")
|
|
128 dat$transitionMutations = apply(dat, FUN=sum_by_row, 1, columns=transitionMutations_columns)
|
|
129
|
|
130 transversionMutations_columns = paste(rep(regions, each=8), c(".IMGT.a.c",".IMGT.c.a",".IMGT.a.t",".IMGT.t.a",".IMGT.g.c",".IMGT.c.g",".IMGT.g.t",".IMGT.t.g"), sep="")
|
|
131 dat$transversionMutations = apply(dat, FUN=sum_by_row, 1, columns=transversionMutations_columns)
|
0
|
132
|
|
133
|
22
|
134 transitionMutationsAtGC_columns = paste(rep(regions, each=2), c(".IMGT.g.a",".IMGT.c.t"), sep="")
|
|
135 dat$transitionMutationsAtGC = apply(dat, FUN=sum_by_row, 1, columns=transitionMutationsAtGC_columns)
|
0
|
136
|
49
|
137
|
|
138 totalMutationsAtGC_columns = paste(rep(regions, each=6), c(".IMGT.c.g",".IMGT.c.t",".IMGT.c.a",".IMGT.g.c",".IMGT.g.a",".IMGT.g.t"), sep="")
|
|
139 #totalMutationsAtGC_columns = paste(rep(regions, each=6), c(".IMGT.g.a",".IMGT.c.t",".IMGT.c.a",".IMGT.c.g",".IMGT.g.t"), sep="")
|
22
|
140 dat$totalMutationsAtGC = apply(dat, FUN=sum_by_row, 1, columns=totalMutationsAtGC_columns)
|
0
|
141
|
49
|
142 transitionMutationsAtAT_columns = paste(rep(regions, each=2), c(".IMGT.a.g",".IMGT.t.c"), sep="")
|
|
143 dat$transitionMutationsAtAT = apply(dat, FUN=sum_by_row, 1, columns=transitionMutationsAtAT_columns)
|
|
144
|
|
145 totalMutationsAtAT_columns = paste(rep(regions, each=6), c(".IMGT.a.g",".IMGT.a.c",".IMGT.a.t",".IMGT.t.g",".IMGT.t.c",".IMGT.t.a"), sep="")
|
|
146 #totalMutationsAtAT_columns = paste(rep(regions, each=5), c(".IMGT.a.g",".IMGT.t.c",".IMGT.a.c",".IMGT.g.c",".IMGT.t.g"), sep="")
|
|
147 dat$totalMutationsAtAT = apply(dat, FUN=sum_by_row, 1, columns=totalMutationsAtAT_columns)
|
|
148
|
|
149
|
24
|
150 FRRegions = regions[grepl("FR", regions)]
|
|
151 CDRRegions = regions[grepl("CDR", regions)]
|
|
152
|
|
153 FR_silentMutations_columns = paste(FRRegions, ".IMGT.Nb.of.silent.mutations", sep="")
|
|
154 dat$silentMutationsFR = apply(dat, FUN=sum_by_row, 1, columns=FR_silentMutations_columns)
|
23
|
155
|
24
|
156 CDR_silentMutations_columns = paste(CDRRegions, ".IMGT.Nb.of.silent.mutations", sep="")
|
|
157 dat$silentMutationsCDR = apply(dat, FUN=sum_by_row, 1, columns=CDR_silentMutations_columns)
|
|
158
|
|
159 FR_nonSilentMutations_columns = paste(FRRegions, ".IMGT.Nb.of.nonsilent.mutations", sep="")
|
|
160 dat$nonSilentMutationsFR = apply(dat, FUN=sum_by_row, 1, columns=FR_nonSilentMutations_columns)
|
|
161
|
|
162 CDR_nonSilentMutations_columns = paste(CDRRegions, ".IMGT.Nb.of.nonsilent.mutations", sep="")
|
|
163 dat$nonSilentMutationsCDR = apply(dat, FUN=sum_by_row, 1, columns=CDR_nonSilentMutations_columns)
|
0
|
164
|
49
|
165 mutation.sum.columns = c("Sequence.ID", "VRegionMutations", "VRegionNucleotides", "transitionMutations", "transversionMutations", "transitionMutationsAtGC", "transitionMutationsAtAT", "silentMutationsFR", "nonSilentMutationsFR", "silentMutationsCDR", "nonSilentMutationsCDR")
|
40
|
166
|
|
167 write.table(dat[,mutation.sum.columns], "mutation_by_id.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
0
|
168
|
4
|
169 setwd(outputdir)
|
|
170
|
53
|
171 calculate_result = function(i, gene, dat, matrx, f, fname, name){
|
78
|
172 tmp = dat[grepl(paste("^", gene, ".*", sep=""), dat$best_match),]
|
68
|
173
|
|
174 j = i - 1
|
|
175 x = (j * 3) + 1
|
|
176 y = (j * 3) + 2
|
|
177 z = (j * 3) + 3
|
|
178
|
|
179 if(nrow(tmp) > 0){
|
53
|
180
|
68
|
181 if(fname == "sum"){
|
|
182 matrx[1,x] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
183 matrx[1,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
184 matrx[1,z] = round(f(matrx[1,x] / matrx[1,y]) * 100, digits=1)
|
|
185 } else {
|
|
186 matrx[1,x] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
187 matrx[1,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
188 matrx[1,z] = round(f(tmp$VRegionMutations / tmp$VRegionNucleotides) * 100, digits=1)
|
|
189 }
|
53
|
190
|
|
191 matrx[2,x] = round(f(tmp$transitionMutations, na.rm=T), digits=1)
|
|
192 matrx[2,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
193 matrx[2,z] = round(matrx[2,x] / matrx[2,y] * 100, digits=1)
|
|
194
|
|
195 matrx[3,x] = round(f(tmp$transversionMutations, na.rm=T), digits=1)
|
|
196 matrx[3,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
197 matrx[3,z] = round(matrx[3,x] / matrx[3,y] * 100, digits=1)
|
|
198
|
|
199 matrx[4,x] = round(f(tmp$transitionMutationsAtGC, na.rm=T), digits=1)
|
|
200 matrx[4,y] = round(f(tmp$totalMutationsAtGC, na.rm=T), digits=1)
|
|
201 matrx[4,z] = round(matrx[4,x] / matrx[4,y] * 100, digits=1)
|
|
202
|
|
203 matrx[5,x] = round(f(tmp$totalMutationsAtGC, na.rm=T), digits=1)
|
|
204 matrx[5,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
205 matrx[5,z] = round(matrx[5,x] / matrx[5,y] * 100, digits=1)
|
|
206
|
|
207 matrx[6,x] = round(f(tmp$transitionMutationsAtAT, na.rm=T), digits=1)
|
|
208 matrx[6,y] = round(f(tmp$totalMutationsAtAT, na.rm=T), digits=1)
|
|
209 matrx[6,z] = round(matrx[6,x] / matrx[6,y] * 100, digits=1)
|
|
210
|
|
211 matrx[7,x] = round(f(tmp$totalMutationsAtAT, na.rm=T), digits=1)
|
|
212 matrx[7,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
213 matrx[7,z] = round(matrx[7,x] / matrx[7,y] * 100, digits=1)
|
|
214
|
|
215 matrx[8,x] = round(f(tmp$nonSilentMutationsFR, na.rm=T), digits=1)
|
|
216 matrx[8,y] = round(f(tmp$silentMutationsFR, na.rm=T), digits=1)
|
|
217 matrx[8,z] = round(matrx[8,x] / matrx[8,y], digits=1)
|
|
218
|
|
219 matrx[9,x] = round(f(tmp$nonSilentMutationsCDR, na.rm=T), digits=1)
|
|
220 matrx[9,y] = round(f(tmp$silentMutationsCDR, na.rm=T), digits=1)
|
|
221 matrx[9,z] = round(matrx[9,x] / matrx[9,y], digits=1)
|
71
|
222
|
|
223 if(fname == "sum"){
|
|
224 matrx[10,x] = round(f(rowSums(tmp[,c("FR2.IMGT.Nb.of.nucleotides", "FR3.IMGT.Nb.of.nucleotides")], na.rm=T)), digits=1)
|
|
225 matrx[10,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
226 matrx[10,z] = round(matrx[10,x] / matrx[10,y], digits=1)
|
|
227
|
72
|
228 matrx[11,x] = round(f(rowSums(tmp[,c("CDR1.IMGT.Nb.of.nucleotides", "CDR2.IMGT.Nb.of.nucleotides")], na.rm=T)), digits=1)
|
71
|
229 matrx[11,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
230 matrx[11,z] = round(matrx[11,x] / matrx[11,y], digits=1)
|
|
231 }
|
53
|
232 }
|
4
|
233
|
22
|
234 transitionTable = data.frame(A=zeros,C=zeros,G=zeros,T=zeros)
|
4
|
235 row.names(transitionTable) = c("A", "C", "G", "T")
|
|
236 transitionTable["A","A"] = NA
|
|
237 transitionTable["C","C"] = NA
|
|
238 transitionTable["G","G"] = NA
|
|
239 transitionTable["T","T"] = NA
|
22
|
240
|
|
241 if(nrow(tmp) > 0){
|
|
242 for(nt1 in nts){
|
|
243 for(nt2 in nts){
|
|
244 if(nt1 == nt2){
|
|
245 next
|
|
246 }
|
|
247 NT1 = LETTERS[letters == nt1]
|
|
248 NT2 = LETTERS[letters == nt2]
|
|
249 FR1 = paste("FR1.IMGT.", nt1, ".", nt2, sep="")
|
|
250 CDR1 = paste("CDR1.IMGT.", nt1, ".", nt2, sep="")
|
|
251 FR2 = paste("FR2.IMGT.", nt1, ".", nt2, sep="")
|
|
252 CDR2 = paste("CDR2.IMGT.", nt1, ".", nt2, sep="")
|
|
253 FR3 = paste("FR3.IMGT.", nt1, ".", nt2, sep="")
|
|
254 if(include_fr1){
|
|
255 transitionTable[NT1,NT2] = sum(tmp[,c(FR1, CDR1, FR2, CDR2, FR3)])
|
|
256 } else {
|
|
257 transitionTable[NT1,NT2] = sum(tmp[,c(CDR1, FR2, CDR2, FR3)])
|
|
258 }
|
|
259 }
|
|
260 }
|
|
261 }
|
4
|
262
|
|
263
|
53
|
264 print(paste("writing value file: ", name, "_", fname, "_value.txt" ,sep=""))
|
|
265
|
|
266 write.table(x=transitionTable, file=paste("transitions_", name ,"_", fname, ".txt", sep=""), sep=",",quote=F,row.names=T,col.names=NA)
|
|
267 write.table(x=tmp[,c("Sequence.ID", "best_match", "chunk_hit_percentage", "nt_hit_percentage", "start_locations")], file=paste("matched_", name , "_", fname, ".txt", sep=""), sep="\t",quote=F,row.names=F,col.names=T)
|
4
|
268
|
53
|
269 cat(matrx[1,x], file=paste(name, "_", fname, "_value.txt" ,sep=""))
|
78
|
270 cat(nrow(tmp), file=paste(name, "_", fname, "_n.txt" ,sep=""))
|
|
271
|
|
272 print(paste(fname, name, nrow(tmp)))
|
53
|
273
|
|
274 matrx
|
4
|
275 }
|
|
276
|
53
|
277 nts = c("a", "c", "g", "t")
|
|
278 zeros=rep(0, 4)
|
49
|
279
|
53
|
280 funcs = c(median, sum, mean)
|
|
281 fnames = c("median", "sum", "mean")
|
49
|
282
|
53
|
283 for(i in 1:length(funcs)){
|
|
284 func = funcs[[i]]
|
|
285 fname = fnames[[i]]
|
|
286
|
71
|
287 rows = 9
|
|
288 if(fname == "sum"){
|
|
289 rows = 11
|
|
290 }
|
|
291 matrx = matrix(data = 0, ncol=((length(genes) + 1) * 3),nrow=rows)
|
49
|
292
|
53
|
293 for(i in 1:length(genes)){
|
|
294 matrx = calculate_result(i, genes[i], dat, matrx, func, fname, genes[i])
|
|
295 }
|
0
|
296
|
53
|
297 matrx = calculate_result(i + 1, ".*", dat, matrx, func, fname, name="all")
|
|
298
|
|
299 result = data.frame(matrx)
|
71
|
300 if(fname == "sum"){
|
|
301 row.names(result) = c("Number of Mutations (%)", "Transition (%)", "Transversions (%)", "Transitions at G C (%)", "Targeting of C G (%)", "Transitions at A T (%)", "Targeting of A T (%)", "FR R/S (ratio)", "CDR R/S (ratio)", "nt in FR", "nt in CDR")
|
|
302 } else {
|
|
303 row.names(result) = c("Number of Mutations (%)", "Transition (%)", "Transversions (%)", "Transitions at G C (%)", "Targeting of C G (%)", "Transitions at A T (%)", "Targeting of A T (%)", "FR R/S (ratio)", "CDR R/S (ratio)")
|
|
304 }
|
53
|
305
|
|
306 write.table(x=result, file=paste("mutations_", fname, ".txt", sep=""), sep=",",quote=F,row.names=T,col.names=F)
|
4
|
307 }
|
|
308
|
|
309
|
|
310 if (!("ggplot2" %in% rownames(installed.packages()))) {
|
|
311 install.packages("ggplot2", repos="http://cran.xl-mirror.nl/")
|
|
312 }
|
49
|
313
|
4
|
314 genesForPlot = gsub("[0-9]", "", dat$best_match)
|
|
315 genesForPlot = data.frame(table(genesForPlot))
|
|
316 colnames(genesForPlot) = c("Gene","Freq")
|
|
317 genesForPlot$label = paste(genesForPlot$Gene, "-", genesForPlot$Freq)
|
26
|
318 write.table(genesForPlot, "all.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
319
|
4
|
320
|
|
321 pc = ggplot(genesForPlot, aes(x = factor(1), y=Freq, fill=label))
|
|
322 pc = pc + geom_bar(width = 1, stat = "identity")
|
|
323 pc = pc + coord_polar(theta="y")
|
26
|
324 pc = pc + xlab(" ") + ylab(" ") + ggtitle(paste("Classes", "( n =", sum(genesForPlot$Freq), ")"))
|
4
|
325
|
|
326 png(filename="all.png")
|
|
327 pc
|
|
328 dev.off()
|
|
329
|
|
330 #blegh
|
|
331 genesForPlot = dat[grepl("ca", dat$best_match),]$best_match
|
|
332 if(length(genesForPlot) > 0){
|
|
333 genesForPlot = data.frame(table(genesForPlot))
|
|
334 colnames(genesForPlot) = c("Gene","Freq")
|
|
335 genesForPlot$label = paste(genesForPlot$Gene, "-", genesForPlot$Freq)
|
|
336
|
|
337 pc = ggplot(genesForPlot, aes(x = factor(1), y=Freq, fill=label))
|
|
338 pc = pc + geom_bar(width = 1, stat = "identity")
|
|
339 pc = pc + coord_polar(theta="y")
|
26
|
340 pc = pc + xlab(" ") + ylab(" ") + ggtitle(paste("IgA subclasses", "( n =", sum(genesForPlot$Freq), ")"))
|
|
341 write.table(genesForPlot, "ca.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
4
|
342
|
|
343 png(filename="ca.png")
|
|
344 print(pc)
|
|
345 dev.off()
|
0
|
346 }
|
|
347
|
4
|
348 genesForPlot = dat[grepl("cg", dat$best_match),]$best_match
|
|
349 if(length(genesForPlot) > 0){
|
|
350 genesForPlot = data.frame(table(genesForPlot))
|
|
351 colnames(genesForPlot) = c("Gene","Freq")
|
|
352 genesForPlot$label = paste(genesForPlot$Gene, "-", genesForPlot$Freq)
|
|
353
|
|
354 pc = ggplot(genesForPlot, aes(x = factor(1), y=Freq, fill=label))
|
|
355 pc = pc + geom_bar(width = 1, stat = "identity")
|
|
356 pc = pc + coord_polar(theta="y")
|
26
|
357 pc = pc + xlab(" ") + ylab(" ") + ggtitle(paste("IgG subclasses", "( n =", sum(genesForPlot$Freq), ")"))
|
|
358 write.table(genesForPlot, "cg.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
0
|
359
|
4
|
360 png(filename="cg.png")
|
|
361 print(pc)
|
|
362 dev.off()
|
|
363 }
|
22
|
364
|
|
365 dat$percentage_mutations = round(dat$VRegionMutations / dat$VRegionNucleotides * 100, 2)
|
|
366
|
26
|
367 p = ggplot(dat, aes(best_match, percentage_mutations))
|
47
|
368 p = p + geom_point(aes(colour=best_match), position="jitter") + geom_boxplot(aes(middle=mean(percentage_mutations)), alpha=0.1, outlier.shape = NA)
|
22
|
369 p = p + xlab("Subclass") + ylab("Frequency") + ggtitle("Frequency scatter plot")
|
|
370
|
|
371 png(filename="scatter.png")
|
|
372 print(p)
|
|
373 dev.off()
|
|
374
|
49
|
375 write.table(dat[,c("Sequence.ID", "best_match", "VRegionMutations", "VRegionNucleotides", "percentage_mutations")], "scatter.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
376
|
|
377 write.table(dat, input, sep="\t",quote=F,row.names=F,col.names=T)
|
|
378
|
|
379
|
|
380
|
|
381
|
|
382
|
|
383
|
|
384 dat$best_match_class = substr(dat$best_match, 0, 2)
|
|
385 freq_labels = c("0", "0-2", "2-5", "5-10", "10-15", "15-20", "20")
|
|
386 dat$frequency_bins = cut(dat$percentage_mutations, breaks=c(-Inf, 0, 2,5,10,15,20, Inf), labels=freq_labels)
|
|
387
|
|
388 frequency_bins_data = data.frame(data.table(dat)[, list(frequency_count=.N), by=c("best_match_class", "frequency_bins")])
|
|
389
|
|
390 p = ggplot(frequency_bins_data, aes(frequency_bins, frequency_count))
|
|
391 p = p + geom_bar(aes(fill=best_match_class), stat="identity", position="dodge")
|
|
392 p = p + xlab("Frequency ranges") + ylab("Frequency") + ggtitle("Mutation Frequencies by class")
|
|
393
|
|
394 png(filename="frequency_ranges.png")
|
|
395 print(p)
|
|
396 dev.off()
|
|
397
|
|
398 frequency_bins_data_by_class = frequency_bins_data
|
|
399
|
|
400 write.table(frequency_bins_data_by_class, "frequency_ranges_classes.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
401
|
|
402 frequency_bins_data = data.frame(data.table(dat)[, list(frequency_count=.N), by=c("best_match", "frequency_bins")])
|
|
403
|
|
404 write.table(frequency_bins_data, "frequency_ranges_subclasses.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
405
|
|
406
|
|
407 #frequency_bins_data_by_class
|
|
408 #frequency_ranges_subclasses.txt
|
|
409
|
22
|
410
|
|
411
|
|
412
|
|
413
|
|
414
|
|
415
|
|
416
|
|
417
|
|
418
|
|
419
|
|
420
|
|
421
|
|
422
|
|
423
|
|
424
|
|
425
|
|
426
|
|
427
|
|
428
|
|
429
|
|
430
|
|
431
|
|
432
|
|
433
|
|
434
|
|
435
|