12
|
1 # ---------------------- load/install packages ----------------------
|
|
2
|
|
3 if (!("gridExtra" %in% rownames(installed.packages()))) {
|
|
4 install.packages("gridExtra", repos="http://cran.xl-mirror.nl/")
|
|
5 }
|
|
6 library(gridExtra)
|
|
7 if (!("ggplot2" %in% rownames(installed.packages()))) {
|
|
8 install.packages("ggplot2", repos="http://cran.xl-mirror.nl/")
|
|
9 }
|
|
10 library(ggplot2)
|
|
11 if (!("plyr" %in% rownames(installed.packages()))) {
|
|
12 install.packages("plyr", repos="http://cran.xl-mirror.nl/")
|
|
13 }
|
|
14 library(plyr)
|
|
15
|
|
16 if (!("data.table" %in% rownames(installed.packages()))) {
|
|
17 install.packages("data.table", repos="http://cran.xl-mirror.nl/")
|
|
18 }
|
|
19 library(data.table)
|
|
20
|
|
21 if (!("reshape2" %in% rownames(installed.packages()))) {
|
|
22 install.packages("reshape2", repos="http://cran.xl-mirror.nl/")
|
|
23 }
|
|
24 library(reshape2)
|
|
25
|
|
26 if (!("lymphclon" %in% rownames(installed.packages()))) {
|
|
27 install.packages("lymphclon", repos="http://cran.xl-mirror.nl/")
|
|
28 }
|
|
29 library(lymphclon)
|
|
30
|
|
31 # ---------------------- parameters ----------------------
|
|
32
|
|
33 args <- commandArgs(trailingOnly = TRUE)
|
|
34
|
|
35 infile = args[1] #path to input file
|
|
36 outfile = args[2] #path to output file
|
|
37 outdir = args[3] #path to output folder (html/images/data)
|
|
38 clonaltype = args[4] #clonaltype definition, or 'none' for no unique filtering
|
|
39 ct = unlist(strsplit(clonaltype, ","))
|
|
40 species = args[5] #human or mouse
|
|
41 locus = args[6] # IGH, IGK, IGL, TRB, TRA, TRG or TRD
|
|
42 filterproductive = ifelse(args[7] == "yes", T, F) #should unproductive sequences be filtered out? (yes/no)
|
|
43 clonality_method = args[8]
|
|
44
|
|
45 # ---------------------- Data preperation ----------------------
|
|
46
|
18
|
47 print("Report Clonality - Data preperation")
|
|
48
|
12
|
49 inputdata = read.table(infile, sep="\t", header=TRUE, fill=T, comment.char="")
|
|
50
|
|
51 setwd(outdir)
|
|
52
|
|
53 # remove weird rows
|
|
54 inputdata = inputdata[inputdata$Sample != "",]
|
|
55
|
|
56 #remove the allele from the V,D and J genes
|
|
57 inputdata$Top.V.Gene = gsub("[*]([0-9]+)", "", inputdata$Top.V.Gene)
|
|
58 inputdata$Top.D.Gene = gsub("[*]([0-9]+)", "", inputdata$Top.D.Gene)
|
|
59 inputdata$Top.J.Gene = gsub("[*]([0-9]+)", "", inputdata$Top.J.Gene)
|
|
60
|
|
61 inputdata$clonaltype = 1:nrow(inputdata)
|
|
62
|
|
63 PRODF = inputdata
|
|
64 UNPROD = inputdata
|
|
65 if(filterproductive){
|
|
66 if("Functionality" %in% colnames(inputdata)) { # "Functionality" is an IMGT column
|
|
67 PRODF = inputdata[inputdata$Functionality == "productive" | inputdata$Functionality == "productive (see comment)", ]
|
|
68 UNPROD = inputdata[!(inputdata$Functionality == "productive" | inputdata$Functionality == "productive (see comment)"), ]
|
|
69 } else {
|
|
70 PRODF = inputdata[inputdata$VDJ.Frame != "In-frame with stop codon" & inputdata$VDJ.Frame != "Out-of-frame" & inputdata$CDR3.Found.How != "NOT_FOUND" , ]
|
|
71 UNPROD = inputdata[!(inputdata$VDJ.Frame != "In-frame with stop codon" & inputdata$VDJ.Frame != "Out-of-frame" & inputdata$CDR3.Found.How != "NOT_FOUND" ), ]
|
|
72 }
|
|
73 }
|
|
74
|
|
75 clonalityFrame = PRODF
|
|
76
|
|
77 #remove duplicates based on the clonaltype
|
|
78 if(clonaltype != "none"){
|
|
79 clonaltype = paste(clonaltype, ",Sample", sep="") #add sample column to clonaltype, unique within samples
|
|
80 PRODF$clonaltype = do.call(paste, c(PRODF[unlist(strsplit(clonaltype, ","))], sep = ":"))
|
|
81 PRODF = PRODF[!duplicated(PRODF$clonaltype), ]
|
|
82
|
|
83 UNPROD$clonaltype = do.call(paste, c(UNPROD[unlist(strsplit(clonaltype, ","))], sep = ":"))
|
|
84 UNPROD = UNPROD[!duplicated(UNPROD$clonaltype), ]
|
|
85
|
|
86 #again for clonalityFrame but with sample+replicate
|
|
87 clonalityFrame$clonaltype = do.call(paste, c(clonalityFrame[unlist(strsplit(clonaltype, ","))], sep = ":"))
|
|
88 clonalityFrame$clonality_clonaltype = do.call(paste, c(clonalityFrame[unlist(strsplit(paste(clonaltype, ",Replicate", sep=""), ","))], sep = ":"))
|
|
89 clonalityFrame = clonalityFrame[!duplicated(clonalityFrame$clonality_clonaltype), ]
|
|
90 }
|
|
91
|
|
92 PRODF$freq = 1
|
|
93
|
|
94 if(any(grepl(pattern="_", x=PRODF$ID))){ #the frequency can be stored in the ID with the pattern ".*_freq_.*"
|
|
95 PRODF$freq = gsub("^[0-9]+_", "", PRODF$ID)
|
|
96 PRODF$freq = gsub("_.*", "", PRODF$freq)
|
|
97 PRODF$freq = as.numeric(PRODF$freq)
|
|
98 if(any(is.na(PRODF$freq))){ #if there was an "_" in the ID, but not the frequency, go back to frequency of 1 for every sequence
|
|
99 PRODF$freq = 1
|
|
100 }
|
|
101 }
|
|
102
|
|
103
|
|
104
|
|
105 #write the complete dataset that is left over, will be the input if 'none' for clonaltype and 'no' for filterproductive
|
|
106 write.table(PRODF, "allUnique.txt", sep=",",quote=F,row.names=F,col.names=T)
|
|
107 write.table(PRODF, "allUnique.csv", sep="\t",quote=F,row.names=F,col.names=T)
|
|
108 write.table(UNPROD, "allUnproductive.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
109
|
|
110 #write the samples to a file
|
|
111 sampleFile <- file("samples.txt")
|
|
112 un = unique(inputdata$Sample)
|
|
113 un = paste(un, sep="\n")
|
|
114 writeLines(un, sampleFile)
|
|
115 close(sampleFile)
|
|
116
|
|
117 # ---------------------- Counting the productive/unproductive and unique sequences ----------------------
|
|
118
|
18
|
119 print("Report Clonality - counting productive/unproductive/unique")
|
|
120
|
13
|
121 if(!("Functionality" %in% inputdata)){ #add a functionality column to the igblast data
|
|
122 inputdata$Functionality = "unproductive"
|
|
123 search = (inputdata$VDJ.Frame != "In-frame with stop codon" & inputdata$VDJ.Frame != "Out-of-frame" & inputdata$CDR3.Found.How != "NOT_FOUND")
|
|
124 if(sum(search) > 0){
|
|
125 inputdata[search,]$Functionality = "productive"
|
|
126 }
|
|
127 }
|
|
128
|
12
|
129 inputdata.dt = data.table(inputdata) #for speed
|
|
130
|
|
131 if(clonaltype == "none"){
|
|
132 ct = c("clonaltype")
|
|
133 }
|
|
134
|
|
135 inputdata.dt$samples_replicates = paste(inputdata.dt$Sample, inputdata.dt$Replicate, sep="_")
|
|
136 samples_replicates = c(unique(inputdata.dt$samples_replicates), unique(as.character(inputdata.dt$Sample)))
|
|
137 frequency_table = data.frame(ID = samples_replicates[order(samples_replicates)])
|
|
138
|
|
139
|
|
140 sample_productive_count = inputdata.dt[, list(All=.N,
|
|
141 Productive = nrow(.SD[.SD$Functionality == "productive" | .SD$Functionality == "productive (see comment)",]),
|
|
142 perc_prod = 1,
|
|
143 Productive_unique = nrow(.SD[.SD$Functionality == "productive" | .SD$Functionality == "productive (see comment)",list(count=.N),by=ct]),
|
|
144 perc_prod_un = 1,
|
|
145 Unproductive= nrow(.SD[.SD$Functionality != "productive" & .SD$Functionality != "productive (see comment)",]),
|
|
146 perc_unprod = 1,
|
|
147 Unproductive_unique =nrow(.SD[.SD$Functionality != "productive" & .SD$Functionality != "productive (see comment)",list(count=.N),by=ct]),
|
|
148 perc_unprod_un = 1),
|
|
149 by=c("Sample")]
|
|
150
|
|
151 sample_productive_count$perc_prod = round(sample_productive_count$Productive / sample_productive_count$All * 100)
|
|
152 sample_productive_count$perc_prod_un = round(sample_productive_count$Productive_unique / sample_productive_count$All * 100)
|
|
153
|
|
154 sample_productive_count$perc_unprod = round(sample_productive_count$Unproductive / sample_productive_count$All * 100)
|
|
155 sample_productive_count$perc_unprod_un = round(sample_productive_count$Unproductive_unique / sample_productive_count$All * 100)
|
|
156
|
|
157
|
|
158 sample_replicate_productive_count = inputdata.dt[, list(All=.N,
|
|
159 Productive = nrow(.SD[.SD$Functionality == "productive" | .SD$Functionality == "productive (see comment)",]),
|
|
160 perc_prod = 1,
|
|
161 Productive_unique = nrow(.SD[.SD$Functionality == "productive" | .SD$Functionality == "productive (see comment)",list(count=.N),by=ct]),
|
|
162 perc_prod_un = 1,
|
|
163 Unproductive= nrow(.SD[.SD$Functionality != "productive" & .SD$Functionality != "productive (see comment)",]),
|
|
164 perc_unprod = 1,
|
|
165 Unproductive_unique =nrow(.SD[.SD$Functionality != "productive" & .SD$Functionality != "productive (see comment)",list(count=.N),by=ct]),
|
|
166 perc_unprod_un = 1),
|
|
167 by=c("samples_replicates")]
|
|
168
|
|
169 sample_replicate_productive_count$perc_prod = round(sample_replicate_productive_count$Productive / sample_replicate_productive_count$All * 100)
|
|
170 sample_replicate_productive_count$perc_prod_un = round(sample_replicate_productive_count$Productive_unique / sample_replicate_productive_count$All * 100)
|
|
171
|
|
172 sample_replicate_productive_count$perc_unprod = round(sample_replicate_productive_count$Unproductive / sample_replicate_productive_count$All * 100)
|
|
173 sample_replicate_productive_count$perc_unprod_un = round(sample_replicate_productive_count$Unproductive_unique / sample_replicate_productive_count$All * 100)
|
|
174
|
|
175 setnames(sample_replicate_productive_count, colnames(sample_productive_count))
|
|
176
|
|
177 counts = rbind(sample_replicate_productive_count, sample_productive_count)
|
|
178 counts = counts[order(counts$Sample),]
|
|
179
|
|
180 write.table(x=counts, file="productive_counting.txt", sep=",",quote=F,row.names=F,col.names=F)
|
|
181
|
|
182 # ---------------------- Frequency calculation for V, D and J ----------------------
|
|
183
|
18
|
184 print("Report Clonality - frequency calculation V, D and J")
|
|
185
|
12
|
186 PRODFV = data.frame(data.table(PRODF)[, list(Length=sum(freq)), by=c("Sample", "Top.V.Gene")])
|
|
187 Total = ddply(PRODFV, .(Sample), function(x) data.frame(Total = sum(x$Length)))
|
|
188 PRODFV = merge(PRODFV, Total, by.x='Sample', by.y='Sample', all.x=TRUE)
|
|
189 PRODFV = ddply(PRODFV, c("Sample", "Top.V.Gene"), summarise, relFreq= (Length*100 / Total))
|
|
190
|
|
191 PRODFD = data.frame(data.table(PRODF)[, list(Length=sum(freq)), by=c("Sample", "Top.D.Gene")])
|
|
192 Total = ddply(PRODFD, .(Sample), function(x) data.frame(Total = sum(x$Length)))
|
|
193 PRODFD = merge(PRODFD, Total, by.x='Sample', by.y='Sample', all.x=TRUE)
|
|
194 PRODFD = ddply(PRODFD, c("Sample", "Top.D.Gene"), summarise, relFreq= (Length*100 / Total))
|
|
195
|
|
196 PRODFJ = data.frame(data.table(PRODF)[, list(Length=sum(freq)), by=c("Sample", "Top.J.Gene")])
|
|
197 Total = ddply(PRODFJ, .(Sample), function(x) data.frame(Total = sum(x$Length)))
|
|
198 PRODFJ = merge(PRODFJ, Total, by.x='Sample', by.y='Sample', all.x=TRUE)
|
|
199 PRODFJ = ddply(PRODFJ, c("Sample", "Top.J.Gene"), summarise, relFreq= (Length*100 / Total))
|
|
200
|
|
201 # ---------------------- Setting up the gene names for the different species/loci ----------------------
|
|
202
|
18
|
203 print("Report Clonality - getting genes for species/loci")
|
|
204
|
12
|
205 Vchain = ""
|
|
206 Dchain = ""
|
|
207 Jchain = ""
|
|
208
|
|
209 if(species == "custom"){
|
|
210 print("Custom genes: ")
|
|
211 splt = unlist(strsplit(locus, ";"))
|
|
212 print(paste("V:", splt[1]))
|
|
213 print(paste("D:", splt[2]))
|
|
214 print(paste("J:", splt[3]))
|
|
215
|
|
216 Vchain = unlist(strsplit(splt[1], ","))
|
|
217 Vchain = data.frame(v.name = Vchain, chr.orderV = 1:length(Vchain))
|
|
218
|
|
219 Dchain = unlist(strsplit(splt[2], ","))
|
|
220 if(length(Dchain) > 0){
|
|
221 Dchain = data.frame(v.name = Dchain, chr.orderD = 1:length(Dchain))
|
|
222 } else {
|
|
223 Dchain = data.frame(v.name = character(0), chr.orderD = numeric(0))
|
|
224 }
|
|
225
|
|
226 Jchain = unlist(strsplit(splt[3], ","))
|
|
227 Jchain = data.frame(v.name = Jchain, chr.orderJ = 1:length(Jchain))
|
|
228
|
|
229 } else {
|
|
230 genes = read.table("genes.txt", sep="\t", header=TRUE, fill=T, comment.char="")
|
|
231
|
|
232 Vchain = genes[grepl(species, genes$Species) & genes$locus == locus & genes$region == "V",c("IMGT.GENE.DB", "chr.order")]
|
|
233 colnames(Vchain) = c("v.name", "chr.orderV")
|
|
234 Dchain = genes[grepl(species, genes$Species) & genes$locus == locus & genes$region == "D",c("IMGT.GENE.DB", "chr.order")]
|
|
235 colnames(Dchain) = c("v.name", "chr.orderD")
|
|
236 Jchain = genes[grepl(species, genes$Species) & genes$locus == locus & genes$region == "J",c("IMGT.GENE.DB", "chr.order")]
|
|
237 colnames(Jchain) = c("v.name", "chr.orderJ")
|
|
238 }
|
|
239 useD = TRUE
|
|
240 if(nrow(Dchain) == 0){
|
|
241 useD = FALSE
|
|
242 cat("No D Genes in this species/locus")
|
|
243 }
|
18
|
244 print(paste(nrow(Vchain), "genes in V"))
|
|
245 print(paste(nrow(Dchain), "genes in D"))
|
|
246 print(paste(nrow(Jchain), "genes in J"))
|
12
|
247
|
|
248 # ---------------------- merge with the frequency count ----------------------
|
|
249
|
|
250 PRODFV = merge(PRODFV, Vchain, by.x='Top.V.Gene', by.y='v.name', all.x=TRUE)
|
|
251
|
|
252 PRODFD = merge(PRODFD, Dchain, by.x='Top.D.Gene', by.y='v.name', all.x=TRUE)
|
|
253
|
|
254 PRODFJ = merge(PRODFJ, Jchain, by.x='Top.J.Gene', by.y='v.name', all.x=TRUE)
|
|
255
|
|
256 # ---------------------- Create the V, D and J frequency plots and write the data.frame for every plot to a file ----------------------
|
|
257
|
18
|
258 print("Report Clonality - V, D and J frequency plots")
|
|
259
|
12
|
260 pV = ggplot(PRODFV)
|
|
261 pV = pV + geom_bar( aes( x=factor(reorder(Top.V.Gene, chr.orderV)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1))
|
|
262 pV = pV + xlab("Summary of V gene") + ylab("Frequency") + ggtitle("Relative frequency of V gene usage")
|
|
263 write.table(x=PRODFV, file="VFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
264
|
|
265 png("VPlot.png",width = 1280, height = 720)
|
|
266 pV
|
|
267 dev.off();
|
|
268
|
|
269 if(useD){
|
|
270 pD = ggplot(PRODFD)
|
|
271 pD = pD + geom_bar( aes( x=factor(reorder(Top.D.Gene, chr.orderD)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1))
|
|
272 pD = pD + xlab("Summary of D gene") + ylab("Frequency") + ggtitle("Relative frequency of D gene usage")
|
|
273 write.table(x=PRODFD, file="DFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
274
|
|
275 png("DPlot.png",width = 800, height = 600)
|
|
276 print(pD)
|
|
277 dev.off();
|
|
278 }
|
|
279
|
|
280 pJ = ggplot(PRODFJ)
|
|
281 pJ = pJ + geom_bar( aes( x=factor(reorder(Top.J.Gene, chr.orderJ)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1))
|
|
282 pJ = pJ + xlab("Summary of J gene") + ylab("Frequency") + ggtitle("Relative frequency of J gene usage")
|
|
283 write.table(x=PRODFJ, file="JFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
284
|
|
285 png("JPlot.png",width = 800, height = 600)
|
|
286 pJ
|
|
287 dev.off();
|
|
288
|
|
289 pJ = ggplot(PRODFJ)
|
|
290 pJ = pJ + geom_bar( aes( x=factor(reorder(Top.J.Gene, chr.orderJ)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1))
|
|
291 pJ = pJ + xlab("Summary of J gene") + ylab("Frequency") + ggtitle("Relative frequency of J gene usage")
|
|
292 write.table(x=PRODFJ, file="JFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
293
|
|
294 png("JPlot.png",width = 800, height = 600)
|
|
295 pJ
|
|
296 dev.off();
|
|
297
|
|
298 # ---------------------- Now the frequency plots of the V, D and J families ----------------------
|
|
299
|
18
|
300 print("Report Clonality - V, D and J family plots")
|
|
301
|
12
|
302 VGenes = PRODF[,c("Sample", "Top.V.Gene")]
|
|
303 VGenes$Top.V.Gene = gsub("-.*", "", VGenes$Top.V.Gene)
|
|
304 VGenes = data.frame(data.table(VGenes)[, list(Count=.N), by=c("Sample", "Top.V.Gene")])
|
|
305 TotalPerSample = data.frame(data.table(VGenes)[, list(total=sum(.SD$Count)), by=Sample])
|
|
306 VGenes = merge(VGenes, TotalPerSample, by="Sample")
|
|
307 VGenes$Frequency = VGenes$Count * 100 / VGenes$total
|
|
308 VPlot = ggplot(VGenes)
|
|
309 VPlot = VPlot + geom_bar(aes( x = Top.V.Gene, y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
310 ggtitle("Distribution of V gene families") +
|
|
311 ylab("Percentage of sequences")
|
|
312 png("VFPlot.png")
|
|
313 VPlot
|
|
314 dev.off();
|
|
315 write.table(x=VGenes, file="VFFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
316
|
|
317 if(useD){
|
|
318 DGenes = PRODF[,c("Sample", "Top.D.Gene")]
|
|
319 DGenes$Top.D.Gene = gsub("-.*", "", DGenes$Top.D.Gene)
|
|
320 DGenes = data.frame(data.table(DGenes)[, list(Count=.N), by=c("Sample", "Top.D.Gene")])
|
|
321 TotalPerSample = data.frame(data.table(DGenes)[, list(total=sum(.SD$Count)), by=Sample])
|
|
322 DGenes = merge(DGenes, TotalPerSample, by="Sample")
|
|
323 DGenes$Frequency = DGenes$Count * 100 / DGenes$total
|
|
324 DPlot = ggplot(DGenes)
|
|
325 DPlot = DPlot + geom_bar(aes( x = Top.D.Gene, y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
326 ggtitle("Distribution of D gene families") +
|
|
327 ylab("Percentage of sequences")
|
|
328 png("DFPlot.png")
|
|
329 print(DPlot)
|
|
330 dev.off();
|
|
331 write.table(x=DGenes, file="DFFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
332 }
|
|
333
|
|
334 JGenes = PRODF[,c("Sample", "Top.J.Gene")]
|
|
335 JGenes$Top.J.Gene = gsub("-.*", "", JGenes$Top.J.Gene)
|
|
336 JGenes = data.frame(data.table(JGenes)[, list(Count=.N), by=c("Sample", "Top.J.Gene")])
|
|
337 TotalPerSample = data.frame(data.table(JGenes)[, list(total=sum(.SD$Count)), by=Sample])
|
|
338 JGenes = merge(JGenes, TotalPerSample, by="Sample")
|
|
339 JGenes$Frequency = JGenes$Count * 100 / JGenes$total
|
|
340 JPlot = ggplot(JGenes)
|
|
341 JPlot = JPlot + geom_bar(aes( x = Top.J.Gene, y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
342 ggtitle("Distribution of J gene families") +
|
|
343 ylab("Percentage of sequences")
|
|
344 png("JFPlot.png")
|
|
345 JPlot
|
|
346 dev.off();
|
|
347 write.table(x=JGenes, file="JFFrequency.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
348
|
|
349 # ---------------------- Plotting the cdr3 length ----------------------
|
|
350
|
18
|
351 print("Report Clonality - CDR3 length plot")
|
|
352
|
12
|
353 CDR3Length = data.frame(data.table(PRODF)[, list(Count=.N), by=c("Sample", "CDR3.Length.DNA")])
|
|
354 TotalPerSample = data.frame(data.table(CDR3Length)[, list(total=sum(.SD$Count)), by=Sample])
|
|
355 CDR3Length = merge(CDR3Length, TotalPerSample, by="Sample")
|
|
356 CDR3Length$Frequency = CDR3Length$Count * 100 / CDR3Length$total
|
|
357 CDR3LengthPlot = ggplot(CDR3Length)
|
|
358 CDR3LengthPlot = CDR3LengthPlot + geom_bar(aes( x = CDR3.Length.DNA, y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
359 ggtitle("Length distribution of CDR3") +
|
|
360 xlab("CDR3 Length") +
|
|
361 ylab("Percentage of sequences")
|
|
362 png("CDR3LengthPlot.png",width = 1280, height = 720)
|
|
363 CDR3LengthPlot
|
|
364 dev.off()
|
|
365 write.table(x=CDR3Length, file="CDR3LengthPlot.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
366
|
|
367 # ---------------------- Plot the heatmaps ----------------------
|
|
368
|
|
369 #get the reverse order for the V and D genes
|
|
370 revVchain = Vchain
|
|
371 revDchain = Dchain
|
|
372 revVchain$chr.orderV = rev(revVchain$chr.orderV)
|
|
373 revDchain$chr.orderD = rev(revDchain$chr.orderD)
|
|
374
|
|
375 if(useD){
|
18
|
376 print("Report Clonality - Heatmaps VD")
|
12
|
377 plotVD <- function(dat){
|
|
378 if(length(dat[,1]) == 0){
|
|
379 return()
|
|
380 }
|
|
381 img = ggplot() +
|
|
382 geom_tile(data=dat, aes(x=factor(reorder(Top.D.Gene, chr.orderD)), y=factor(reorder(Top.V.Gene, chr.orderV)), fill=relLength)) +
|
|
383 theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
384 scale_fill_gradient(low="gold", high="blue", na.value="white") +
|
|
385 ggtitle(paste(unique(dat$Sample), " (N=" , sum(dat$Length, na.rm=T) ,")", sep="")) +
|
|
386 xlab("D genes") +
|
|
387 ylab("V Genes")
|
|
388
|
|
389 png(paste("HeatmapVD_", unique(dat[3])[1,1] , ".png", sep=""), width=150+(15*length(Dchain$v.name)), height=100+(15*length(Vchain$v.name)))
|
|
390 print(img)
|
|
391 dev.off()
|
|
392 write.table(x=acast(dat, Top.V.Gene~Top.D.Gene, value.var="Length"), file=paste("HeatmapVD_", unique(dat[3])[1,1], ".csv", sep=""), sep=",",quote=F,row.names=T,col.names=NA)
|
|
393 }
|
|
394
|
|
395 VandDCount = data.frame(data.table(PRODF)[, list(Length=.N), by=c("Top.V.Gene", "Top.D.Gene", "Sample")])
|
|
396
|
|
397 VandDCount$l = log(VandDCount$Length)
|
|
398 maxVD = data.frame(data.table(VandDCount)[, list(max=max(l)), by=c("Sample")])
|
|
399 VandDCount = merge(VandDCount, maxVD, by.x="Sample", by.y="Sample", all.x=T)
|
|
400 VandDCount$relLength = VandDCount$l / VandDCount$max
|
|
401
|
|
402 cartegianProductVD = expand.grid(Top.V.Gene = Vchain$v.name, Top.D.Gene = Dchain$v.name, Sample = unique(inputdata$Sample))
|
|
403
|
|
404 completeVD = merge(VandDCount, cartegianProductVD, all.y=TRUE)
|
|
405 completeVD = merge(completeVD, revVchain, by.x="Top.V.Gene", by.y="v.name", all.x=TRUE)
|
|
406 completeVD = merge(completeVD, Dchain, by.x="Top.D.Gene", by.y="v.name", all.x=TRUE)
|
|
407 VDList = split(completeVD, f=completeVD[,"Sample"])
|
|
408 lapply(VDList, FUN=plotVD)
|
|
409 }
|
|
410
|
18
|
411 print("Report Clonality - Heatmaps VJ")
|
|
412
|
12
|
413 plotVJ <- function(dat){
|
|
414 if(length(dat[,1]) == 0){
|
|
415 return()
|
|
416 }
|
|
417 cat(paste(unique(dat[3])[1,1]))
|
|
418 img = ggplot() +
|
|
419 geom_tile(data=dat, aes(x=factor(reorder(Top.J.Gene, chr.orderJ)), y=factor(reorder(Top.V.Gene, chr.orderV)), fill=relLength)) +
|
|
420 theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
421 scale_fill_gradient(low="gold", high="blue", na.value="white") +
|
|
422 ggtitle(paste(unique(dat$Sample), " (N=" , sum(dat$Length, na.rm=T) ,")", sep="")) +
|
|
423 xlab("J genes") +
|
|
424 ylab("V Genes")
|
|
425
|
|
426 png(paste("HeatmapVJ_", unique(dat[3])[1,1] , ".png", sep=""), width=150+(15*length(Jchain$v.name)), height=100+(15*length(Vchain$v.name)))
|
|
427 print(img)
|
|
428 dev.off()
|
|
429 write.table(x=acast(dat, Top.V.Gene~Top.J.Gene, value.var="Length"), file=paste("HeatmapVJ_", unique(dat[3])[1,1], ".csv", sep=""), sep=",",quote=F,row.names=T,col.names=NA)
|
|
430 }
|
|
431
|
|
432 VandJCount = data.frame(data.table(PRODF)[, list(Length=.N), by=c("Top.V.Gene", "Top.J.Gene", "Sample")])
|
|
433
|
|
434 VandJCount$l = log(VandJCount$Length)
|
|
435 maxVJ = data.frame(data.table(VandJCount)[, list(max=max(l)), by=c("Sample")])
|
|
436 VandJCount = merge(VandJCount, maxVJ, by.x="Sample", by.y="Sample", all.x=T)
|
|
437 VandJCount$relLength = VandJCount$l / VandJCount$max
|
|
438
|
|
439 cartegianProductVJ = expand.grid(Top.V.Gene = Vchain$v.name, Top.J.Gene = Jchain$v.name, Sample = unique(inputdata$Sample))
|
|
440
|
|
441 completeVJ = merge(VandJCount, cartegianProductVJ, all.y=TRUE)
|
|
442 completeVJ = merge(completeVJ, revVchain, by.x="Top.V.Gene", by.y="v.name", all.x=TRUE)
|
|
443 completeVJ = merge(completeVJ, Jchain, by.x="Top.J.Gene", by.y="v.name", all.x=TRUE)
|
|
444 VJList = split(completeVJ, f=completeVJ[,"Sample"])
|
|
445 lapply(VJList, FUN=plotVJ)
|
|
446
|
18
|
447
|
|
448
|
12
|
449 if(useD){
|
18
|
450 print("Report Clonality - Heatmaps DJ")
|
12
|
451 plotDJ <- function(dat){
|
|
452 if(length(dat[,1]) == 0){
|
|
453 return()
|
|
454 }
|
|
455 img = ggplot() +
|
|
456 geom_tile(data=dat, aes(x=factor(reorder(Top.J.Gene, chr.orderJ)), y=factor(reorder(Top.D.Gene, chr.orderD)), fill=relLength)) +
|
|
457 theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
|
|
458 scale_fill_gradient(low="gold", high="blue", na.value="white") +
|
|
459 ggtitle(paste(unique(dat$Sample), " (N=" , sum(dat$Length, na.rm=T) ,")", sep="")) +
|
|
460 xlab("J genes") +
|
|
461 ylab("D Genes")
|
|
462
|
|
463 png(paste("HeatmapDJ_", unique(dat[3])[1,1] , ".png", sep=""), width=150+(15*length(Jchain$v.name)), height=100+(15*length(Dchain$v.name)))
|
|
464 print(img)
|
|
465 dev.off()
|
|
466 write.table(x=acast(dat, Top.D.Gene~Top.J.Gene, value.var="Length"), file=paste("HeatmapDJ_", unique(dat[3])[1,1], ".csv", sep=""), sep=",",quote=F,row.names=T,col.names=NA)
|
|
467 }
|
|
468
|
|
469
|
|
470 DandJCount = data.frame(data.table(PRODF)[, list(Length=.N), by=c("Top.D.Gene", "Top.J.Gene", "Sample")])
|
|
471
|
|
472 DandJCount$l = log(DandJCount$Length)
|
|
473 maxDJ = data.frame(data.table(DandJCount)[, list(max=max(l)), by=c("Sample")])
|
|
474 DandJCount = merge(DandJCount, maxDJ, by.x="Sample", by.y="Sample", all.x=T)
|
|
475 DandJCount$relLength = DandJCount$l / DandJCount$max
|
|
476
|
|
477 cartegianProductDJ = expand.grid(Top.D.Gene = Dchain$v.name, Top.J.Gene = Jchain$v.name, Sample = unique(inputdata$Sample))
|
|
478
|
|
479 completeDJ = merge(DandJCount, cartegianProductDJ, all.y=TRUE)
|
|
480 completeDJ = merge(completeDJ, revDchain, by.x="Top.D.Gene", by.y="v.name", all.x=TRUE)
|
|
481 completeDJ = merge(completeDJ, Jchain, by.x="Top.J.Gene", by.y="v.name", all.x=TRUE)
|
|
482 DJList = split(completeDJ, f=completeDJ[,"Sample"])
|
|
483 lapply(DJList, FUN=plotDJ)
|
|
484 }
|
|
485
|
|
486
|
|
487 # ---------------------- calculating the clonality score ----------------------
|
|
488
|
|
489 if("Replicate" %in% colnames(inputdata)) #can only calculate clonality score when replicate information is available
|
|
490 {
|
|
491 if(clonality_method == "boyd"){
|
|
492 samples = split(clonalityFrame, clonalityFrame$Sample, drop=T)
|
|
493
|
|
494 for (sample in samples){
|
|
495 res = data.frame(paste=character(0))
|
|
496 sample_id = unique(sample$Sample)[[1]]
|
|
497 for(replicate in unique(sample$Replicate)){
|
|
498 tmp = sample[sample$Replicate == replicate,]
|
|
499 clone_table = data.frame(table(tmp$clonaltype))
|
|
500 clone_col_name = paste("V", replicate, sep="")
|
|
501 colnames(clone_table) = c("paste", clone_col_name)
|
|
502 res = merge(res, clone_table, by="paste", all=T)
|
|
503 }
|
|
504
|
|
505 res[is.na(res)] = 0
|
|
506 infer.result = infer.clonality(as.matrix(res[,2:ncol(res)]))
|
|
507
|
|
508 write.table(data.table(infer.result[[12]]), file=paste("lymphclon_clonality_", sample_id, ".csv", sep=""), sep=",",quote=F,row.names=F,col.names=F)
|
|
509
|
|
510 res$type = rowSums(res[,2:ncol(res)])
|
|
511
|
|
512 coincidence.table = data.frame(table(res$type))
|
|
513 colnames(coincidence.table) = c("Coincidence Type", "Raw Coincidence Freq")
|
|
514 write.table(coincidence.table, file=paste("lymphclon_coincidences_", sample_id, ".csv", sep=""), sep=",",quote=F,row.names=F,col.names=T)
|
|
515 }
|
|
516 } else {
|
|
517 write.table(clonalityFrame, "clonalityComplete.csv", sep=",",quote=F,row.names=F,col.names=T)
|
|
518
|
|
519 clonalFreq = data.frame(data.table(clonalityFrame)[, list(Type=.N), by=c("Sample", "clonaltype")])
|
|
520 clonalFreqCount = data.frame(data.table(clonalFreq)[, list(Count=.N), by=c("Sample", "Type")])
|
|
521 clonalFreqCount$realCount = clonalFreqCount$Type * clonalFreqCount$Count
|
|
522 clonalSum = data.frame(data.table(clonalFreqCount)[, list(Reads=sum(realCount)), by=c("Sample")])
|
|
523 clonalFreqCount = merge(clonalFreqCount, clonalSum, by.x="Sample", by.y="Sample")
|
|
524
|
|
525 ct = c('Type\tWeight\n2\t1\n3\t3\n4\t6\n5\t10\n6\t15')
|
|
526 tcct = textConnection(ct)
|
|
527 CT = read.table(tcct, sep="\t", header=TRUE)
|
|
528 close(tcct)
|
|
529 clonalFreqCount = merge(clonalFreqCount, CT, by.x="Type", by.y="Type", all.x=T)
|
|
530 clonalFreqCount$WeightedCount = clonalFreqCount$Count * clonalFreqCount$Weight
|
|
531
|
|
532 ReplicateReads = data.frame(data.table(clonalityFrame)[, list(Type=.N), by=c("Sample", "Replicate", "clonaltype")])
|
|
533 ReplicateReads = data.frame(data.table(ReplicateReads)[, list(Reads=.N), by=c("Sample", "Replicate")])
|
|
534 clonalFreqCount$Reads = as.numeric(clonalFreqCount$Reads)
|
|
535 ReplicateReads$squared = ReplicateReads$Reads * ReplicateReads$Reads
|
|
536
|
|
537 ReplicatePrint <- function(dat){
|
|
538 write.table(dat[-1], paste("ReplicateReads_", unique(dat[1])[1,1] , ".csv", sep=""), sep=",",quote=F,na="-",row.names=F,col.names=F)
|
|
539 }
|
|
540
|
|
541 ReplicateSplit = split(ReplicateReads, f=ReplicateReads[,"Sample"])
|
|
542 lapply(ReplicateSplit, FUN=ReplicatePrint)
|
|
543
|
|
544 ReplicateReads = data.frame(data.table(ReplicateReads)[, list(ReadsSum=sum(as.numeric(Reads)), ReadsSquaredSum=sum(as.numeric(squared))), by=c("Sample")])
|
|
545 clonalFreqCount = merge(clonalFreqCount, ReplicateReads, by.x="Sample", by.y="Sample", all.x=T)
|
|
546
|
|
547 ReplicateSumPrint <- function(dat){
|
|
548 write.table(dat[-1], paste("ReplicateSumReads_", unique(dat[1])[1,1] , ".csv", sep=""), sep=",",quote=F,na="-",row.names=F,col.names=F)
|
|
549 }
|
|
550
|
|
551 ReplicateSumSplit = split(ReplicateReads, f=ReplicateReads[,"Sample"])
|
|
552 lapply(ReplicateSumSplit, FUN=ReplicateSumPrint)
|
|
553
|
|
554 clonalFreqCountSum = data.frame(data.table(clonalFreqCount)[, list(Numerator=sum(WeightedCount, na.rm=T)), by=c("Sample")])
|
|
555 clonalFreqCount = merge(clonalFreqCount, clonalFreqCountSum, by.x="Sample", by.y="Sample", all.x=T)
|
|
556 clonalFreqCount$ReadsSum = as.numeric(clonalFreqCount$ReadsSum) #prevent integer overflow
|
|
557 clonalFreqCount$Denominator = (((clonalFreqCount$ReadsSum * clonalFreqCount$ReadsSum) - clonalFreqCount$ReadsSquaredSum) / 2)
|
|
558 clonalFreqCount$Result = (clonalFreqCount$Numerator + 1) / (clonalFreqCount$Denominator + 1)
|
|
559
|
|
560 ClonalityScorePrint <- function(dat){
|
|
561 write.table(dat$Result, paste("ClonalityScore_", unique(dat[1])[1,1] , ".csv", sep=""), sep=",",quote=F,na="-",row.names=F,col.names=F)
|
|
562 }
|
|
563
|
|
564 clonalityScore = clonalFreqCount[c("Sample", "Result")]
|
|
565 clonalityScore = unique(clonalityScore)
|
|
566
|
|
567 clonalityScoreSplit = split(clonalityScore, f=clonalityScore[,"Sample"])
|
|
568 lapply(clonalityScoreSplit, FUN=ClonalityScorePrint)
|
|
569
|
|
570 clonalityOverview = clonalFreqCount[c("Sample", "Type", "Count", "Weight", "WeightedCount")]
|
|
571
|
|
572
|
|
573
|
|
574 ClonalityOverviewPrint <- function(dat){
|
|
575 write.table(dat[-1], paste("ClonalityOverView_", unique(dat[1])[1,1] , ".csv", sep=""), sep=",",quote=F,na="-",row.names=F,col.names=F)
|
|
576 }
|
|
577
|
|
578 clonalityOverviewSplit = split(clonalityOverview, f=clonalityOverview$Sample)
|
|
579 lapply(clonalityOverviewSplit, FUN=ClonalityOverviewPrint)
|
|
580 }
|
|
581 }
|
|
582
|
|
583 imgtcolumns = c("X3V.REGION.trimmed.nt.nb","P3V.nt.nb", "N1.REGION.nt.nb", "P5D.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "P3D.nt.nb", "N2.REGION.nt.nb", "P5J.nt.nb", "X5J.REGION.trimmed.nt.nb", "X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb")
|
|
584 if(all(imgtcolumns %in% colnames(inputdata)))
|
|
585 {
|
17
|
586 print("found IMGT columns, running junction analysis")
|
19
|
587
|
|
588 if(locus %in% c("IGK","IGL", "TRA", "TRG")){
|
|
589 print("VJ recombination, using N column for junction analysis")
|
|
590 print(names(PRODF))
|
|
591 print(head(PRODF$N.REGION.nt.nb, 30))
|
|
592 PRODF$N1.REGION.nt.nb = PRODF$N.REGION.nt.nb
|
|
593 }
|
|
594
|
12
|
595 newData = data.frame(data.table(PRODF)[,list(unique=.N,
|
|
596 VH.DEL=mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T),
|
|
597 P1=mean(.SD$P3V.nt.nb, na.rm=T),
|
|
598 N1=mean(.SD$N1.REGION.nt.nb, na.rm=T),
|
|
599 P2=mean(.SD$P5D.nt.nb, na.rm=T),
|
|
600 DEL.DH=mean(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T),
|
|
601 DH.DEL=mean(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T),
|
|
602 P3=mean(.SD$P3D.nt.nb, na.rm=T),
|
|
603 N2=mean(.SD$N2.REGION.nt.nb, na.rm=T),
|
|
604 P4=mean(.SD$P5J.nt.nb, na.rm=T),
|
|
605 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T),
|
|
606 Total.Del=( mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T) +
|
|
607 mean(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T) +
|
|
608 mean(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T) +
|
|
609 mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T)),
|
|
610
|
|
611 Total.N=( mean(.SD$N1.REGION.nt.nb, na.rm=T) +
|
|
612 mean(.SD$N2.REGION.nt.nb, na.rm=T)),
|
|
613
|
|
614 Total.P=( mean(.SD$P3V.nt.nb, na.rm=T) +
|
|
615 mean(.SD$P5D.nt.nb, na.rm=T) +
|
|
616 mean(.SD$P3D.nt.nb, na.rm=T) +
|
|
617 mean(.SD$P5J.nt.nb, na.rm=T))),
|
|
618 by=c("Sample")])
|
16
|
619 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1)
|
12
|
620 write.table(newData, "junctionAnalysisProd.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F)
|
|
621
|
|
622 newData = data.frame(data.table(UNPROD)[,list(unique=.N,
|
|
623 VH.DEL=mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T),
|
|
624 P1=mean(.SD$P3V.nt.nb, na.rm=T),
|
|
625 N1=mean(.SD$N1.REGION.nt.nb, na.rm=T),
|
|
626 P2=mean(.SD$P5D.nt.nb, na.rm=T),
|
|
627 DEL.DH=mean(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T),
|
|
628 DH.DEL=mean(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T),
|
|
629 P3=mean(.SD$P3D.nt.nb, na.rm=T),
|
|
630 N2=mean(.SD$N2.REGION.nt.nb, na.rm=T),
|
|
631 P4=mean(.SD$P5J.nt.nb, na.rm=T),
|
|
632 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T),
|
17
|
633 Total.Del=(mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T) +
|
|
634 mean(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T) +
|
|
635 mean(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T) +
|
|
636 mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T)),
|
|
637 Total.N=( mean(.SD$N1.REGION.nt.nb, na.rm=T) +
|
|
638 mean(.SD$N2.REGION.nt.nb, na.rm=T)),
|
|
639 Total.P=( mean(.SD$P3V.nt.nb, na.rm=T) +
|
|
640 mean(.SD$P5D.nt.nb, na.rm=T) +
|
|
641 mean(.SD$P3D.nt.nb, na.rm=T) +
|
|
642 mean(.SD$P5J.nt.nb, na.rm=T))),
|
12
|
643 by=c("Sample")])
|
16
|
644 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1)
|
12
|
645 write.table(newData, "junctionAnalysisUnProd.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F)
|
|
646 }
|
|
647
|
|
648 # ---------------------- AA composition in CDR3 ----------------------
|
|
649
|
|
650 AACDR3 = PRODF[,c("Sample", "CDR3.Seq")]
|
|
651
|
|
652 TotalPerSample = data.frame(data.table(AACDR3)[, list(total=sum(nchar(as.character(.SD$CDR3.Seq)))), by=Sample])
|
|
653
|
|
654 AAfreq = list()
|
|
655
|
|
656 for(i in 1:nrow(TotalPerSample)){
|
|
657 sample = TotalPerSample$Sample[i]
|
|
658 AAfreq[[i]] = data.frame(table(unlist(strsplit(as.character(AACDR3[AACDR3$Sample == sample,c("CDR3.Seq")]), ""))))
|
|
659 AAfreq[[i]]$Sample = sample
|
|
660 }
|
|
661
|
|
662 AAfreq = ldply(AAfreq, data.frame)
|
|
663 AAfreq = merge(AAfreq, TotalPerSample, by="Sample", all.x = T)
|
|
664 AAfreq$freq_perc = as.numeric(AAfreq$Freq / AAfreq$total * 100)
|
|
665
|
|
666
|
|
667 AAorder = read.table(sep="\t", header=TRUE, text="order.aa\tAA\n1\tR\n2\tK\n3\tN\n4\tD\n5\tQ\n6\tE\n7\tH\n8\tP\n9\tY\n10\tW\n11\tS\n12\tT\n13\tG\n14\tA\n15\tM\n16\tC\n17\tF\n18\tL\n19\tV\n20\tI")
|
|
668 AAfreq = merge(AAfreq, AAorder, by.x='Var1', by.y='AA', all.x=TRUE)
|
|
669
|
|
670 AAfreq = AAfreq[!is.na(AAfreq$order.aa),]
|
|
671
|
|
672 AAfreqplot = ggplot(AAfreq)
|
|
673 AAfreqplot = AAfreqplot + geom_bar(aes( x=factor(reorder(Var1, order.aa)), y = freq_perc, fill = Sample), stat='identity', position='dodge' )
|
|
674 AAfreqplot = AAfreqplot + annotate("rect", xmin = 0.5, xmax = 2.5, ymin = 0, ymax = Inf, fill = "red", alpha = 0.2)
|
|
675 AAfreqplot = AAfreqplot + annotate("rect", xmin = 3.5, xmax = 4.5, ymin = 0, ymax = Inf, fill = "blue", alpha = 0.2)
|
|
676 AAfreqplot = AAfreqplot + annotate("rect", xmin = 5.5, xmax = 6.5, ymin = 0, ymax = Inf, fill = "blue", alpha = 0.2)
|
|
677 AAfreqplot = AAfreqplot + annotate("rect", xmin = 6.5, xmax = 7.5, ymin = 0, ymax = Inf, fill = "red", alpha = 0.2)
|
|
678 AAfreqplot = AAfreqplot + ggtitle("Amino Acid Composition in the CDR3") + xlab("Amino Acid, from Hydrophilic (left) to Hydrophobic (right)") + ylab("Percentage")
|
|
679
|
|
680 png("AAComposition.png",width = 1280, height = 720)
|
|
681 AAfreqplot
|
|
682 dev.off()
|
|
683 write.table(AAfreq, "AAComposition.csv" , sep=",",quote=F,na="-",row.names=F,col.names=T)
|
|
684
|
|
685
|