annotate sequence_overview.r @ 33:22fabe161cf3 draft

Uploaded
author davidvanzessen
date Thu, 15 Dec 2016 09:44:17 -0500
parents 4c5ba6b5d10d
children a24f8c93583a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
1 library(reshape2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
2
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
3 args <- commandArgs(trailingOnly = TRUE)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
4
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
5 before.unique.file = args[1]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
6 merged.file = args[2]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
7 outputdir = args[3]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
8 gene.classes = unlist(strsplit(args[4], ","))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
9 hotspot.analysis.sum.file = args[5]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
10 NToverview.file = paste(outputdir, "ntoverview.txt", sep="/")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
11 NTsum.file = paste(outputdir, "ntsum.txt", sep="/")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
12 main.html = "index.html"
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
13 empty.region.filter = args[6]
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
14
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
15
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
16 setwd(outputdir)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
17
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
18 before.unique = read.table(before.unique.file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
19 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
20 hotspot.analysis.sum = read.table(hotspot.analysis.sum.file, header=F, sep=",", fill=T, stringsAsFactors=F, quote="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
21
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
22 #before.unique = before.unique[!grepl("unmatched", before.unique$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
23
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
24 if(empty.region.filter == "leader"){
31
fe44a905aee9 Uploaded
davidvanzessen
parents: 8
diff changeset
25 before.unique$seq_conc = paste(before.unique$FR1.IMGT.seq, before.unique$CDR1.IMGT.seq, before.unique$FR2.IMGT.seq, before.unique$CDR2.IMGT.seq, before.unique$FR3.IMGT.seq, before.unique$CDR3.IMGT.seq)
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
26 } else if(empty.region.filter == "FR1"){
31
fe44a905aee9 Uploaded
davidvanzessen
parents: 8
diff changeset
27 before.unique$seq_conc = paste(before.unique$CDR1.IMGT.seq, before.unique$FR2.IMGT.seq, before.unique$CDR2.IMGT.seq, before.unique$FR3.IMGT.seq, before.unique$CDR3.IMGT.seq)
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
28 } else if(empty.region.filter == "CDR1"){
31
fe44a905aee9 Uploaded
davidvanzessen
parents: 8
diff changeset
29 before.unique$seq_conc = paste(before.unique$FR2.IMGT.seq, before.unique$CDR2.IMGT.seq, before.unique$FR3.IMGT.seq, before.unique$CDR3.IMGT.seq)
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
30 } else if(empty.region.filter == "FR2"){
31
fe44a905aee9 Uploaded
davidvanzessen
parents: 8
diff changeset
31 before.unique$seq_conc = paste(before.unique$CDR2.IMGT.seq, before.unique$FR3.IMGT.seq, before.unique$CDR3.IMGT.seq)
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
32 }
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
33
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
34 IDs = before.unique[,c("Sequence.ID", "seq_conc", "best_match", "Functionality")]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
35 IDs$best_match = as.character(IDs$best_match)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
36
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
37 dat = data.frame(table(before.unique$seq_conc))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
38
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
39 names(dat) = c("seq_conc", "Freq")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
40
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
41 dat$seq_conc = factor(dat$seq_conc)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
42
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
43 dat = dat[order(as.character(dat$seq_conc)),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
44
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
45 #writing html from R...
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
46 get.bg.color = function(val){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
47 if(val %in% c("TRUE", "FALSE", "T", "F")){ #if its a logical value, give the background a green/red color
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
48 return(ifelse(val,"#eafaf1","#f9ebea"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
49 } else if (!is.na(as.numeric(val))) { #if its a numerical value, give it a grey tint if its >0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
50 return(ifelse(val > 0,"#eaecee","white"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
51 } else {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
52 return("white")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
53 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
54 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
55 td = function(val) {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
56 return(paste("<td bgcolor='", get.bg.color(val), "'>", val, "</td>", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
57 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
58 tr = function(val) {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
59 return(paste(c("<tr>", sapply(val, td), "</tr>"), collapse=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
60 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
61
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
62 make.link = function(id, clss, val) {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
63 paste("<a href='", clss, "_", id, ".html'>", val, "</a>", sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
64 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
65 tbl = function(df) {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
66 res = "<table border='1'>"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
67 for(i in 1:nrow(df)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
68 res = paste(res, tr(df[i,]), sep="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
69 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
70 res = paste(res, "</table>")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
71 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
72
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
73 cat("<table border='1' class='pure-table pure-table-striped'>", file=main.html, append=F)
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
74
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
75 if(empty.region.filter == "leader"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
76 cat("<caption>FR1+CDR1+FR2+CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
77 } else if(empty.region.filter == "FR1"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
78 cat("<caption>CDR1+FR2+CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
79 } else if(empty.region.filter == "CDR1"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
80 cat("<caption>FR2+CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
81 } else if(empty.region.filter == "FR2"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
82 cat("<caption>CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
83 }
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
84
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
85 cat("<tr>", file=main.html, append=T)
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
86 cat("<th>Sequence</th><th>Functionality</th><th>IGA1</th><th>IGA2</th><th>IGG1</th><th>IGG2</th><th>IGG3</th><th>IGG4</th><th>IGM</th><th>IGE</th><th>UN</th>", file=main.html, append=T)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
87 cat("<th>total IGA</th><th>total IGG</th><th>total IGE</th><th>total IGM</th><th>number of subclasses</th><th>present in both IGA and IGG</th><th>present in IGA, IGG and IGM</th><th>present in IGA, IGG and IGE</th><th>present in IGA, IGG, IGM and IGE</th><th>IGA1+IGA2</th>", file=main.html, append=T)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
88 cat("<th>IGG1+IGG2</th><th>IGG1+IGG3</th><th>IGG1+IGG4</th><th>IGG2+IGG3</th><th>IGG2+IGG4</th><th>IGG3+IGG4</th>", file=main.html, append=T)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
89 cat("<th>IGG1+IGG2+IGG3</th><th>IGG2+IGG3+IGG4</th><th>IGG1+IGG2+IGG4</th><th>IGG1+IGG3+IGG4</th><th>IGG1+IGG2+IGG3+IGG4</th>", file=main.html, append=T)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
90 cat("</tr>", file=main.html, append=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
91
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
92
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
93
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
94 single.sequences=0 #sequence only found once, skipped
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
95 in.multiple=0 #same sequence across multiple subclasses
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
96 multiple.in.one=0 #same sequence multiple times in one subclass
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
97 unmatched=0 #all of the sequences are unmatched
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
98 some.unmatched=0 #one or more sequences in a clone are unmatched
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
99 matched=0 #should be the same als matched sequences
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
100
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
101 sequence.id.page="by_id.html"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
102
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
103 for(i in 1:nrow(dat)){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
104
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
105 ca1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGA1", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
106 ca2 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGA2", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
107
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
108 cg1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGG1", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
109 cg2 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGG2", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
110 cg3 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGG3", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
111 cg4 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGG4", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
112
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
113 cm = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGM", IDs$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
114
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
115 ce = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^IGE", IDs$best_match),]
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
116
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
117 un = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^unmatched", IDs$best_match),]
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
118
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
119 allc = rbind(ca1, ca2, cg1, cg2, cg3, cg4, cm, ce, un)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
120
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
121 ca1.n = nrow(ca1)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
122 ca2.n = nrow(ca2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
123
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
124 cg1.n = nrow(cg1)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
125 cg2.n = nrow(cg2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
126 cg3.n = nrow(cg3)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
127 cg4.n = nrow(cg4)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
128
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
129 cm.n = nrow(cm)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
130
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
131 ce.n = nrow(ce)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
132
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
133 un.n = nrow(un)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
134
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
135 classes = c(ca1.n, ca2.n, cg1.n, cg2.n, cg3.n, cg4.n, cm.n, ce.n, un.n)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
136
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
137 classes.sum = sum(classes)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
138
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
139 if(classes.sum == 1){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
140 single.sequences = single.sequences + 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
141 next
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
142 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
143
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
144 if(un.n == classes.sum){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
145 unmatched = unmatched + 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
146 next
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
147 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
148
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
149 in.classes = sum(classes > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
150
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
151 matched = matched + in.classes #count in how many subclasses the sequence occurs.
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
152
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
153 if(any(classes == classes.sum)){
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
154 multiple.in.one = multiple.in.one + 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
155 } else if (un.n > 0) {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
156 some.unmatched = some.unmatched + 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
157 } else {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
158 in.multiple = in.multiple + 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
159 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
160
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
161 id = as.numeric(dat[i,"seq_conc"])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
162
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
163 functionality = paste(unique(allc[,"Functionality"]), collapse=",")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
164
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
165 by.id.row = c()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
166
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
167 if(ca1.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
168 cat(tbl(ca1), file=paste("IGA1_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
169 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
170
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
171 if(ca2.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
172 cat(tbl(ca2), file=paste("IGA2_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
173 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
174
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
175 if(cg1.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
176 cat(tbl(cg1), file=paste("IGG1_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
177 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
178
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
179 if(cg2.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
180 cat(tbl(cg2), file=paste("IGG2_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
181 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
182
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
183 if(cg3.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
184 cat(tbl(cg3), file=paste("IGG3_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
185 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
186
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
187 if(cg4.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
188 cat(tbl(cg4), file=paste("IGG4_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
189 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
190
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
191 if(cm.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
192 cat(tbl(cm), file=paste("IGM_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
193 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
194
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
195 if(ce.n > 0){
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
196 cat(tbl(ce), file=paste("IGE_", id, ".html", sep=""))
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
197 }
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
198
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
199 if(un.n > 0){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
200 cat(tbl(un), file=paste("un_", id, ".html", sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
201 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
202
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
203 ca1.html = make.link(id, "IGA1", ca1.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
204 ca2.html = make.link(id, "IGA2", ca2.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
205
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
206 cg1.html = make.link(id, "IGG1", cg1.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
207 cg2.html = make.link(id, "IGG2", cg2.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
208 cg3.html = make.link(id, "IGG3", cg3.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
209 cg4.html = make.link(id, "IGG4", cg4.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
210
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
211 cm.html = make.link(id, "IGM", cm.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
212
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
213 ce.html = make.link(id, "IGE", ce.n)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
214
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
215 un.html = make.link(id, "un", un.n)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
216
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
217 #extra columns
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
218 ca.n = ca1.n + ca2.n
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
219
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
220 cg.n = cg1.n + cg2.n + cg3.n + cg4.n
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
221
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
222 #in.classes
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
223
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
224 in.ca.cg = (ca.n > 0 & cg.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
225
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
226 in.ca.cg.cm = (ca.n > 0 & cg.n > 0 & cm.n > 0)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
227
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
228 in.ca.cg.ce = (ca.n > 0 & cg.n > 0 & ce.n > 0)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
229
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
230 in.ca.cg.cm.ce = (ca.n > 0 & cg.n > 0 & cm.n > 0 & ce.n > 0)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
231
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
232 in.ca1.ca2 = (ca1.n > 0 & ca2.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
233
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
234 in.cg1.cg2 = (cg1.n > 0 & cg2.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
235 in.cg1.cg3 = (cg1.n > 0 & cg3.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
236 in.cg1.cg4 = (cg1.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
237 in.cg2.cg3 = (cg2.n > 0 & cg3.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
238 in.cg2.cg4 = (cg2.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
239 in.cg3.cg4 = (cg3.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
240
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
241 in.cg1.cg2.cg3 = (cg1.n > 0 & cg2.n > 0 & cg3.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
242 in.cg2.cg3.cg4 = (cg2.n > 0 & cg3.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
243 in.cg1.cg2.cg4 = (cg1.n > 0 & cg2.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
244 in.cg1.cg3.cg4 = (cg1.n > 0 & cg3.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
245
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
246 in.cg.all = (cg1.n > 0 & cg2.n > 0 & cg3.n > 0 & cg4.n > 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
247
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
248 #rw = c(as.character(dat[i,"seq_conc"]), functionality, ca1.html, ca2.html, cg1.html, cg2.html, cg3.html, cg4.html, cm.html, un.html)
32
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
249 rw = c(as.character(dat[i,"seq_conc"]), functionality, ca1.html, ca2.html, cg1.html, cg2.html, cg3.html, cg4.html, cm.html, ce.html, un.html)
4c5ba6b5d10d Uploaded
davidvanzessen
parents: 31
diff changeset
250 rw = c(rw, ca.n, cg.n, cm.n, ce.n, in.classes, in.ca.cg, in.ca.cg.cm, in.ca.cg.ce, in.ca.cg.cm.ce, in.ca1.ca2, in.cg1.cg2, in.cg1.cg3, in.cg1.cg4, in.cg2.cg3, in.cg2.cg4, in.cg3.cg4, in.cg1.cg2.cg3, in.cg2.cg3.cg4, in.cg1.cg2.cg4, in.cg1.cg3.cg4, in.cg.all)
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
251
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
252 cat(tr(rw), file=main.html, append=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
253
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
254
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
255 for(i in 1:nrow(allc)){ #generate html by id
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
256 html = make.link(id, allc[i,"best_match"], allc[i,"Sequence.ID"])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
257 cat(paste(html, "<br />"), file=sequence.id.page, append=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
258 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
259 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
260
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
261 cat("</table>", file=main.html, append=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
262
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
263 print(paste("Single sequences:", single.sequences))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
264 print(paste("Sequences in multiple subclasses:", in.multiple))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
265 print(paste("Multiple sequences in one subclass:", multiple.in.one))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
266 print(paste("Matched with unmatched:", some.unmatched))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
267 print(paste("Count that should match 'matched' sequences:", matched))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
268
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
269 #ACGT overview
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
270
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
271 #NToverview = merged[!grepl("^unmatched", merged$best_match),]
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
272 NToverview = merged
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
273
7
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
274 if(empty.region.filter == "leader"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
275 NToverview$seq = paste(NToverview$FR1.IMGT.seq, NToverview$CDR1.IMGT.seq, NToverview$FR2.IMGT.seq, NToverview$CDR2.IMGT.seq, NToverview$FR3.IMGT.seq)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
276 } else if(empty.region.filter == "FR1"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
277 NToverview$seq = paste(NToverview$CDR1.IMGT.seq, NToverview$FR2.IMGT.seq, NToverview$CDR2.IMGT.seq, NToverview$FR3.IMGT.seq)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
278 } else if(empty.region.filter == "CDR1"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
279 NToverview$seq = paste(NToverview$FR2.IMGT.seq, NToverview$CDR2.IMGT.seq, NToverview$FR3.IMGT.seq)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
280 } else if(empty.region.filter == "FR2"){
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
281 NToverview$seq = paste(NToverview$CDR2.IMGT.seq, NToverview$FR3.IMGT.seq)
ad9be244b104 Uploaded
davidvanzessen
parents: 0
diff changeset
282 }
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
283
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
284 NToverview$A = nchar(gsub("[^Aa]", "", NToverview$seq))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
285 NToverview$C = nchar(gsub("[^Cc]", "", NToverview$seq))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
286 NToverview$G = nchar(gsub("[^Gg]", "", NToverview$seq))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
287 NToverview$T = nchar(gsub("[^Tt]", "", NToverview$seq))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
288
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
289 #Nsum = data.frame(Sequence.ID="-", best_match="Sum", seq="-", A = sum(NToverview$A), C = sum(NToverview$C), G = sum(NToverview$G), T = sum(NToverview$T))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
290
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
291 #NToverview = rbind(NToverview, NTsum)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
292
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
293 NTresult = data.frame(nt=c("A", "C", "T", "G"))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
294
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
295 for(clazz in gene.classes){
8
3968d04b5724 Uploaded
davidvanzessen
parents: 7
diff changeset
296 print(paste("class:", clazz))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
297 NToverview.sub = NToverview[grepl(paste("^", clazz, sep=""), NToverview$best_match),]
8
3968d04b5724 Uploaded
davidvanzessen
parents: 7
diff changeset
298 print(paste("nrow:", nrow(NToverview.sub)))
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
299 new.col.x = c(sum(NToverview.sub$A), sum(NToverview.sub$C), sum(NToverview.sub$T), sum(NToverview.sub$G))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
300 new.col.y = sum(new.col.x)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
301 new.col.z = round(new.col.x / new.col.y * 100, 2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
302
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
303 tmp = names(NTresult)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
304 NTresult = cbind(NTresult, data.frame(new.col.x, new.col.y, new.col.z))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
305 names(NTresult) = c(tmp, paste(clazz, c("x", "y", "z"), sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
306 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
307
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
308 write.table(NToverview[,c("Sequence.ID", "best_match", "seq", "A", "C", "G", "T")], NToverview.file, quote=F, sep="\t", row.names=F, col.names=T)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
309
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
310 NToverview = NToverview[!grepl("unmatched", NToverview$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
311
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
312 new.col.x = c(sum(NToverview$A), sum(NToverview$C), sum(NToverview$T), sum(NToverview$G))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
313 new.col.y = sum(new.col.x)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
314 new.col.z = round(new.col.x / new.col.y * 100, 2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
315
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
316 tmp = names(NTresult)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
317 NTresult = cbind(NTresult, data.frame(new.col.x, new.col.y, new.col.z))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
318 names(NTresult) = c(tmp, paste("all", c("x", "y", "z"), sep=""))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
319
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
320 names(hotspot.analysis.sum) = names(NTresult)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
321
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
322 hotspot.analysis.sum = rbind(hotspot.analysis.sum, NTresult)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
323
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
324 write.table(hotspot.analysis.sum, hotspot.analysis.sum.file, quote=F, sep=",", row.names=F, col.names=F, na="0")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
325
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
326
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
327
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
328
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
329
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
330
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
331
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
332
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
333
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
334
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
335
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
336
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
337
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
338
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
339
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
340
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
341
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
342
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
343
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
344
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
345
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
346
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
347
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
348
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
349
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
350
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
351
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
352
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
353
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
354