annotate sequence_overview.r @ 0:8a5a2abbb870 draft default tip

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