diff report_clonality/RScript.r @ 48:d08dfc8d5225 draft

Uploaded
author davidvanzessen
date Wed, 27 Jan 2016 10:36:35 -0500
parents d97e1421aa86
children 2a79f9adf89b
line wrap: on
line diff
--- a/report_clonality/RScript.r	Wed Jan 27 10:25:43 2016 -0500
+++ b/report_clonality/RScript.r	Wed Jan 27 10:36:35 2016 -0500
@@ -62,7 +62,9 @@
 #filter uniques
 inputdata.removed = inputdata[NULL,]
 
-if(filter_uniques == "yes" && c("CDR1.Seq", "CDR2.Seq", "CDR3.Seq", "FR1.IMGT", "FR2.IMGT", "FR3.IMGT") %in% names(inputdata)){
+filter_uniques = filter_uniques == "yes" && c("CDR1.Seq", "CDR2.Seq", "CDR3.Seq", "FR1.IMGT", "FR2.IMGT", "FR3.IMGT") %in% names(inputdata)
+
+if(filter_uniques){
 	
 	clmns = names(inputdata)
 	
@@ -177,12 +179,17 @@
 sample_productive_count$perc_unprod = round(sample_productive_count$Unproductive / sample_productive_count$All * 100)
 sample_productive_count$perc_unprod_un = round(sample_productive_count$Unproductive_unique / sample_productive_count$All * 100)
 
-inputdata.removed.s = data.table(inputdata.removed)[, list(UniqueRemoved=.N), by=c("Sample")]
+
+if(filter_uniques){
+	inputdata.removed.s = data.table(inputdata.removed)[, list(UniqueRemoved=.N), by=c("Sample")]
+
+	sample_productive_count = merge(sample_productive_count, inputdata.removed.s, by="Sample")
 
-sample_productive_count = merge(sample_productive_count, inputdata.removed.s, by="Sample")
-
-sample_productive_count$perc_rem = round(sample_productive_count$UniqueRemoved / sample_productive_count$All * 100)
-
+	sample_productive_count$perc_rem = round(sample_productive_count$UniqueRemoved / sample_productive_count$All * 100)
+} else {
+	sample_productive_count$UniqueRemoved = 0
+	sample_productive_count$perc_rem = 0
+}
 
 sample_replicate_productive_count = inputdata.dt[, list(All=.N, 
                                                         Productive = nrow(.SD[.SD$Functionality == "productive" | .SD$Functionality == "productive (see comment)",]), 
@@ -201,12 +208,17 @@
 sample_replicate_productive_count$perc_unprod = round(sample_replicate_productive_count$Unproductive / sample_replicate_productive_count$All * 100)
 sample_replicate_productive_count$perc_unprod_un = round(sample_replicate_productive_count$Unproductive_unique / sample_replicate_productive_count$All * 100)
 
-inputdata.removed.sr = data.table(inputdata.removed)[, list(UniqueRemoved=.N), by=c("samples_replicates")]
+
+if(filter_uniques){
+	inputdata.removed.sr = data.table(inputdata.removed)[, list(UniqueRemoved=.N), by=c("samples_replicates")]
+
+	sample_replicate_productive_count = merge(sample_replicate_productive_count, inputdata.removed.sr, by="samples_replicates")
 
-sample_replicate_productive_count = merge(sample_replicate_productive_count, inputdata.removed.sr, by="samples_replicates")
-
-sample_replicate_productive_count$perc_rem = round(sample_replicate_productive_count$UniqueRemoved / sample_productive_count$All * 100)
-
+	sample_replicate_productive_count$perc_rem = round(sample_replicate_productive_count$UniqueRemoved / sample_productive_count$All * 100)
+} else {
+	sample_replicate_productive_count$UniqueRemoved = 0
+	sample_replicate_productive_count$perc_rem = 0
+}
 
 setnames(sample_replicate_productive_count, colnames(sample_productive_count))