comparison sequence_overview.r @ 104:603a10976e9c draft

Uploaded
author davidvanzessen
date Wed, 22 Jun 2016 10:07:28 -0400
parents e21cbe15381f
children 074ae1e30e8f
comparison
equal deleted inserted replaced
103:e21cbe15381f 104:603a10976e9c
37 dat$seq_conc = factor(dat$seq_conc) 37 dat$seq_conc = factor(dat$seq_conc)
38 38
39 dat = dat[order(as.character(dat$seq_conc)),] 39 dat = dat[order(as.character(dat$seq_conc)),]
40 40
41 #writing html from R... 41 #writing html from R...
42 td = function(val) { paste("<td>", val, "</td>", sep="") } 42 get.bg.color = function(val){
43 tr = function(val) { capture.output(cat("<tr>", td(val), "</tr>", sep="")) } 43 if(val %in% c("TRUE", "FALSE", "T", "F")){ #if its a logical value, give the background a green/red color
44 make.link = function(id, clss, val) { paste("<a href='", clss, "_", id, ".html'>", val, "</a>", sep="") } 44 return(ifelse(val,"#eafaf1","#f9ebea"))
45 tbl = function(df) { res = "<table border='1'>"; for(i in 1:nrow(df)){ res = paste(res, tr(df[i,]), sep=""); }; res = paste(res, "</table>"); } 45 } else if (!is.na(as.numeric(val))) { #if its a numerical value, give it a grey tint if its >0
46 return(ifelse(val > 0,"#eaecee","white"))
47 } else {
48 return("white")
49 }
50 }
51 td = function(val) {
52 return(paste("<td bgcolor='", get.bg.color(val), "'>", val, "</td>", sep=""))
53 }
54 tr = function(val) {
55 return(paste(c("<tr>", sapply(val, td), "</tr>"), collapse=""))
56 }
57
58 make.link = function(id, clss, val) {
59 paste("<a href='", clss, "_", id, ".html'>", val, "</a>", sep="")
60 }
61 tbl = function(df) {
62 res = "<table border='1'>"
63 for(i in 1:nrow(df)){
64 res = paste(res, tr(df[i,]), sep="")
65 }
66 res = paste(res, "</table>")
67 }
46 68
47 cat("<table border='1'>", file=main.html, append=F) 69 cat("<table border='1'>", file=main.html, append=F)
48 cat("<caption>CDR1+FR2+CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T) 70 cat("<caption>CDR1+FR2+CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T)
49 cat("<tr><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></tr>", file=main.html, append=T) 71 cat("<tr>", file=main.html, append=T)
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)
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)
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)
75 cat("<th>Cg1+Cg2+Cg3</th><th>Cg2+Cg3+Cg4</th><th>Cg1+Cg2+Cg4</th><th>Cg1+Cg3+Cg4</th>", file=main.html, append=T)
76 cat("</tr>", file=main.html, append=T)
50 77
51 78
52 79
53 single.sequences=0 #sequence only found once, skipped 80 single.sequences=0 #sequence only found once, skipped
54 in.multiple=0 #same sequence across multiple subclasses 81 in.multiple=0 #same sequence across multiple subclasses
72 cm = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^cm", IDs$best_match),] 99 cm = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^cm", IDs$best_match),]
73 100
74 un = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^unmatched", IDs$best_match),] 101 un = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^unmatched", IDs$best_match),]
75 allc = rbind(ca1, ca2, cg1, cg2, cg3, cg4, cm, un) 102 allc = rbind(ca1, ca2, cg1, cg2, cg3, cg4, cm, un)
76 103
77 classes = c(nrow(ca1), nrow(ca2), nrow(cg1), nrow(cg2), nrow(cg3), nrow(cg4), nrow(cm), nrow(un)) 104 ca1.n = nrow(ca1)
105 ca2.n = nrow(ca2)
106
107 cg1.n = nrow(cg1)
108 cg2.n = nrow(cg2)
109 cg3.n = nrow(cg3)
110 cg4.n = nrow(cg4)
111
112 cm.n = nrow(cm)
113
114 un.n = nrow(un)
115
116 classes = c(ca1.n, ca2.n, cg1.n, cg2.n, cg3.n, cg4.n, cm.n, un.n)
78 117
79 classes.sum = sum(classes) 118 classes.sum = sum(classes)
80 119
81 if(classes.sum == 1){ 120 if(classes.sum == 1){
82 single.sequences = single.sequences + 1 121 single.sequences = single.sequences + 1
83 next 122 next
84 } 123 }
85 124
86 if(nrow(un) == classes.sum){ 125 if(un.n == classes.sum){
87 unmatched = unmatched + 1 126 unmatched = unmatched + 1
88 next 127 next
89 } 128 }
90 129
91 matched = matched + sum(classes > 0) #count in how many subclasses the sequence occurs. 130 in.classes = sum(classes > 0)
131
132 matched = matched + in.classes #count in how many subclasses the sequence occurs.
92 133
93 if(any(classes == classes.sum)){ 134 if(any(classes == classes.sum)){
94 multiple.in.one = multiple.in.one + 1 135 multiple.in.one = multiple.in.one + 1
95 } else if (nrow(un) > 0) { 136 } else if (un.n > 0) {
96 some.unmatched = some.unmatched + 1 137 some.unmatched = some.unmatched + 1
97 } else { 138 } else {
98 in.multiple = in.multiple + 1 139 in.multiple = in.multiple + 1
99 } 140 }
100 141
102 143
103 functionality = paste(unique(allc[,"Functionality"]), collapse=",") 144 functionality = paste(unique(allc[,"Functionality"]), collapse=",")
104 145
105 by.id.row = c() 146 by.id.row = c()
106 147
107 if(nrow(ca1) > 0){ 148 if(ca1.n > 0){
108 cat(tbl(ca1), file=paste("ca1_", id, ".html", sep="")) 149 cat(tbl(ca1), file=paste("ca1_", id, ".html", sep=""))
109 } 150 }
110 151
111 if(nrow(ca2) > 0){ 152 if(ca2.n > 0){
112 cat(tbl(ca2), file=paste("ca2_", id, ".html", sep="")) 153 cat(tbl(ca2), file=paste("ca2_", id, ".html", sep=""))
113 } 154 }
114 155
115 if(nrow(cg1) > 0){ 156 if(cg1.n > 0){
116 cat(tbl(cg1), file=paste("cg1_", id, ".html", sep="")) 157 cat(tbl(cg1), file=paste("cg1_", id, ".html", sep=""))
117 } 158 }
118 159
119 if(nrow(cg2) > 0){ 160 if(cg2.n > 0){
120 cat(tbl(cg2), file=paste("cg2_", id, ".html", sep="")) 161 cat(tbl(cg2), file=paste("cg2_", id, ".html", sep=""))
121 } 162 }
122 163
123 if(nrow(cg3) > 0){ 164 if(cg3.n > 0){
124 cat(tbl(cg3), file=paste("cg3_", id, ".html", sep="")) 165 cat(tbl(cg3), file=paste("cg3_", id, ".html", sep=""))
125 } 166 }
126 167
127 if(nrow(cg4) > 0){ 168 if(cg4.n > 0){
128 cat(tbl(cg4), file=paste("cg4_", id, ".html", sep="")) 169 cat(tbl(cg4), file=paste("cg4_", id, ".html", sep=""))
129 } 170 }
130 171
131 if(nrow(cm) > 0){ 172 if(cm.n > 0){
132 cat(tbl(cm), file=paste("cm_", id, ".html", sep="")) 173 cat(tbl(cm), file=paste("cm_", id, ".html", sep=""))
133 } 174 }
134 175
135 if(nrow(un) > 0){ 176 if(un.n > 0){
136 cat(tbl(un), file=paste("un_", id, ".html", sep="")) 177 cat(tbl(un), file=paste("un_", id, ".html", sep=""))
137 } 178 }
138 179
139 ca1.html = make.link(id, "ca1", nrow(ca1)) 180 ca1.html = make.link(id, "ca1", ca1.n)
140 ca2.html = make.link(id, "ca2", nrow(ca2)) 181 ca2.html = make.link(id, "ca2", ca2.n)
141 182
142 cg1.html = make.link(id, "cg1", nrow(cg1)) 183 cg1.html = make.link(id, "cg1", cg1.n)
143 cg2.html = make.link(id, "cg2", nrow(cg2)) 184 cg2.html = make.link(id, "cg2", cg2.n)
144 cg3.html = make.link(id, "cg3", nrow(cg3)) 185 cg3.html = make.link(id, "cg3", cg3.n)
145 cg4.html = make.link(id, "cg4", nrow(cg4)) 186 cg4.html = make.link(id, "cg4", cg4.n)
146 187
147 cm.html = make.link(id, "cm", nrow(cm)) 188 cm.html = make.link(id, "cm", cm.n)
148 189
149 un.html = make.link(id, "un", nrow(un)) 190 un.html = make.link(id, "un", un.n)
191
192 #extra columns
193 ca.n = ca1.n + ca2.n
194
195 cg.n = cg1.n + cg2.n + cg3.n + cg4.n
196
197 #in.classes
198
199 in.ca.cg = (ca.n > 0 & cg.n > 0)
200
201 in.ca1.ca2 = (ca1.n > 0 & ca2.n > 0)
202
203 in.cg1.cg2 = (cg1.n > 0 & cg2.n > 0)
204 in.cg1.cg3 = (cg1.n > 0 & cg3.n > 0)
205 in.cg1.cg4 = (cg1.n > 0 & cg4.n > 0)
206 in.cg2.cg3 = (cg2.n > 0 & cg3.n > 0)
207 in.cg2.cg4 = (cg2.n > 0 & cg4.n > 0)
208 in.cg3.cg4 = (cg3.n > 0 & cg4.n > 0)
209
210 in.cg1.cg2.cg3 = (cg1.n > 0 & cg2.n > 0 & cg3.n > 0)
211 in.cg2.cg3.cg4 = (cg2.n > 0 & cg3.n > 0 & cg4.n > 0)
212 in.cg1.cg2.cg4 = (cg1.n > 0 & cg2.n > 0 & cg4.n > 0)
213 in.cg1.cg3.cg4 = (cg1.n > 0 & cg3.n > 0 & cg4.n > 0)
214
215
216
150 217
151 #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) 218 #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)
152 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) 219 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)
220 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)
153 221
154 cat(tr(rw), file=main.html, append=T) 222 cat(tr(rw), file=main.html, append=T)
155 223
156 224
157 for(i in 1:nrow(allc)){ #generate html by id 225 for(i in 1:nrow(allc)){ #generate html by id