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