changeset 9:58a28427930e draft

Uploaded
author davidvanzessen
date Tue, 30 Sep 2014 10:06:57 -0400
parents fa240d1c57a9
children 974febc99fd4
files RScript.r wrapper.sh
diffstat 2 files changed, 215 insertions(+), 185 deletions(-) [+]
line wrap: on
line diff
--- a/RScript.r	Thu Sep 18 10:28:24 2014 -0400
+++ b/RScript.r	Tue Sep 30 10:06:57 2014 -0400
@@ -15,13 +15,18 @@
 library(parallel)
 #require(xtable)
 cat("<tr><td>Reading input</td></tr>", file=logfile, append=T)
-dat = read.csv(inFile, sep="\t")
-#dat = data.frame(fread(inFile)) #faster but with a dep
+dat = read.table(inFile, header=T, sep="\t", dec=",", fill=T, stringsAsFactors=F)
+dat = dat[!is.na(dat$Patient),]
+
 setwd(outDir)
 cat("<tr><td>Selecting first V/J Genes</td></tr>", file=logfile, append=T)
 dat$V_Segment_Major_Gene = as.factor(as.character(lapply(strsplit(as.character(dat$V_Segment_Major_Gene), "; "), "[[", 1)))
 dat$J_Segment_Major_Gene = as.factor(as.character(lapply(strsplit(as.character(dat$J_Segment_Major_Gene), "; "), "[[", 1)))
 
+str(dat)
+cat("<tr><td>Deduplication</td></tr>", file=logfile, append=T)
+dat = data.frame(data.table(dat)[, list(Patient=unique(.SD$Patient), Clone_Molecule_Count_From_Spikes=sum(.SD$Clone_Molecule_Count_From_Spikes), Log10_Frequency=sum(.SD$Log10_Frequency), Total_Read_Count=sum(.SD$Total_Read_Count), Related_to_leukemia_clone=any(.SD$Related_to_leukemia_clone)), by=c("Sample", "Cell_Count", "J_Segment_Major_Gene", "V_Segment_Major_Gene", "CDR3_Sense_Sequence")])
+
 cat("<tr><td>Calculating Frequency</td></tr>", file=logfile, append=T)
 dat$Frequency = ((10^dat$Log10_Frequency)*100)
 
@@ -31,10 +36,10 @@
 dat$normalized_read_count = round(dat$Clone_Molecule_Count_From_Spikes / dat$Cell_Count * 1000000 / 2)
 dat = dat[dat$normalized_read_count >= min_cells,]
 dat$paste = paste(dat$Sample, dat$V_Segment_Major_Gene, dat$J_Segment_Major_Gene, dat$CDR3_Sense_Sequence)
-cat("<tr><td>Removing duplicates</td></tr>", file=logfile, append=T)
-dat = dat[!duplicated(dat$paste),]
+triplets = dat[grepl("VanDongen_cALL_14696", dat$Patient) | grepl("(16278)|(26402)|(26759)", dat$Sample),]
+
 patients = split(dat, dat$Patient, drop=T)
-intervalReads = rev(c(0,10,25,50,100,1000,10000))
+intervalReads = rev(c(0,10,25,50,100,250,500,750,1000,10000))
 intervalFreq = rev(c(0,0.01,0.05,0.1,0.5,1,5))
 V_Segments = c(".*", "IGHV", "IGHD", "IGKV", "IGKV", "IgKINTR", "TRGV", "TRDV", "TRDD" , "TRBV")
 J_Segments = c(".*", ".*", ".*", "IGKJ", "KDE", ".*", ".*", ".*", ".*", ".*")
@@ -82,7 +87,11 @@
     cat(paste(patient, oneSample, twoSample, type, sep="\t"), file="patients.txt", append=T, sep="", fill=3)
   }
   cat(paste("<tr><td>", patient, "</td></tr>", sep=""), file=logfile, append=T)
-  patientMerge = merge(patient1, patient2, by="Clone_Sequence")
+  
+  patient1$merge = paste(patient1$V_Segment_Major_Gene, patient1$J_Segment_Major_Gene, patient1$CDR3_Sense_Sequence)
+  patient2$merge = paste(patient2$V_Segment_Major_Gene, patient2$J_Segment_Major_Gene, patient2$CDR3_Sense_Sequence)
+  
+  patientMerge = merge(patient1, patient2, by.x="merge", by.y="merge")
   res1 = vector()
   res2 = vector()
   resBoth = vector()
@@ -90,14 +99,16 @@
   read2Count = vector()
   locussum1 = vector()
   locussum2 = vector()
+  
+  print(patient)
   #for(iter in 1){
   for(iter in 1:length(product[,1])){
     threshhold = product[iter,threshholdIndex]
     V_Segment = paste(".*", as.character(product[iter,V_SegmentIndex]), ".*", sep="")
     J_Segment = paste(".*", as.character(product[iter,J_SegmentIndex]), ".*", sep="")
     both = (grepl(V_Segment, patientMerge$V_Segment_Major_Gene.x) & grepl(J_Segment, patientMerge$J_Segment_Major_Gene.x) & patientMerge[,paste(on, ".x", sep="")] > threshhold & patientMerge[,paste(on, ".y", sep="")] > threshhold)
-    one = (grepl(V_Segment, patient1$V_Segment_Major_Gene) & grepl(J_Segment, patient1$J_Segment_Major_Gene) & patient1[,on] > threshhold & !(patient1$Clone_Sequence %in% patientMerge[both,]$Clone_Sequence))
-    two = (grepl(V_Segment, patient2$V_Segment_Major_Gene) & grepl(J_Segment, patient2$J_Segment_Major_Gene) & patient2[,on] > threshhold & !(patient2$Clone_Sequence %in% patientMerge[both,]$Clone_Sequence))
+    one = (grepl(V_Segment, patient1$V_Segment_Major_Gene) & grepl(J_Segment, patient1$J_Segment_Major_Gene) & patient1[,on] > threshhold & !(patient1$CDR3_Sense_Sequence %in% patientMerge[both,]$CDR3_Sense_Sequence))
+    two = (grepl(V_Segment, patient2$V_Segment_Major_Gene) & grepl(J_Segment, patient2$J_Segment_Major_Gene) & patient2[,on] > threshhold & !(patient2$CDR3_Sense_Sequence %in% patientMerge[both,]$CDR3_Sense_Sequence))
     read1Count = append(read1Count, sum(patient1[one,]$normalized_read_count) + sum(patientMerge[both,]$normalized_read_count.x))
     read2Count = append(read2Count, sum(patient2[two,]$normalized_read_count) + sum(patientMerge[both,]$normalized_read_count.y))
     res1 = append(res1, sum(one))
@@ -108,21 +119,21 @@
     #threshhold = 0
     if(threshhold != 0){
       if(sum(one) > 0){
-        dfOne = patient1[one,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "Clone_Sequence", "Related_to_leukemia_clone")]
-        colnames(dfOne) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "Sequence", "Related_to_leukemia_clone")
+        dfOne = patient1[one,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "CDR3_Sense_Sequence", "Related_to_leukemia_clone")]
+        colnames(dfOne) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "CDR3 Sequence", "Related_to_leukemia_clone")
         filenameOne = paste(oneSample, "_", product[iter, titleIndex], "_", threshhold, sep="")
         write.table(dfOne, file=paste(filenameOne, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
       }
       if(sum(two) > 0){
-        dfTwo = patient2[two,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "Clone_Sequence", "Related_to_leukemia_clone")]
-        colnames(dfTwo) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "Sequence", "Related_to_leukemia_clone")
+        dfTwo = patient2[two,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "CDR3_Sense_Sequence", "Related_to_leukemia_clone")]
+        colnames(dfTwo) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "CDR3 Sequence", "Related_to_leukemia_clone")
         filenameTwo = paste(twoSample, "_", product[iter, titleIndex], "_", threshhold, sep="")
         write.table(dfTwo, file=paste(filenameTwo, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
       }
     }
     if(sum(both) > 0){
-      dfBoth = patientMerge[both,c("V_Segment_Major_Gene.x", "J_Segment_Major_Gene.x", "normalized_read_count.x", "Frequency.x", "Related_to_leukemia_clone.x", "Clone_Sequence", "V_Segment_Major_Gene.y", "J_Segment_Major_Gene.y", "normalized_read_count.y", "Frequency.y", "Related_to_leukemia_clone.y")]
-      colnames(dfBoth) = c(paste("Proximal segment", oneSample), paste("Distal segment", oneSample), paste("Normalized_Read_Count", oneSample), paste("Frequency", oneSample), paste("Related_to_leukemia_clone", oneSample),"Sequence", paste("Proximal segment", twoSample), paste("Distal segment", twoSample), paste("Normalized_Read_Count", twoSample), paste("Frequency", twoSample), paste("Related_to_leukemia_clone", twoSample))
+      dfBoth = patientMerge[both,c("V_Segment_Major_Gene.x", "J_Segment_Major_Gene.x", "normalized_read_count.x", "Frequency.x", "Related_to_leukemia_clone.x", "CDR3_Sense_Sequence.x", "V_Segment_Major_Gene.y", "J_Segment_Major_Gene.y", "normalized_read_count.y", "Frequency.y", "Related_to_leukemia_clone.y")]
+      colnames(dfBoth) = c(paste("Proximal segment", oneSample), paste("Distal segment", oneSample), paste("Normalized_Read_Count", oneSample), paste("Frequency", oneSample), paste("Related_to_leukemia_clone", oneSample),"CDR3 Sequence", paste("Proximal segment", twoSample), paste("Distal segment", twoSample), paste("Normalized_Read_Count", twoSample), paste("Frequency", twoSample), paste("Related_to_leukemia_clone", twoSample))
       filenameBoth = paste(oneSample, "_", twoSample, "_", product[iter, titleIndex], "_", threshhold, sep="")
       write.table(dfBoth, file=paste(filenameBoth, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
     }
@@ -188,7 +199,7 @@
 interval = intervalReads
 intervalOrder = data.frame("interval"=paste(">", interval, sep=""), "intervalOrder"=1:length(interval))
 product = data.frame("Titles"=rep(Titles, each=length(interval)), "interval"=rep(interval, times=10), "V_Segments"=rep(V_Segments, each=length(interval)), "J_Segments"=rep(J_Segments, each=length(interval)))
-mclapply(patients, FUN=patientCountOnColumn, product = product, interval=interval, on="Clone_Molecule_Count_From_Spikes")
+mclapply(patients, FUN=patientCountOnColumn, product = product, interval=interval, on="normalized_read_count")
 
 cat("</table></html>", file=logfile, append=T)
 
@@ -210,9 +221,13 @@
   twoSample = paste(patient2[1,sampleIndex], sep="")
   threeSample = paste(patient3[1,sampleIndex], sep="")
   
-  patientMerge = merge(patient1, patient2, by="Clone_Sequence")
-  patientMerge = merge(patientMerge, patient3, by="Clone_Sequence")
-  colnames(patientMerge)[32:length(colnames(patientMerge))] = paste(colnames(patientMerge)[32:length(colnames(patientMerge))], ".z", sep="")
+  patient1$merge = paste(patient1$V_Segment_Major_Gene, patient1$J_Segment_Major_Gene, patient1$CDR3_Sense_Sequence)
+  patient2$merge = paste(patient2$V_Segment_Major_Gene, patient2$J_Segment_Major_Gene, patient2$CDR3_Sense_Sequence)
+  patient3$merge = paste(patient3$V_Segment_Major_Gene, patient3$J_Segment_Major_Gene, patient3$CDR3_Sense_Sequence)
+  
+  patientMerge = merge(patient1, patient2, by="merge")
+  patientMerge = merge(patientMerge, patient3, by="merge")
+  colnames(patientMerge)[28:length(colnames(patientMerge))] = paste(colnames(patientMerge)[28:length(colnames(patientMerge))], ".z", sep="")
   res1 = vector()
   res2 = vector()
   res3 = vector()
@@ -222,16 +237,16 @@
   read3Count = vector()
   
   if(appendTriplets){
-		cat(paste(label1, label2, label3, sep="\t"), file="triplets.txt", append=T, sep="", fill=3)
+    cat(paste(label1, label2, label3, sep="\t"), file="triplets.txt", append=T, sep="", fill=3)
   }
   for(iter in 1:length(product[,1])){
     threshhold = product[iter,threshholdIndex]
     V_Segment = paste(".*", as.character(product[iter,V_SegmentIndex]), ".*", sep="")
     J_Segment = paste(".*", as.character(product[iter,J_SegmentIndex]), ".*", sep="")
     all = (grepl(V_Segment, patientMerge$V_Segment_Major_Gene.x) & grepl(J_Segment, patientMerge$J_Segment_Major_Gene.x) & patientMerge[,paste(on, ".x", sep="")] > threshhold & patientMerge[,paste(on, ".y", sep="")] > threshhold & patientMerge[,paste(on, ".z", sep="")] > threshhold)
-    one = (grepl(V_Segment, patient1$V_Segment_Major_Gene) & grepl(J_Segment, patient1$J_Segment_Major_Gene) & patient1[,on] > threshhold & !(patient1$Clone_Sequence %in% patientMerge[all,]$Clone_Sequence))
-    two = (grepl(V_Segment, patient2$V_Segment_Major_Gene) & grepl(J_Segment, patient2$J_Segment_Major_Gene) & patient2[,on] > threshhold & !(patient2$Clone_Sequence %in% patientMerge[all,]$Clone_Sequence))
-    three = (grepl(V_Segment, patient3$V_Segment_Major_Gene) & grepl(J_Segment, patient3$J_Segment_Major_Gene) & patient3[,on] > threshhold & !(patient3$Clone_Sequence %in% patientMerge[all,]$Clone_Sequence))
+    one = (grepl(V_Segment, patient1$V_Segment_Major_Gene) & grepl(J_Segment, patient1$J_Segment_Major_Gene) & patient1[,on] > threshhold & !(patient1$CDR3_Sense_Sequence %in% patientMerge[all,]$CDR3_Sense_Sequence))
+    two = (grepl(V_Segment, patient2$V_Segment_Major_Gene) & grepl(J_Segment, patient2$J_Segment_Major_Gene) & patient2[,on] > threshhold & !(patient2$CDR3_Sense_Sequence %in% patientMerge[all,]$CDR3_Sense_Sequence))
+    three = (grepl(V_Segment, patient3$V_Segment_Major_Gene) & grepl(J_Segment, patient3$J_Segment_Major_Gene) & patient3[,on] > threshhold & !(patient3$CDR3_Sense_Sequence %in% patientMerge[all,]$CDR3_Sense_Sequence))
     
     read1Count = append(read1Count, sum(patient1[one,]$normalized_read_count) + sum(patientMerge[all,]$normalized_read_count.x))
     read2Count = append(read2Count, sum(patient2[two,]$normalized_read_count) + sum(patientMerge[all,]$normalized_read_count.y))
@@ -243,27 +258,27 @@
     #threshhold = 0
     if(threshhold != 0){
       if(sum(one) > 0){
-        dfOne = patient1[one,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "Clone_Sequence", "Related_to_leukemia_clone")]
+        dfOne = patient1[one,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "CDR3_Sense_Sequence", "Related_to_leukemia_clone")]
         colnames(dfOne) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "Sequence", "Related_to_leukemia_clone")
         filenameOne = paste(label1, "_", product[iter, titleIndex], "_", threshhold, sep="")
         write.table(dfOne, file=paste(filenameOne, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
       }
       if(sum(two) > 0){
-        dfTwo = patient2[two,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "Clone_Sequence", "Related_to_leukemia_clone")]
+        dfTwo = patient2[two,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "CDR3_Sense_Sequence", "Related_to_leukemia_clone")]
         colnames(dfTwo) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "Sequence", "Related_to_leukemia_clone")
         filenameTwo = paste(label2, "_", product[iter, titleIndex], "_", threshhold, sep="")
         write.table(dfTwo, file=paste(filenameTwo, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
       }
       if(sum(three) > 0){
-        dfThree = patient3[three,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "Clone_Sequence", "Related_to_leukemia_clone")]
+        dfThree = patient3[three,c("V_Segment_Major_Gene", "J_Segment_Major_Gene", "normalized_read_count", "Frequency", "CDR3_Sense_Sequence", "Related_to_leukemia_clone")]
         colnames(dfThree) = c("Proximal segment", "Distal segment", "normalized_read_count", "Frequency", "Sequence", "Related_to_leukemia_clone")
         filenameThree = paste(label3, "_", product[iter, titleIndex], "_", threshhold, sep="")
         write.table(dfThree, file=paste(filenameThree, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
       }
     }
     if(sum(all) > 0){
-      dfAll = patientMerge[all,c("V_Segment_Major_Gene.x", "J_Segment_Major_Gene.x", "normalized_read_count.x", "Frequency.x", "Related_to_leukemia_clone.x", "Clone_Sequence", "V_Segment_Major_Gene.y", "J_Segment_Major_Gene.y", "normalized_read_count.y", "Frequency.y", "Related_to_leukemia_clone.y", "V_Segment_Major_Gene.z", "J_Segment_Major_Gene.z", "normalized_read_count.z", "Frequency.z", "Related_to_leukemia_clone.z")]
-      colnames(dfAll) = c(paste("Proximal segment", oneSample), paste("Distal segment", oneSample), paste("Normalized_Read_Count", oneSample), paste("Frequency", oneSample), paste("Related_to_leukemia_clone", oneSample),"Sequence", paste("Proximal segment", twoSample), paste("Distal segment", twoSample), paste("Normalized_Read_Count", twoSample), paste("Frequency", twoSample), paste("Related_to_leukemia_clone", twoSample), paste("Proximal segment", threeSample), paste("Distal segment", threeSample), paste("Normalized_Read_Count", threeSample), paste("Frequency", threeSample), paste("Related_to_leukemia_clone", threeSample))
+      dfAll = patientMerge[all,c("V_Segment_Major_Gene.x", "J_Segment_Major_Gene.x", "normalized_read_count.x", "Frequency.x", "Related_to_leukemia_clone.x", "CDR3_Sense_Sequence.x", "V_Segment_Major_Gene.y", "J_Segment_Major_Gene.y", "normalized_read_count.y", "Frequency.y", "Related_to_leukemia_clone.y", "V_Segment_Major_Gene.z", "J_Segment_Major_Gene.z", "normalized_read_count.z", "Frequency.z", "Related_to_leukemia_clone.z")]
+      colnames(dfAll) = c(paste("Proximal segment", oneSample), paste("Distal segment", oneSample), paste("Normalized_Read_Count", oneSample), paste("Frequency", oneSample), paste("Related_to_leukemia_clone", oneSample),"CDR3_Sense_Sequence", paste("Proximal segment", twoSample), paste("Distal segment", twoSample), paste("Normalized_Read_Count", twoSample), paste("Frequency", twoSample), paste("Related_to_leukemia_clone", twoSample), paste("Proximal segment", threeSample), paste("Distal segment", threeSample), paste("Normalized_Read_Count", threeSample), paste("Frequency", threeSample), paste("Related_to_leukemia_clone", threeSample))
       filenameAll = paste(label1, "_", label2, "_", label3, "_", product[iter, titleIndex], "_", threshhold, sep="")
       write.table(dfAll, file=paste(filenameAll, ".txt", sep=""), quote=F, sep="\t", dec=",", row.names=F, col.names=T)
     }
@@ -310,23 +325,41 @@
   dev.off()
 }
 
+
+triplets$uniqueID = "ID"
+
+triplets[grepl("16278_Left", triplets$Sample),]$uniqueID = "16278_26402_26759_Left"
+triplets[grepl("26402_Left", triplets$Sample),]$uniqueID = "16278_26402_26759_Left"
+triplets[grepl("26759_Left", triplets$Sample),]$uniqueID = "16278_26402_26759_Left"
+
+triplets[grepl("16278_Right", triplets$Sample),]$uniqueID = "16278_26402_26759_Right"
+triplets[grepl("26402_Right", triplets$Sample),]$uniqueID = "16278_26402_26759_Right"
+triplets[grepl("26759_Right", triplets$Sample),]$uniqueID = "16278_26402_26759_Right"
+
+triplets[grepl("14696", triplets$Patient),]$uniqueID = "14696"
+
+triplets = data.frame(data.table(triplets)[, list(Patient=unique(.SD$uniqueID), Clone_Molecule_Count_From_Spikes=sum(.SD$Clone_Molecule_Count_From_Spikes), Log10_Frequency=sum(.SD$Log10_Frequency), Total_Read_Count=sum(.SD$Total_Read_Count), Related_to_leukemia_clone=any(.SD$Related_to_leukemia_clone)), by=c("Sample", "Cell_Count", "J_Segment_Major_Gene", "V_Segment_Major_Gene", "CDR3_Sense_Sequence")])
+
+triplets$Frequency = (10^as.numeric(triplets$Log10_Frequency))*100
+triplets$normalized_read_count = round(triplets$Clone_Molecule_Count_From_Spikes / triplets$Cell_Count * 1000000 / 2)
+
 interval = intervalReads
 intervalOrder = data.frame("interval"=paste(">", interval, sep=""), "intervalOrder"=1:length(interval))
 product = data.frame("Titles"=rep(Titles, each=length(interval)), "interval"=rep(interval, times=10), "V_Segments"=rep(V_Segments, each=length(interval)), "J_Segments"=rep(J_Segments, each=length(interval)))
 
-one = dat[dat$Patient == "VanDongen_cALL_14696.1",]
-two = dat[dat$Patient == "VanDongen_cALL_14696.2",]
-three = dat[dat$Patient == "VanDongen_cALL_14696.3",]
+one = triplets[triplets$Sample == "14696_reg_BM",]
+two = triplets[triplets$Sample == "24536_reg_BM",]
+three = triplets[triplets$Sample == "24062_reg_BM",]
 tripletAnalysis(one, "14696_1", two, "14696_2", three, "14696_3", product=product, interval=interval, on="normalized_read_count", T)
 
-one = dat[dat$Sample == "16278_Left",]
-two = dat[dat$Sample == "26402_Left",]
-three = dat[dat$Sample == "26759_Left",]
+one = triplets[triplets$Sample == "16278_Left",]
+two = triplets[triplets$Sample == "26402_Left",]
+three = triplets[triplets$Sample == "26759_Left",]
 tripletAnalysis(one, "16278_Left", two, "26402_Left", three, "26759_Left", product=product, interval=interval, on="normalized_read_count", T)
 
-one = dat[dat$Sample == "16278_Right",]
-two = dat[dat$Sample == "26402_Right",]
-three = dat[dat$Sample == "26759_Right",]
+one = triplets[triplets$Sample == "16278_Right",]
+two = triplets[triplets$Sample == "26402_Right",]
+three = triplets[triplets$Sample == "26759_Right",]
 tripletAnalysis(one, "16278_Right", two, "26402_Right", three, "26759_Right", product=product, interval=interval, on="normalized_read_count", T)
 
 
@@ -334,20 +367,17 @@
 intervalOrder = data.frame("interval"=paste(">", interval, sep=""), "intervalOrder"=1:length(interval))
 product = data.frame("Titles"=rep(Titles, each=length(interval)), "interval"=rep(interval, times=10), "V_Segments"=rep(V_Segments, each=length(interval)), "J_Segments"=rep(J_Segments, each=length(interval)))
 
-one = dat[dat$Patient == "VanDongen_cALL_14696.1",]
-two = dat[dat$Patient == "VanDongen_cALL_14696.2",]
-three = dat[dat$Patient == "VanDongen_cALL_14696.3",]
+one = triplets[triplets$Sample == "14696_reg_BM",]
+two = triplets[triplets$Sample == "24536_reg_BM",]
+three = triplets[triplets$Sample == "24062_reg_BM",]
 tripletAnalysis(one, "14696_1", two, "14696_2", three, "14696_3", product=product, interval=interval, on="Frequency", F)
 
-one = dat[dat$Sample == "16278_Left",]
-two = dat[dat$Sample == "26402_Left",]
-three = dat[dat$Sample == "26759_Left",]
+one = triplets[triplets$Sample == "16278_Left",]
+two = triplets[triplets$Sample == "26402_Left",]
+three = triplets[triplets$Sample == "26759_Left",]
 tripletAnalysis(one, "16278_Left", two, "26402_Left", three, "26759_Left", product=product, interval=interval, on="Frequency", F)
 
-one = dat[dat$Sample == "16278_Right",]
-two = dat[dat$Sample == "26402_Right",]
-three = dat[dat$Sample == "26759_Right",]
+one = triplets[triplets$Sample == "16278_Right",]
+two = triplets[triplets$Sample == "26402_Right",]
+three = triplets[triplets$Sample == "26759_Right",]
 tripletAnalysis(one, "16278_Right", two, "26402_Right", three, "26759_Right", product=product, interval=interval, on="Frequency", F)
-
-
-
--- a/wrapper.sh	Thu Sep 18 10:28:24 2014 -0400
+++ b/wrapper.sh	Tue Sep 30 10:06:57 2014 -0400
@@ -29,7 +29,7 @@
 do
 	echo "$patient"
 	html="${patient}.html"
-	echo "$header" > $html
+	echo "$header" > "$html"
 	if [[ "$type" == *pair* ]] ; then
 		if [[ "$sample1" == *_BM* ]] || [[ "$sample1" == *_PB* ]] ; then
 			pairs_BM_PB+=( "$patient" )
@@ -45,128 +45,128 @@
 	sample1="$(echo ${sample1} | tr -d '\r' | tr -d '\n')"
 	sample2="$(echo ${sample2} | tr -d '\r' | tr -d '\n')"
 	tail -n+2 ${patient}_freq.txt | sed "s/>//" > tmp.txt
-	echo "<div class='tabber'>" >> $html
-	echo "<div class='tabbertab' title='Data frequency'>" >> $html
-	echo "<table><tr><td style='vertical-align:top;'>" >> $html
-	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_freq'>" >> $html
-	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_Both</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Sum number of sequences $patient</th><th>Percentage of sequences ${patient}_both</th></thead>" >> $html
-	echo "<tbody>" >> $html
+	echo "<div class='tabber'>" >> "$html"
+	echo "<div class='tabbertab' title='Data frequency'>" >> "$html"
+	echo "<table><tr><td style='vertical-align:top;'>" >> "$html"
+	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_freq'>" >> "$html"
+	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_Both</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Sum number of sequences $patient</th><th>Percentage of sequences ${patient}_both</th></thead>" >> "$html"
+	echo "<tbody>" >> "$html"
 	while read locus j_segment v_segment cut_off_value both one read_count1 two read_count2 sum percent locusreadsum1 locusreadsum2
 	do
 		if [ "$locus" != "$oldLocus" ] ; then
-			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> $html
-			echo "<tr><td><b>$locus</b></td>" >> $html
+			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> "$html"
+			echo "<tr><td><b>$locus</b></td>" >> "$html"
 		else
-			echo "<td></td>" >> $html
+			echo "<td></td>" >> "$html"
 		fi
-		echo "<td>$v_segment</td>" >> $html
-		echo "<td>$j_segment</td>" >> $html
-		echo "<td>>$cut_off_value</td>" >> $html 
+		echo "<td>$v_segment</td>" >> "$html"
+		echo "<td>$j_segment</td>" >> "$html"
+		echo "<td>>$cut_off_value</td>" >> "$html" 
 		if [ "$both" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$both</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$both</td>" >> "$html"
 		else
-			echo "<td>$both</td>" >> $html
+			echo "<td>$both</td>" >> "$html"
 		fi
 		if [ "$one" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$one</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$one</td>" >> "$html"
 		else
-			echo "<td>$one</td>" >> $html
+			echo "<td>$one</td>" >> "$html"
 		fi
-		echo "<td>$read_count1</td>" >> $html
+		echo "<td>$read_count1</td>" >> "$html"
 		if [ "$two" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$two</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$two</td>" >> "$html"
 		else
-			echo "<td>$two</td>" >> $html
+			echo "<td>$two</td>" >> "$html"
 		fi
-		echo "<td>$read_count2</td>" >> $html
-		echo "<td>$sum</td>" >> $html
-		echo "<td>${percent}&#37;</td>" >> $html
-		echo "</tr>" >> $html
+		echo "<td>$read_count2</td>" >> "$html"
+		echo "<td>$sum</td>" >> "$html"
+		echo "<td>${percent}&#37;</td>" >> "$html"
+		echo "</tr>" >> "$html"
 		oldLocus="$locus"	
 	done < tmp.txt
-	echo "</tbody></table>" >> $html
-	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_freq'></div></td></tr></table>" >> $html
-	echo "</div>" >> $html
-	echo "<div class='tabbertab' title='Graphs frequency'>" >> $html
-	echo "<a href='${patient}_freq.png'><img src='${patient}_freq.png' width='1280' height='720' /></a><br />" >> $html
-	echo "<a href='${patient}_freq_both.png'><img src='${patient}_freq_both.png' width='1280' height='720' /></a><br />" >> $html
-	echo "<a href='${patient}_percent_freq.png'><img src='${patient}_percent_freq.png' width='1280' height='720' /></a></div>" >> $html
+	echo "</tbody></table>" >> "$html"
+	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_freq'></div></td></tr></table>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "<div class='tabbertab' title='Graphs frequency'>" >> "$html"
+	echo "<a href='${patient}_freq.png'><img src='${patient}_freq.png' width='1280' height='720' /></a><br />" >> "$html"
+	echo "<a href='${patient}_freq_both.png'><img src='${patient}_freq_both.png' width='1280' height='720' /></a><br />" >> "$html"
+	echo "<a href='${patient}_percent_freq.png'><img src='${patient}_percent_freq.png' width='1280' height='720' /></a></div>" >> "$html"
 	
 	tail -n+2 ${patient}_reads.txt | sed "s/>//" > tmp.txt
-	echo "<div class='tabbertab' title='Data reads'>" >> $html
-	echo "<table><tr><td style='vertical-align:top;'>" >> $html
-	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_reads'>" >> $html
-	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_Both</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Sum number of sequences $patient</th><th>Percentage of sequences ${patient}_both</th></thead>" >> $html
-	echo "<tbody>" >> $html
+	echo "<div class='tabbertab' title='Data reads'>" >> "$html"
+	echo "<table><tr><td style='vertical-align:top;'>" >> "$html"
+	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_reads'>" >> "$html"
+	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_Both</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Sum number of sequences $patient</th><th>Percentage of sequences ${patient}_both</th></thead>" >> "$html"
+	echo "<tbody>" >> "$html"
 	while read locus j_segment v_segment cut_off_value both one read_count1 two read_count2 sum percent locusreadsum1 locusreadsum2
 	do
 		if [ "$locus" != "$oldLocus" ] ; then
-			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> $html
-			echo "<tr><td><b>$locus</b></td>" >> $html
+			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> "$html"
+			echo "<tr><td><b>$locus</b></td>" >> "$html"
 		else
-			echo "<td></td>" >> $html
+			echo "<td></td>" >> "$html"
 		fi
-		echo "<td>$v_segment</td>" >> $html
-		echo "<td>$j_segment</td>" >> $html
-		echo "<td>>$cut_off_value</td>" >> $html 
+		echo "<td>$v_segment</td>" >> "$html"
+		echo "<td>$j_segment</td>" >> "$html"
+		echo "<td>>$cut_off_value</td>" >> "$html" 
 		if [ "$both" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$both</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$both</td>" >> "$html"
 		else
-			echo "<td>$both</td>" >> $html
+			echo "<td>$both</td>" >> "$html"
 		fi
 		if [ "$one" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$one</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$one</td>" >> "$html"
 		else
-			echo "<td>$one</td>" >> $html
+			echo "<td>$one</td>" >> "$html"
 		fi
-		echo "<td>$read_count1</td>" >> $html
+		echo "<td>$read_count1</td>" >> "$html"
 		if [ "$two" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$two</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$two</td>" >> "$html"
 		else
-			echo "<td>$two</td>" >> $html
+			echo "<td>$two</td>" >> "$html"
 		fi
-		echo "<td>$read_count2</td>" >> $html
-		echo "<td>$sum</td>" >> $html
-		echo "<td>${percent}&#37;</td>" >> $html
-		echo "</tr>" >> $html
+		echo "<td>$read_count2</td>" >> "$html"
+		echo "<td>$sum</td>" >> "$html"
+		echo "<td>${percent}&#37;</td>" >> "$html"
+		echo "</tr>" >> "$html"
 		oldLocus="$locus"
 	done < tmp.txt
-	echo "</tbody></table>" >> $html
-	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_reads'></div></td></tr></table>" >> $html
-	echo "</div>" >> $html
-	echo "<div class='tabbertab' title='Graphs reads'>" >> $html
-	echo "<a href='${patient}_reads.png'><img src='${patient}_reads.png' width='1280' height='720' /></a><br />" >> $html
-	echo "<a href='${patient}_reads_both.png'><img src='${patient}_reads_both.png' width='1280' height='720' /></a><br />" >> $html
-	echo "<a href='${patient}_percent_reads.png'><img src='${patient}_percent_reads.png' width='1280' height='720' /></a></div>" >> $html
-	echo "</div>" >> $html
-	echo "</div>" >> $html
-	echo "</html>" >> $html
+	echo "</tbody></table>" >> "$html"
+	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_reads'></div></td></tr></table>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "<div class='tabbertab' title='Graphs reads'>" >> "$html"
+	echo "<a href='${patient}_reads.png'><img src='${patient}_reads.png' width='1280' height='720' /></a><br />" >> "$html"
+	echo "<a href='${patient}_reads_both.png'><img src='${patient}_reads_both.png' width='1280' height='720' /></a><br />" >> "$html"
+	echo "<a href='${patient}_percent_reads.png'><img src='${patient}_percent_reads.png' width='1280' height='720' /></a></div>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "</html>" >> "$html"
 done < patients.txt
 
 html="index.html"
 echo "<html>" > $html
-echo "<table>" >> $html
-echo "<tr><td><b>Singles:</b></td></tr>" >> $html
+echo "<table>" >> "$html"
+echo "<tr><td><b>Singles:</b></td></tr>" >> "$html"
 for patient in "${singles[@]}"
 do
-	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> $html
+	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> "$html"
 done
-echo "<tr><td><b>Pairs (Left & Right):</b></td></tr>" >> $html
+echo "<tr><td><b>Pairs (Left & Right):</b></td></tr>" >> "$html"
 for patient in "${pairs_Left_Right[@]}"
 do
-	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> $html
+	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> "$html"
 done
-echo "<tr><td><b>Pairs (BM & PB):</b></td></tr>" >> $html
+echo "<tr><td><b>Pairs (BM & PB):</b></td></tr>" >> "$html"
 for patient in "${pairs_BM_PB[@]}"
 do
-	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> $html
+	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> "$html"
 done
-echo "<tr><td><b>Pairs (Dx & R):</b></td></tr>" >> $html
+echo "<tr><td><b>Pairs (Dx & R):</b></td></tr>" >> "$html"
 for patient in "${pairs_R_Dx[@]}"
 do
-	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> $html
+	echo "<tr><td><a href='${patient}.html'>$patient</a></td></tr>" >> "$html"
 done
-echo "<tr><td><b>Triplets:</b></td></tr>" >> $html
+echo "<tr><td><b>Triplets:</b></td></tr>" >> "$html"
 
 while read sample1 sample2 sample3
 do
@@ -180,114 +180,114 @@
 	echo "$header" > $html
 	oldLocus=""
 	tail -n+2 ${patient}_freq.txt | sed "s/>//" > tmp.txt
-	echo "<div class='tabber'>" >> $html
-	echo "<div class='tabbertab' title='Data frequency'>" >> $html
-	echo "<table><tr><td style='vertical-align:top;'>" >> $html
-	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_freq'>" >> $html
-	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_All</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Number of sequences_$sample3</th><th>Read Count $sample3</th></thead>" >> $html
-	echo "<tbody>" >> $html
+	echo "<div class='tabber'>" >> "$html"
+	echo "<div class='tabbertab' title='Data frequency'>" >> "$html"
+	echo "<table><tr><td style='vertical-align:top;'>" >> "$html"
+	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_freq'>" >> "$html"
+	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_All</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Number of sequences_$sample3</th><th>Read Count $sample3</th></thead>" >> "$html"
+	echo "<tbody>" >> "$html"
 	while read locus j_segment v_segment cut_off_value all one read_count1 two read_count2 three read_count3
 	do
 		if [ "$locus" != "$oldLocus" ] ; then
-			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> $html
-			echo "<tr><td><b>$locus</b></td>" >> $html
+			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> "$html"
+			echo "<tr><td><b>$locus</b></td>" >> "$html"
 		else
-			echo "<td></td>" >> $html
+			echo "<td></td>" >> "$html"
 		fi
-		echo "<td>$v_segment</td>" >> $html
-		echo "<td>$j_segment</td>" >> $html
-		echo "<td>>$cut_off_value</td>" >> $html 
+		echo "<td>$v_segment</td>" >> "$html"
+		echo "<td>$j_segment</td>" >> "$html"
+		echo "<td>>$cut_off_value</td>" >> "$html" 
 		if [ "$all" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$all</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$all</td>" >> "$html"
 		else
-			echo "<td>$all</td>" >> $html
+			echo "<td>$all</td>" >> "$html"
 		fi
 		if [ "$one" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$one</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$one</td>" >> "$html"
 		else
-			echo "<td>$one</td>" >> $html
+			echo "<td>$one</td>" >> "$html"
 		fi
-		echo "<td>$read_count1</td>" >> $html
+		echo "<td>$read_count1</td>" >> "$html"
 		if [ "$two" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$two</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$two</td>" >> "$html"
 		else
-			echo "<td>$two</td>" >> $html
+			echo "<td>$two</td>" >> "$html"
 		fi
-		echo "<td>$read_count2</td>" >> $html
+		echo "<td>$read_count2</td>" >> "$html"
 		if [ "$three" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$three</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"freq\")'>$three</td>" >> "$html"
 		else
-			echo "<td>$three</td>" >> $html
+			echo "<td>$three</td>" >> "$html"
 		fi
-		echo "<td>$read_count3</td>" >> $html
-		echo "</tr>" >> $html
+		echo "<td>$read_count3</td>" >> "$html"
+		echo "</tr>" >> "$html"
 		oldLocus="$locus"	
 	done < tmp.txt
-	echo "</tbody></table>" >> $html
-	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_freq'></div></td></tr></table>" >> $html
-	echo "</div>" >> $html
-	echo "<div class='tabbertab' title='Graphs frequency'>" >> $html
-	echo "<a href='${patient}_freq_total_all.png'><img src='${patient}_freq_total_all.png' width='1280' height='720' /></a><br />" >> $html
-	echo "<a href='${patient}_freq_indiv_all.png'><img src='${patient}_freq_indiv_all.png' width='1280' height='720' /></a><br /></div>" >> $html
+	echo "</tbody></table>" >> "$html"
+	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_freq'></div></td></tr></table>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "<div class='tabbertab' title='Graphs frequency'>" >> "$html"
+	echo "<a href='${patient}_freq_total_all.png'><img src='${patient}_freq_total_all.png' width='1280' height='720' /></a><br />" >> "$html"
+	echo "<a href='${patient}_freq_indiv_all.png'><img src='${patient}_freq_indiv_all.png' width='1280' height='720' /></a><br /></div>" >> "$html"
 	
 	tail -n+2 ${patient}_reads.txt | sed "s/>//" > tmp.txt
-	echo "<div class='tabbertab' title='Data reads'>" >> $html
-	echo "<table><tr><td style='vertical-align:top;'>" >> $html
-	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_reads'>" >> $html
-	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_All</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Number of sequences_$sample3</th><th>Read Count $sample3</th></thead>" >> $html
-	echo "<tbody>" >> $html
+	echo "<div class='tabbertab' title='Data reads'>" >> "$html"
+	echo "<table><tr><td style='vertical-align:top;'>" >> "$html"
+	echo "<table border = 1 class='result_table summary_table' id='summary_table_${patient}_reads'>" >> "$html"
+	echo "<thead><th>Ig/TCR gene rearrangement type</th><th>Proximal gene segment</th><th>Distal gene segment</th><th>Cut off value</th><th>Number of sequences ${patient}_All</th><th>Number of sequences_$sample1</th><th>Read Count $sample1</th><th>Number of sequences_$sample2</th><th>Read Count $sample2</th><th>Number of sequences_$sample3</th><th>Read Count $sample3</th></thead>" >> "$html"
+	echo "<tbody>" >> "$html"
 	while read locus j_segment v_segment cut_off_value all one read_count1 two read_count2 three read_count3 
 	do
 		if [ "$locus" != "$oldLocus" ] ; then
-			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> $html
-			echo "<tr><td><b>$locus</b></td>" >> $html
+			echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>" >> "$html"
+			echo "<tr><td><b>$locus</b></td>" >> "$html"
 		else
-			echo "<td></td>" >> $html
+			echo "<td></td>" >> "$html"
 		fi
-		echo "<td>$v_segment</td>" >> $html
-		echo "<td>$j_segment</td>" >> $html
-		echo "<td>>$cut_off_value</td>" >> $html 
+		echo "<td>$v_segment</td>" >> "$html"
+		echo "<td>$j_segment</td>" >> "$html"
+		echo "<td>>$cut_off_value</td>" >> "$html" 
 		if [ "$all" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$all</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${sample2}_${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$all</td>" >> "$html"
 		else
-			echo "<td>$all</td>" >> $html
+			echo "<td>$all</td>" >> "$html"
 		fi
 		if [ "$one" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$one</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample1}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$one</td>" >> "$html"
 		else
-			echo "<td>$one</td>" >> $html
+			echo "<td>$one</td>" >> "$html"
 		fi
-		echo "<td>$read_count1</td>" >> $html
+		echo "<td>$read_count1</td>" >> "$html"
 		if [ "$two" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$two</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample2}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$two</td>" >> "$html"
 		else
-			echo "<td>$two</td>" >> $html
+			echo "<td>$two</td>" >> "$html"
 		fi
-		echo "<td>$read_count2</td>" >> $html
+		echo "<td>$read_count2</td>" >> "$html"
 		if [ "$three" != "0" ] && [ "$cut_off_value" != "0" ] ; then
-			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$three</td>" >> $html
+			echo "<td data-patient='${patient}' style='cursor:pointer' onclick='javascript:loadfile(\"${sample3}_${locus}_${cut_off_value}.txt\", \"$patient\", \"reads\")'>$three</td>" >> "$html"
 		else
-			echo "<td>$three</td>" >> $html
+			echo "<td>$three</td>" >> "$html"
 		fi
-		echo "<td>$read_count3</td>" >> $html
-		echo "</tr>" >> $html
+		echo "<td>$read_count3</td>" >> "$html"
+		echo "</tr>" >> "$html"
 		oldLocus="$locus"
 	done < tmp.txt
-	echo "</tbody></table>" >> $html
-	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_reads'></div></td></tr></table>" >> $html
-	echo "</div>" >> $html
-	echo "<div class='tabbertab' title='Graphs reads'>" >> $html
-	echo "<a href='${patient}_reads_total_all.png'><img src='${patient}_reads_total_all.png' width='1280' height='720' /></a><br />" >> $html
-	echo "<a href='${patient}_reads_indiv_all.png'><img src='${patient}_reads_indiv_all.png' width='1280' height='720' /></a><br /></div>" >> $html
-	echo "</div>" >> $html
-	echo "</div>" >> $html
-	echo "</html>" >> $html
+	echo "</tbody></table>" >> "$html"
+	echo "</td><td style='vertical-align:top;'><div id='result_div_${patient}_reads'></div></td></tr></table>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "<div class='tabbertab' title='Graphs reads'>" >> "$html"
+	echo "<a href='${patient}_reads_total_all.png'><img src='${patient}_reads_total_all.png' width='1280' height='720' /></a><br />" >> "$html"
+	echo "<a href='${patient}_reads_indiv_all.png'><img src='${patient}_reads_indiv_all.png' width='1280' height='720' /></a><br /></div>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "</div>" >> "$html"
+	echo "</html>" >> "$html"
 done < triplets.txt
 rm tmp.txt
 
 
 html="index.html"
 
-echo "</table>" >> $html
-echo "</html>" >> $html
+echo "</table>" >> "$html"
+echo "</html>" >> "$html"