annotate imgt_loader.r @ 50:75ee66a691a0 draft

Uploaded
author davidvanzessen
date Mon, 15 May 2017 03:13:16 -0400
parents 64711f461c8e
children ba3220f921af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
1 args <- commandArgs(trailingOnly = TRUE)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
2
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
3 summ.file = args[1]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
4 aa.file = args[2]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
5 junction.file = args[3]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
6 out.file = args[4]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
7
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
8 summ = read.table(summ.file, sep="\t", header=T, quote="", fill=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
9 aa = read.table(aa.file, sep="\t", header=T, quote="", fill=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
10 junction = read.table(junction.file, sep="\t", header=T, quote="", fill=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
11
47
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
12 fix_column_names = function(df){
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
13 if("V.DOMAIN.Functionality" %in% names(df)){
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
14 names(df)[names(df) == "V.DOMAIN.Functionality"] = "Functionality"
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
15 print("found V.DOMAIN.Functionality, changed")
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
16 }
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
17 if("V.DOMAIN.Functionality.comment" %in% names(df)){
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
18 names(df)[names(df) == "V.DOMAIN.Functionality.comment"] = "Functionality.comment"
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
19 print("found V.DOMAIN.Functionality.comment, changed")
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
20 }
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
21 return(df)
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
22 }
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
23
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
24 summ = fix_column_names(summ)
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
25 aa = fix_column_names(aa)
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
26 junction = fix_column_names(junction)
64711f461c8e Uploaded
davidvanzessen
parents: 0
diff changeset
27
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
28 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')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
29 old_sequence_columns=c('CDR1.IMGT','CDR2.IMGT','CDR3.IMGT')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
30 old_junction_columns=c('JUNCTION')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
31
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
32 added_summary_columns=c('Functionality','V.REGION.identity..','V.REGION.identity.nt','D.REGION.reading.frame','AA.JUNCTION','Functionality.comment','Sequence')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
33 added_sequence_columns=c('FR1.IMGT','FR2.IMGT','FR3.IMGT','CDR3.IMGT','JUNCTION','J.REGION','FR4.IMGT')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
34
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
35 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')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
36 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')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
37
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
38 out=summ[,c("Sequence.ID","JUNCTION.frame","V.GENE.and.allele","D.GENE.and.allele","J.GENE.and.allele")]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
39
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
40 out[,"CDR1.Seq"] = aa[,"CDR1.IMGT"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
41 out[,"CDR1.Length"] = summ[,"CDR1.IMGT.length"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
42
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
43 out[,"CDR2.Seq"] = aa[,"CDR2.IMGT"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
44 out[,"CDR2.Length"] = summ[,"CDR2.IMGT.length"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
45
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
46 out[,"CDR3.Seq"] = aa[,"CDR3.IMGT"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
47 out[,"CDR3.Length"] = summ[,"CDR3.IMGT.length"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
48
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
49 out[,"CDR3.Seq.DNA"] = junction[,"JUNCTION"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
50 out[,"CDR3.Length.DNA"] = nchar(as.character(junction[,"JUNCTION"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
51 out[,"Strand"] = summ[,"Orientation"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
52 out[,"CDR3.Found.How"] = "a"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
53
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
54 out[,added_summary_columns] = summ[,added_summary_columns]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
55
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
56 out[,added_sequence_columns] = aa[,added_sequence_columns]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
57
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
58 out[,added_junction_columns] = junction[,added_junction_columns]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
59
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
60 out[,"Top V Gene"] = gsub(".* ", "", gsub("\\*.*", "", summ[,"V.GENE.and.allele"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
61 out[,"Top D Gene"] = gsub(".* ", "", gsub("\\*.*", "", summ[,"D.GENE.and.allele"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
62 out[,"Top J Gene"] = gsub(".* ", "", gsub("\\*.*", "", summ[,"J.GENE.and.allele"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
63
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
64 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')]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
65
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
66 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')
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
67
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
68 out[,"VDJ Frame"] = as.character(out[,"VDJ Frame"])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
69
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
70 fltr = out[,"VDJ Frame"] == "in-frame"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
71 if(any(fltr)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
72 out[fltr, "VDJ Frame"] = "In-frame"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
73 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
74
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
75 fltr = out[,"VDJ Frame"] == "null"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
76 if(any(fltr)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
77 out[fltr, "VDJ Frame"] = "Out-of-frame"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
78 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
79
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
80 fltr = out[,"VDJ Frame"] == "out-of-frame"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
81 if(any(fltr)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
82 out[fltr, "VDJ Frame"] = "Out-of-frame"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
83 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
84
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
85 fltr = out[,"VDJ Frame"] == ""
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
86 if(any(fltr)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
87 out[fltr, "VDJ Frame"] = "Out-of-frame"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
88 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
89
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
90 for(col in c('Top V Gene','Top D Gene','Top J Gene')){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
91 out[,col] = as.character(out[,col])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
92 fltr = out[,col] == ""
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
93 if(any(fltr)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
94 out[fltr,col] = "NA"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
95 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
96 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
97
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
98 write.table(out, out.file, sep="\t", quote=F, row.names=F, col.names=T)