diff sequence_overview.r @ 102:e6bc976760d4 draft

Uploaded
author davidvanzessen
date Tue, 21 Jun 2016 03:32:50 -0400
parents ff5be711382b
children e21cbe15381f
line wrap: on
line diff
--- a/sequence_overview.r	Fri Jun 17 08:31:20 2016 -0400
+++ b/sequence_overview.r	Tue Jun 21 03:32:50 2016 -0400
@@ -17,7 +17,7 @@
 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="")
 hotspot.analysis.sum = read.table(hotspot.analysis.sum.file, header=F, sep=",", fill=T, stringsAsFactors=F, quote="")
 
-before.unique = before.unique[!grepl("unmatched", before.unique$best_match),]
+#before.unique = before.unique[!grepl("unmatched", before.unique$best_match),]
 
 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)
 
@@ -46,15 +46,19 @@
 
 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></tr>", 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)
 
 
 
 single.sequences=0 #sequence only found once, skipped
 in.multiple=0 #same sequence across multiple subclasses
 multiple.in.one=0 #same sequence multiple times in one subclass
+unmatched=0 #all of the sequences are unmatched
+some.unmatched=0 #one or more sequences in a clone are unmatched
 matched=0 #should be the same als matched sequences
 
+sequence.id.page="by_id.html"
+
 for(i in 1:nrow(dat)){
 	
 	ca1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^ca1", IDs$best_match),]
@@ -66,9 +70,11 @@
 	cg4 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^cg4", IDs$best_match),]
 	
 	cm = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & grepl("^cm", IDs$best_match),]
-	allc = rbind(ca1, ca2, cg1, cg2, cg3, cg4, cm)
 	
-	classes = c(nrow(ca1), nrow(ca2), nrow(cg1), nrow(cg2), nrow(cg3), nrow(cg4), nrow(cm))
+	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))
 	
 	classes.sum = sum(classes)
 	
@@ -77,18 +83,27 @@
 		next
 	}
 	
+	if(nrow(un) == classes.sum){
+		unmatched = unmatched + 1
+		next
+	}
+	
 	matched = matched + sum(classes > 0) #count in how many subclasses the sequence occurs.
 	
 	if(any(classes  == classes.sum)){
-		in.multiple = in.multiple + 1
+		multiple.in.one = multiple.in.one + 1
+	} else if (nrow(un) > 0) {
+		some.unmatched = some.unmatched + 1
 	} else {
-		multiple.in.one = multiple.in.one + 1
+		in.multiple = in.multiple + 1
 	}
 	
 	id = as.numeric(dat[i,"seq_conc"])
 	
 	functionality = paste(unique(allc[,"Functionality"]), collapse=",")
-
+	
+	by.id.row = c()
+	
 	if(nrow(ca1) > 0){
 		cat(tbl(ca1), file=paste("ca1_", id, ".html", sep=""))
 	}
@@ -116,6 +131,10 @@
 	if(nrow(cm) > 0){
 		cat(tbl(cm), file=paste("cm_", id, ".html", sep=""))
 	}
+
+	if(nrow(un) > 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))
@@ -127,9 +146,18 @@
 	
 	cm.html = make.link(id, "cm", nrow(cm))
 	
-	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 = make.link(id, "un", nrow(un))
+	
+	#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)
 
 	cat(tr(rw), file=main.html, append=T)
+	
+	
+	for(i in 1:nrow(allc)){ #generate html by id
+		html = make.link(id, allc[i,"best_match"], allc[i,"Sequence.ID"])
+		cat(paste(html, "<br />"), file=sequence.id.page, append=T)
+	}
 }
 
 cat("</table>", file=main.html, append=T)
@@ -137,6 +165,7 @@
 print(paste("Single sequences:", single.sequences))
 print(paste("Sequences in multiple subclasses:", in.multiple))
 print(paste("Multiple sequences in one subclass:", multiple.in.one))
+print(paste("Matched with unmatched:", some.unmatched))
 print(paste("Count that should match 'matched' sequences:", matched))
 
 #ACGT overview