0
|
1 args <- commandArgs(trailingOnly = TRUE)
|
|
2
|
|
3 summ.file = args[1]
|
20
|
4 sequences.file = args[2]
|
|
5 aa.file = args[3]
|
|
6 junction.file = args[4]
|
28
|
7 gapped.aa.file = args[5]
|
|
8 out.file = args[6]
|
0
|
9
|
|
10 summ = read.table(summ.file, sep="\t", header=T, quote="", fill=T)
|
20
|
11 sequences = read.table(sequences.file, sep="\t", header=T, quote="", fill=T)
|
0
|
12 aa = read.table(aa.file, sep="\t", header=T, quote="", fill=T)
|
28
|
13 gapped.aa = read.table(gapped.aa.file, sep="\t", header=T, quote="", fill=T)
|
0
|
14 junction = read.table(junction.file, sep="\t", header=T, quote="", fill=T)
|
|
15
|
|
16 old_summary_columns=c('Sequence.ID','JUNCTION.frame','V.GENE.and.allele','D.GENE.and.allele','J.GENE.and.allele','CDR1.IMGT.length','CDR2.IMGT.length','CDR3.IMGT.length','Orientation')
|
|
17 old_sequence_columns=c('CDR1.IMGT','CDR2.IMGT','CDR3.IMGT')
|
|
18 old_junction_columns=c('JUNCTION')
|
|
19
|
|
20 added_summary_columns=c('Functionality','V.REGION.identity..','V.REGION.identity.nt','D.REGION.reading.frame','AA.JUNCTION','Functionality.comment','Sequence')
|
|
21 added_sequence_columns=c('FR1.IMGT','FR2.IMGT','FR3.IMGT','CDR3.IMGT','JUNCTION','J.REGION','FR4.IMGT')
|
|
22
|
|
23 added_junction_columns=c('P3.V.nt.nb','N.REGION.nt.nb','N1.REGION.nt.nb','P5.D.nt.nb','P3.D.nt.nb','N2.REGION.nt.nb','P5.J.nt.nb','X3.V.REGION.trimmed.nt.nb','X5.D.REGION.trimmed.nt.nb','X3.D.REGION.trimmed.nt.nb','X5.J.REGION.trimmed.nt.nb','N.REGION','N1.REGION','N2.REGION')
|
|
24 added_junction_columns=c(added_junction_columns, 'P5.D1.nt.nb', 'P3.D1.nt.nb', 'N2.REGION.nt.nb', 'P5.D2.nt.nb', 'P3.D2.nt.nb', 'N3.REGION.nt.nb', 'P5.D3.nt.nb', 'P3.D2.nt.nb', 'N4.REGION.nt.nb', 'X5.D1.REGION.trimmed.nt.nb', 'X3.D1.REGION.trimmed.nt.nb', 'X5.D2.REGION.trimmed.nt.nb', 'X3.D2.REGION.trimmed.nt.nb', 'X5.D3.REGION.trimmed.nt.nb', 'X3.D3.REGION.trimmed.nt.nb', 'D.REGION.nt.nb', 'D1.REGION.nt.nb', 'D2.REGION.nt.nb', 'D3.REGION.nt.nb')
|
|
25
|
|
26 out=summ[,c("Sequence.ID","JUNCTION.frame","V.GENE.and.allele","D.GENE.and.allele","J.GENE.and.allele")]
|
|
27
|
|
28 out[,"CDR1.Seq"] = aa[,"CDR1.IMGT"]
|
|
29 out[,"CDR1.Length"] = summ[,"CDR1.IMGT.length"]
|
|
30
|
|
31 out[,"CDR2.Seq"] = aa[,"CDR2.IMGT"]
|
|
32 out[,"CDR2.Length"] = summ[,"CDR2.IMGT.length"]
|
|
33
|
|
34 out[,"CDR3.Seq"] = aa[,"CDR3.IMGT"]
|
|
35 out[,"CDR3.Length"] = summ[,"CDR3.IMGT.length"]
|
|
36
|
28
|
37 out[,"CDR3.Seq.DNA"] = gapped.aa[,"CDR3.IMGT"]
|
|
38 out[,"CDR3.Length.DNA"] = nchar(as.character(out[,"CDR3.Seq.DNA"]))
|
0
|
39 out[,"Strand"] = summ[,"Orientation"]
|
|
40 out[,"CDR3.Found.How"] = "a"
|
|
41
|
|
42 out[,added_summary_columns] = summ[,added_summary_columns]
|
|
43
|
|
44 out[,added_sequence_columns] = aa[,added_sequence_columns]
|
|
45
|
|
46 out[,added_junction_columns] = junction[,added_junction_columns]
|
|
47
|
|
48 out[,"Top V Gene"] = gsub(".* ", "", gsub("\\*.*", "", summ[,"V.GENE.and.allele"]))
|
|
49 out[,"Top D Gene"] = gsub(".* ", "", gsub("\\*.*", "", summ[,"D.GENE.and.allele"]))
|
|
50 out[,"Top J Gene"] = gsub(".* ", "", gsub("\\*.*", "", summ[,"J.GENE.and.allele"]))
|
|
51
|
|
52 out = out[!grepl("Less than", summ[,"V.GENE.and.allele"]),]
|
|
53 out = out[!grepl("Less than", summ[,"D.GENE.and.allele"]),]
|
|
54 out = out[!grepl("Less than", summ[,"J.GENE.and.allele"]),]
|
|
55
|
|
56 out = out[,c('Sequence.ID','JUNCTION.frame','Top V Gene','Top D Gene','Top J Gene','CDR1.Seq','CDR1.Length','CDR2.Seq','CDR2.Length','CDR3.Seq','CDR3.Length','CDR3.Seq.DNA','CDR3.Length.DNA','Strand','CDR3.Found.How','Functionality','V.REGION.identity..','V.REGION.identity.nt','D.REGION.reading.frame','AA.JUNCTION','Functionality.comment','Sequence','FR1.IMGT','FR2.IMGT','FR3.IMGT','CDR3.IMGT','JUNCTION','J.REGION','FR4.IMGT','P3.V.nt.nb','N.REGION.nt.nb','N1.REGION.nt.nb','P5.D.nt.nb','P3.D.nt.nb','N2.REGION.nt.nb','P5.J.nt.nb','X3.V.REGION.trimmed.nt.nb','X5.D.REGION.trimmed.nt.nb','X3.D.REGION.trimmed.nt.nb','X5.J.REGION.trimmed.nt.nb','N.REGION','N1.REGION','N2.REGION', 'P5.D1.nt.nb', 'P3.D1.nt.nb', 'N2.REGION.nt.nb', 'P5.D2.nt.nb', 'P3.D2.nt.nb', 'N3.REGION.nt.nb', 'P5.D3.nt.nb', 'P3.D2.nt.nb', 'N4.REGION.nt.nb', 'X5.D1.REGION.trimmed.nt.nb', 'X3.D1.REGION.trimmed.nt.nb', 'X5.D2.REGION.trimmed.nt.nb', 'X3.D2.REGION.trimmed.nt.nb', 'X5.D3.REGION.trimmed.nt.nb', 'X3.D3.REGION.trimmed.nt.nb', 'D.REGION.nt.nb', 'D1.REGION.nt.nb', 'D2.REGION.nt.nb', 'D3.REGION.nt.nb')]
|
|
57
|
|
58 names(out) = c('ID','VDJ Frame','Top V Gene','Top D Gene','Top J Gene','CDR1 Seq','CDR1 Length','CDR2 Seq','CDR2 Length','CDR3 Seq','CDR3 Length','CDR3 Seq DNA','CDR3 Length DNA','Strand','CDR3 Found How','Functionality','V-REGION identity %','V-REGION identity nt','D-REGION reading frame','AA JUNCTION','Functionality comment','Sequence','FR1-IMGT','FR2-IMGT','FR3-IMGT','CDR3-IMGT','JUNCTION','J-REGION','FR4-IMGT','P3V-nt nb','N-REGION-nt nb','N1-REGION-nt nb','P5D-nt nb','P3D-nt nb','N2-REGION-nt nb','P5J-nt nb','3V-REGION trimmed-nt nb','5D-REGION trimmed-nt nb','3D-REGION trimmed-nt nb','5J-REGION trimmed-nt nb','N-REGION','N1-REGION','N2-REGION', 'P5.D1.nt.nb', 'P3.D1.nt.nb', 'N2.REGION.nt.nb', 'P5.D2.nt.nb', 'P3.D2.nt.nb', 'N3.REGION.nt.nb', 'P5.D3.nt.nb', 'P3.D2.nt.nb', 'N4.REGION.nt.nb', 'X5.D1.REGION.trimmed.nt.nb', 'X3.D1.REGION.trimmed.nt.nb', 'X5.D2.REGION.trimmed.nt.nb', 'X3.D2.REGION.trimmed.nt.nb', 'X5.D3.REGION.trimmed.nt.nb', 'X3.D3.REGION.trimmed.nt.nb', 'D.REGION.nt.nb', 'D1.REGION.nt.nb', 'D2.REGION.nt.nb', 'D3.REGION.nt.nb')
|
|
59
|
|
60 out[,"VDJ Frame"] = as.character(out[,"VDJ Frame"])
|
|
61
|
|
62 fltr = out[,"VDJ Frame"] == "in-frame"
|
|
63 if(any(fltr)){
|
|
64 out[fltr, "VDJ Frame"] = "In-frame"
|
|
65 }
|
|
66
|
|
67 fltr = out[,"VDJ Frame"] == "null"
|
|
68 if(any(fltr)){
|
|
69 out[fltr, "VDJ Frame"] = "Out-of-frame"
|
|
70 }
|
|
71
|
|
72 fltr = out[,"VDJ Frame"] == "out-of-frame"
|
|
73 if(any(fltr)){
|
|
74 out[fltr, "VDJ Frame"] = "Out-of-frame"
|
|
75 }
|
|
76
|
|
77 fltr = out[,"VDJ Frame"] == ""
|
|
78 if(any(fltr)){
|
|
79 out[fltr, "VDJ Frame"] = "Out-of-frame"
|
|
80 }
|
|
81
|
|
82 for(col in c('Top V Gene','Top D Gene','Top J Gene')){
|
|
83 out[,col] = as.character(out[,col])
|
|
84 fltr = out[,col] == ""
|
|
85 fltr[is.na(fltr)] = T
|
|
86 if(any(fltr)){
|
|
87 out[fltr,col] = "NA"
|
|
88 }
|
|
89 }
|
|
90
|
|
91 write.table(out, out.file, sep="\t", quote=F, row.names=F, col.names=T)
|