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="")
|
94
|
125 dat$FR3.IMGT.Nb.of.nucleotides = nchar(dat$FR3.IMGT.seq)
|
22
|
126 dat$VRegionNucleotides = apply(dat, FUN=sum_by_row, 1, columns=VRegionNucleotides_columns)
|
|
127
|
|
128 transitionMutations_columns = paste(rep(regions, each=4), c(".IMGT.a.g", ".IMGT.g.a", ".IMGT.c.t", ".IMGT.t.c"), sep="")
|
|
129 dat$transitionMutations = apply(dat, FUN=sum_by_row, 1, columns=transitionMutations_columns)
|
|
130
|
|
131 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="")
|
|
132 dat$transversionMutations = apply(dat, FUN=sum_by_row, 1, columns=transversionMutations_columns)
|
0
|
133
|
|
134
|
22
|
135 transitionMutationsAtGC_columns = paste(rep(regions, each=2), c(".IMGT.g.a",".IMGT.c.t"), sep="")
|
|
136 dat$transitionMutationsAtGC = apply(dat, FUN=sum_by_row, 1, columns=transitionMutationsAtGC_columns)
|
0
|
137
|
49
|
138
|
|
139 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="")
|
|
140 #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
|
141 dat$totalMutationsAtGC = apply(dat, FUN=sum_by_row, 1, columns=totalMutationsAtGC_columns)
|
0
|
142
|
49
|
143 transitionMutationsAtAT_columns = paste(rep(regions, each=2), c(".IMGT.a.g",".IMGT.t.c"), sep="")
|
|
144 dat$transitionMutationsAtAT = apply(dat, FUN=sum_by_row, 1, columns=transitionMutationsAtAT_columns)
|
|
145
|
|
146 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="")
|
|
147 #totalMutationsAtAT_columns = paste(rep(regions, each=5), c(".IMGT.a.g",".IMGT.t.c",".IMGT.a.c",".IMGT.g.c",".IMGT.t.g"), sep="")
|
|
148 dat$totalMutationsAtAT = apply(dat, FUN=sum_by_row, 1, columns=totalMutationsAtAT_columns)
|
|
149
|
|
150
|
24
|
151 FRRegions = regions[grepl("FR", regions)]
|
|
152 CDRRegions = regions[grepl("CDR", regions)]
|
|
153
|
|
154 FR_silentMutations_columns = paste(FRRegions, ".IMGT.Nb.of.silent.mutations", sep="")
|
|
155 dat$silentMutationsFR = apply(dat, FUN=sum_by_row, 1, columns=FR_silentMutations_columns)
|
23
|
156
|
24
|
157 CDR_silentMutations_columns = paste(CDRRegions, ".IMGT.Nb.of.silent.mutations", sep="")
|
|
158 dat$silentMutationsCDR = apply(dat, FUN=sum_by_row, 1, columns=CDR_silentMutations_columns)
|
|
159
|
|
160 FR_nonSilentMutations_columns = paste(FRRegions, ".IMGT.Nb.of.nonsilent.mutations", sep="")
|
|
161 dat$nonSilentMutationsFR = apply(dat, FUN=sum_by_row, 1, columns=FR_nonSilentMutations_columns)
|
|
162
|
|
163 CDR_nonSilentMutations_columns = paste(CDRRegions, ".IMGT.Nb.of.nonsilent.mutations", sep="")
|
|
164 dat$nonSilentMutationsCDR = apply(dat, FUN=sum_by_row, 1, columns=CDR_nonSilentMutations_columns)
|
0
|
165
|
49
|
166 mutation.sum.columns = c("Sequence.ID", "VRegionMutations", "VRegionNucleotides", "transitionMutations", "transversionMutations", "transitionMutationsAtGC", "transitionMutationsAtAT", "silentMutationsFR", "nonSilentMutationsFR", "silentMutationsCDR", "nonSilentMutationsCDR")
|
40
|
167
|
|
168 write.table(dat[,mutation.sum.columns], "mutation_by_id.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
0
|
169
|
4
|
170 setwd(outputdir)
|
|
171
|
53
|
172 calculate_result = function(i, gene, dat, matrx, f, fname, name){
|
78
|
173 tmp = dat[grepl(paste("^", gene, ".*", sep=""), dat$best_match),]
|
68
|
174
|
|
175 j = i - 1
|
|
176 x = (j * 3) + 1
|
|
177 y = (j * 3) + 2
|
|
178 z = (j * 3) + 3
|
|
179
|
|
180 if(nrow(tmp) > 0){
|
53
|
181
|
68
|
182 if(fname == "sum"){
|
|
183 matrx[1,x] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
184 matrx[1,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
185 matrx[1,z] = round(f(matrx[1,x] / matrx[1,y]) * 100, digits=1)
|
|
186 } else {
|
|
187 matrx[1,x] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
188 matrx[1,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
189 matrx[1,z] = round(f(tmp$VRegionMutations / tmp$VRegionNucleotides) * 100, digits=1)
|
|
190 }
|
53
|
191
|
|
192 matrx[2,x] = round(f(tmp$transitionMutations, na.rm=T), digits=1)
|
|
193 matrx[2,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
194 matrx[2,z] = round(matrx[2,x] / matrx[2,y] * 100, digits=1)
|
|
195
|
|
196 matrx[3,x] = round(f(tmp$transversionMutations, na.rm=T), digits=1)
|
|
197 matrx[3,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
198 matrx[3,z] = round(matrx[3,x] / matrx[3,y] * 100, digits=1)
|
|
199
|
|
200 matrx[4,x] = round(f(tmp$transitionMutationsAtGC, na.rm=T), digits=1)
|
|
201 matrx[4,y] = round(f(tmp$totalMutationsAtGC, na.rm=T), digits=1)
|
|
202 matrx[4,z] = round(matrx[4,x] / matrx[4,y] * 100, digits=1)
|
|
203
|
|
204 matrx[5,x] = round(f(tmp$totalMutationsAtGC, na.rm=T), digits=1)
|
|
205 matrx[5,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
206 matrx[5,z] = round(matrx[5,x] / matrx[5,y] * 100, digits=1)
|
|
207
|
|
208 matrx[6,x] = round(f(tmp$transitionMutationsAtAT, na.rm=T), digits=1)
|
|
209 matrx[6,y] = round(f(tmp$totalMutationsAtAT, na.rm=T), digits=1)
|
|
210 matrx[6,z] = round(matrx[6,x] / matrx[6,y] * 100, digits=1)
|
|
211
|
|
212 matrx[7,x] = round(f(tmp$totalMutationsAtAT, na.rm=T), digits=1)
|
|
213 matrx[7,y] = round(f(tmp$VRegionMutations, na.rm=T), digits=1)
|
|
214 matrx[7,z] = round(matrx[7,x] / matrx[7,y] * 100, digits=1)
|
|
215
|
|
216 matrx[8,x] = round(f(tmp$nonSilentMutationsFR, na.rm=T), digits=1)
|
|
217 matrx[8,y] = round(f(tmp$silentMutationsFR, na.rm=T), digits=1)
|
|
218 matrx[8,z] = round(matrx[8,x] / matrx[8,y], digits=1)
|
|
219
|
|
220 matrx[9,x] = round(f(tmp$nonSilentMutationsCDR, na.rm=T), digits=1)
|
|
221 matrx[9,y] = round(f(tmp$silentMutationsCDR, na.rm=T), digits=1)
|
|
222 matrx[9,z] = round(matrx[9,x] / matrx[9,y], digits=1)
|
71
|
223
|
|
224 if(fname == "sum"){
|
|
225 matrx[10,x] = round(f(rowSums(tmp[,c("FR2.IMGT.Nb.of.nucleotides", "FR3.IMGT.Nb.of.nucleotides")], na.rm=T)), digits=1)
|
|
226 matrx[10,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
227 matrx[10,z] = round(matrx[10,x] / matrx[10,y], digits=1)
|
|
228
|
72
|
229 matrx[11,x] = round(f(rowSums(tmp[,c("CDR1.IMGT.Nb.of.nucleotides", "CDR2.IMGT.Nb.of.nucleotides")], na.rm=T)), digits=1)
|
71
|
230 matrx[11,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
|
|
231 matrx[11,z] = round(matrx[11,x] / matrx[11,y], digits=1)
|
|
232 }
|
53
|
233 }
|
4
|
234
|
22
|
235 transitionTable = data.frame(A=zeros,C=zeros,G=zeros,T=zeros)
|
4
|
236 row.names(transitionTable) = c("A", "C", "G", "T")
|
|
237 transitionTable["A","A"] = NA
|
|
238 transitionTable["C","C"] = NA
|
|
239 transitionTable["G","G"] = NA
|
|
240 transitionTable["T","T"] = NA
|
22
|
241
|
|
242 if(nrow(tmp) > 0){
|
|
243 for(nt1 in nts){
|
|
244 for(nt2 in nts){
|
|
245 if(nt1 == nt2){
|
|
246 next
|
|
247 }
|
|
248 NT1 = LETTERS[letters == nt1]
|
|
249 NT2 = LETTERS[letters == nt2]
|
|
250 FR1 = paste("FR1.IMGT.", nt1, ".", nt2, sep="")
|
|
251 CDR1 = paste("CDR1.IMGT.", nt1, ".", nt2, sep="")
|
|
252 FR2 = paste("FR2.IMGT.", nt1, ".", nt2, sep="")
|
|
253 CDR2 = paste("CDR2.IMGT.", nt1, ".", nt2, sep="")
|
|
254 FR3 = paste("FR3.IMGT.", nt1, ".", nt2, sep="")
|
|
255 if(include_fr1){
|
|
256 transitionTable[NT1,NT2] = sum(tmp[,c(FR1, CDR1, FR2, CDR2, FR3)])
|
|
257 } else {
|
|
258 transitionTable[NT1,NT2] = sum(tmp[,c(CDR1, FR2, CDR2, FR3)])
|
|
259 }
|
|
260 }
|
|
261 }
|
|
262 }
|
4
|
263
|
|
264
|
53
|
265 print(paste("writing value file: ", name, "_", fname, "_value.txt" ,sep=""))
|
|
266
|
|
267 write.table(x=transitionTable, file=paste("transitions_", name ,"_", fname, ".txt", sep=""), sep=",",quote=F,row.names=T,col.names=NA)
|
|
268 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
|
269
|
53
|
270 cat(matrx[1,x], file=paste(name, "_", fname, "_value.txt" ,sep=""))
|
78
|
271 cat(nrow(tmp), file=paste(name, "_", fname, "_n.txt" ,sep=""))
|
|
272
|
|
273 print(paste(fname, name, nrow(tmp)))
|
53
|
274
|
|
275 matrx
|
4
|
276 }
|
|
277
|
53
|
278 nts = c("a", "c", "g", "t")
|
|
279 zeros=rep(0, 4)
|
49
|
280
|
53
|
281 funcs = c(median, sum, mean)
|
|
282 fnames = c("median", "sum", "mean")
|
49
|
283
|
53
|
284 for(i in 1:length(funcs)){
|
|
285 func = funcs[[i]]
|
|
286 fname = fnames[[i]]
|
|
287
|
71
|
288 rows = 9
|
|
289 if(fname == "sum"){
|
|
290 rows = 11
|
|
291 }
|
|
292 matrx = matrix(data = 0, ncol=((length(genes) + 1) * 3),nrow=rows)
|
49
|
293
|
53
|
294 for(i in 1:length(genes)){
|
|
295 matrx = calculate_result(i, genes[i], dat, matrx, func, fname, genes[i])
|
|
296 }
|
0
|
297
|
98
|
298 matrx = calculate_result(i + 1, ".*", dat[!grepl("unmatched", dat$best_match),], matrx, func, fname, name="all")
|
53
|
299
|
|
300 result = data.frame(matrx)
|
71
|
301 if(fname == "sum"){
|
|
302 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")
|
|
303 } else {
|
|
304 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)")
|
|
305 }
|
53
|
306
|
|
307 write.table(x=result, file=paste("mutations_", fname, ".txt", sep=""), sep=",",quote=F,row.names=T,col.names=F)
|
4
|
308 }
|
|
309
|
|
310
|
|
311 if (!("ggplot2" %in% rownames(installed.packages()))) {
|
|
312 install.packages("ggplot2", repos="http://cran.xl-mirror.nl/")
|
|
313 }
|
49
|
314
|
4
|
315 genesForPlot = gsub("[0-9]", "", dat$best_match)
|
|
316 genesForPlot = data.frame(table(genesForPlot))
|
|
317 colnames(genesForPlot) = c("Gene","Freq")
|
|
318 genesForPlot$label = paste(genesForPlot$Gene, "-", genesForPlot$Freq)
|
26
|
319 write.table(genesForPlot, "all.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
320
|
4
|
321
|
|
322 pc = ggplot(genesForPlot, aes(x = factor(1), y=Freq, fill=label))
|
|
323 pc = pc + geom_bar(width = 1, stat = "identity")
|
|
324 pc = pc + coord_polar(theta="y")
|
26
|
325 pc = pc + xlab(" ") + ylab(" ") + ggtitle(paste("Classes", "( n =", sum(genesForPlot$Freq), ")"))
|
4
|
326
|
|
327 png(filename="all.png")
|
|
328 pc
|
|
329 dev.off()
|
|
330
|
|
331 #blegh
|
|
332 genesForPlot = dat[grepl("ca", dat$best_match),]$best_match
|
|
333 if(length(genesForPlot) > 0){
|
|
334 genesForPlot = data.frame(table(genesForPlot))
|
|
335 colnames(genesForPlot) = c("Gene","Freq")
|
|
336 genesForPlot$label = paste(genesForPlot$Gene, "-", genesForPlot$Freq)
|
|
337
|
|
338 pc = ggplot(genesForPlot, aes(x = factor(1), y=Freq, fill=label))
|
|
339 pc = pc + geom_bar(width = 1, stat = "identity")
|
|
340 pc = pc + coord_polar(theta="y")
|
26
|
341 pc = pc + xlab(" ") + ylab(" ") + ggtitle(paste("IgA subclasses", "( n =", sum(genesForPlot$Freq), ")"))
|
|
342 write.table(genesForPlot, "ca.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
4
|
343
|
|
344 png(filename="ca.png")
|
|
345 print(pc)
|
|
346 dev.off()
|
0
|
347 }
|
|
348
|
4
|
349 genesForPlot = dat[grepl("cg", dat$best_match),]$best_match
|
|
350 if(length(genesForPlot) > 0){
|
|
351 genesForPlot = data.frame(table(genesForPlot))
|
|
352 colnames(genesForPlot) = c("Gene","Freq")
|
|
353 genesForPlot$label = paste(genesForPlot$Gene, "-", genesForPlot$Freq)
|
|
354
|
|
355 pc = ggplot(genesForPlot, aes(x = factor(1), y=Freq, fill=label))
|
|
356 pc = pc + geom_bar(width = 1, stat = "identity")
|
|
357 pc = pc + coord_polar(theta="y")
|
26
|
358 pc = pc + xlab(" ") + ylab(" ") + ggtitle(paste("IgG subclasses", "( n =", sum(genesForPlot$Freq), ")"))
|
|
359 write.table(genesForPlot, "cg.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
0
|
360
|
4
|
361 png(filename="cg.png")
|
|
362 print(pc)
|
|
363 dev.off()
|
|
364 }
|
22
|
365
|
|
366 dat$percentage_mutations = round(dat$VRegionMutations / dat$VRegionNucleotides * 100, 2)
|
|
367
|
26
|
368 p = ggplot(dat, aes(best_match, percentage_mutations))
|
47
|
369 p = p + geom_point(aes(colour=best_match), position="jitter") + geom_boxplot(aes(middle=mean(percentage_mutations)), alpha=0.1, outlier.shape = NA)
|
22
|
370 p = p + xlab("Subclass") + ylab("Frequency") + ggtitle("Frequency scatter plot")
|
|
371
|
|
372 png(filename="scatter.png")
|
|
373 print(p)
|
|
374 dev.off()
|
|
375
|
49
|
376 write.table(dat[,c("Sequence.ID", "best_match", "VRegionMutations", "VRegionNucleotides", "percentage_mutations")], "scatter.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
377
|
|
378 write.table(dat, input, sep="\t",quote=F,row.names=F,col.names=T)
|
|
379
|
|
380
|
|
381
|
|
382
|
|
383
|
|
384
|
|
385 dat$best_match_class = substr(dat$best_match, 0, 2)
|
|
386 freq_labels = c("0", "0-2", "2-5", "5-10", "10-15", "15-20", "20")
|
|
387 dat$frequency_bins = cut(dat$percentage_mutations, breaks=c(-Inf, 0, 2,5,10,15,20, Inf), labels=freq_labels)
|
|
388
|
|
389 frequency_bins_data = data.frame(data.table(dat)[, list(frequency_count=.N), by=c("best_match_class", "frequency_bins")])
|
|
390
|
|
391 p = ggplot(frequency_bins_data, aes(frequency_bins, frequency_count))
|
|
392 p = p + geom_bar(aes(fill=best_match_class), stat="identity", position="dodge")
|
|
393 p = p + xlab("Frequency ranges") + ylab("Frequency") + ggtitle("Mutation Frequencies by class")
|
|
394
|
|
395 png(filename="frequency_ranges.png")
|
|
396 print(p)
|
|
397 dev.off()
|
|
398
|
|
399 frequency_bins_data_by_class = frequency_bins_data
|
|
400
|
|
401 write.table(frequency_bins_data_by_class, "frequency_ranges_classes.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
402
|
|
403 frequency_bins_data = data.frame(data.table(dat)[, list(frequency_count=.N), by=c("best_match", "frequency_bins")])
|
|
404
|
|
405 write.table(frequency_bins_data, "frequency_ranges_subclasses.txt", sep="\t",quote=F,row.names=F,col.names=T)
|
|
406
|
|
407
|
|
408 #frequency_bins_data_by_class
|
|
409 #frequency_ranges_subclasses.txt
|
|
410
|
22
|
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
|
|
436
|