diff sequence_overview.r @ 104:603a10976e9c draft

Uploaded
author davidvanzessen
date Wed, 22 Jun 2016 10:07:28 -0400
parents e21cbe15381f
children 074ae1e30e8f
line wrap: on
line diff
--- a/sequence_overview.r	Tue Jun 21 05:30:16 2016 -0400
+++ b/sequence_overview.r	Wed Jun 22 10:07:28 2016 -0400
@@ -39,14 +39,41 @@
 dat = dat[order(as.character(dat$seq_conc)),]
 
 #writing html from R...
-td = function(val) { paste("<td>", val, "</td>", sep="") }
-tr = function(val) { capture.output(cat("<tr>", td(val), "</tr>", sep="")) }
-make.link = function(id, clss, val) { paste("<a href='", clss, "_", id, ".html'>", val, "</a>", sep="") }
-tbl = function(df) { res = "<table border='1'>"; for(i in 1:nrow(df)){ res = paste(res, tr(df[i,]), sep=""); }; res = paste(res, "</table>"); }
+get.bg.color = function(val){
+	if(val %in% c("TRUE", "FALSE", "T", "F")){ #if its a logical value, give the background a green/red color
+		return(ifelse(val,"#eafaf1","#f9ebea"))
+	} else if (!is.na(as.numeric(val))) { #if its a numerical value, give it a grey tint if its >0
+		return(ifelse(val > 0,"#eaecee","white"))
+	} else {
+		return("white")
+	}
+}
+td = function(val) {
+  return(paste("<td bgcolor='", get.bg.color(val), "'>", val, "</td>", sep=""))
+}
+tr = function(val) { 
+	return(paste(c("<tr>", sapply(val, td), "</tr>"), collapse="")) 
+}
+
+make.link = function(id, clss, val) { 
+	paste("<a href='", clss, "_", id, ".html'>", val, "</a>", sep="") 
+}
+tbl = function(df) {
+	res = "<table border='1'>"
+	for(i in 1:nrow(df)){ 
+		res = paste(res, tr(df[i,]), sep="")
+	}
+	res = paste(res, "</table>")
+}
 
 cat("<table border='1'>", file=main.html, append=F)
 cat("<caption>CDR1+FR2+CDR2+FR3+CDR3 sequences that show up more than once</caption>", file=main.html, append=T)
-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)
+cat("<tr>", file=main.html, append=T)
+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)
+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)
+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)
+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)
+cat("</tr>", file=main.html, append=T)
 
 
 
@@ -74,7 +101,19 @@
 	un = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^unmatched", IDs$best_match),]
 	allc = rbind(ca1, ca2, cg1, cg2, cg3, cg4, cm, un)
 	
-	classes = c(nrow(ca1), nrow(ca2), nrow(cg1), nrow(cg2), nrow(cg3), nrow(cg4), nrow(cm), nrow(un))
+	ca1.n = nrow(ca1)
+	ca2.n = nrow(ca2)
+	
+	cg1.n = nrow(cg1)
+	cg2.n = nrow(cg2)
+	cg3.n = nrow(cg3)
+	cg4.n = nrow(cg4)
+	
+	cm.n = nrow(cm)
+	
+	un.n = nrow(un)
+	
+	classes = c(ca1.n, ca2.n, cg1.n, cg2.n, cg3.n, cg4.n, cm.n, un.n)
 	
 	classes.sum = sum(classes)
 	
@@ -83,16 +122,18 @@
 		next
 	}
 	
-	if(nrow(un) == classes.sum){
+	if(un.n == classes.sum){
 		unmatched = unmatched + 1
 		next
 	}
 	
-	matched = matched + sum(classes > 0) #count in how many subclasses the sequence occurs.
+	in.classes = sum(classes > 0)
+	
+	matched = matched + in.classes #count in how many subclasses the sequence occurs.
 	
 	if(any(classes  == classes.sum)){
 		multiple.in.one = multiple.in.one + 1
-	} else if (nrow(un) > 0) {
+	} else if (un.n > 0) {
 		some.unmatched = some.unmatched + 1
 	} else {
 		in.multiple = in.multiple + 1
@@ -104,52 +145,79 @@
 	
 	by.id.row = c()
 	
-	if(nrow(ca1) > 0){
+	if(ca1.n > 0){
 		cat(tbl(ca1), file=paste("ca1_", id, ".html", sep=""))
 	}
 
-	if(nrow(ca2) > 0){
+	if(ca2.n > 0){
 		cat(tbl(ca2), file=paste("ca2_", id, ".html", sep=""))
 	}
 
-	if(nrow(cg1) > 0){
+	if(cg1.n > 0){
 		cat(tbl(cg1), file=paste("cg1_", id, ".html", sep=""))
 	}
 
-	if(nrow(cg2) > 0){
+	if(cg2.n > 0){
 		cat(tbl(cg2), file=paste("cg2_", id, ".html", sep=""))
 	}
 
-	if(nrow(cg3) > 0){
+	if(cg3.n > 0){
 		cat(tbl(cg3), file=paste("cg3_", id, ".html", sep=""))
 	}
 
-	if(nrow(cg4) > 0){
+	if(cg4.n > 0){
 		cat(tbl(cg4), file=paste("cg4_", id, ".html", sep=""))
 	}
 
-	if(nrow(cm) > 0){
+	if(cm.n > 0){
 		cat(tbl(cm), file=paste("cm_", id, ".html", sep=""))
 	}
 
-	if(nrow(un) > 0){
+	if(un.n > 0){
 		cat(tbl(un), file=paste("un_", id, ".html", sep=""))
 	}
 	
-	ca1.html = make.link(id, "ca1", nrow(ca1))
-	ca2.html = make.link(id, "ca2", nrow(ca2))
+	ca1.html = make.link(id, "ca1", ca1.n)
+	ca2.html = make.link(id, "ca2", ca2.n)
+	
+	cg1.html = make.link(id, "cg1", cg1.n)
+	cg2.html = make.link(id, "cg2", cg2.n)
+	cg3.html = make.link(id, "cg3", cg3.n)
+	cg4.html = make.link(id, "cg4", cg4.n)
+	
+	cm.html = make.link(id, "cm", cm.n)
+	
+	un.html = make.link(id, "un", un.n)
+	
+	#extra columns
+	ca.n = ca1.n + ca2.n
+	
+	cg.n = cg1.n + cg2.n + cg3.n + cg4.n
+	
+	#in.classes
 	
-	cg1.html = make.link(id, "cg1", nrow(cg1))
-	cg2.html = make.link(id, "cg2", nrow(cg2))
-	cg3.html = make.link(id, "cg3", nrow(cg3))
-	cg4.html = make.link(id, "cg4", nrow(cg4))
+	in.ca.cg = (ca.n > 0 & cg.n > 0)
+	
+	in.ca1.ca2 = (ca1.n > 0 & ca2.n > 0)
 	
-	cm.html = make.link(id, "cm", nrow(cm))
+	in.cg1.cg2 = (cg1.n > 0 & cg2.n > 0)
+	in.cg1.cg3 = (cg1.n > 0 & cg3.n > 0)
+	in.cg1.cg4 = (cg1.n > 0 & cg4.n > 0)
+	in.cg2.cg3 = (cg2.n > 0 & cg3.n > 0)
+	in.cg2.cg4 = (cg2.n > 0 & cg4.n > 0)
+	in.cg3.cg4 = (cg3.n > 0 & cg4.n > 0)
 	
-	un.html = make.link(id, "un", nrow(un))
+	in.cg1.cg2.cg3 = (cg1.n > 0 & cg2.n > 0 & cg3.n > 0)
+	in.cg2.cg3.cg4 = (cg2.n > 0 & cg3.n > 0 & cg4.n > 0)
+	in.cg1.cg2.cg4 = (cg1.n > 0 & cg2.n > 0 & cg4.n > 0)
+	in.cg1.cg3.cg4 = (cg1.n > 0 & cg3.n > 0 & cg4.n > 0)
+	
+	
+	
 	
 	#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)
 	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)
+	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)
 
 	cat(tr(rw), file=main.html, append=T)