diff report_clonality/RScript.r @ 43:2325074a8461 draft

Uploaded
author davidvanzessen
date Thu, 26 Oct 2017 09:58:05 -0400
parents 9a47d7a552d6
children 1d8728f3ff37
line wrap: on
line diff
--- a/report_clonality/RScript.r	Thu Oct 26 09:08:37 2017 -0400
+++ b/report_clonality/RScript.r	Thu Oct 26 09:58:05 2017 -0400
@@ -988,39 +988,44 @@
 median.aa.l = data.frame(data.table(PRODF)[, list(median=as.double(median(as.numeric(.SD$CDR3.Length, na.rm=T), na.rm=T))), by=c("Sample")])
 write.table(median.aa.l, "AAMedianBySample.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F)
 
-
-#generate the "Sequences that are present in more than one replicate" dataset
-clonaltype.in.replicates = inputdata
-clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$Functionality %in% c("productive (see comment)","productive"),]
-clonaltype.in.replicates = clonaltype.in.replicates[!(is.na(clonaltype.in.replicates$ID) | is.na(clonaltype.in.replicates$Top.V.Gene) | is.na(clonaltype.in.replicates$Top.J.Gene)),]
-clonaltype = unlist(strsplit(clonaltype, ","))
+if(clonaltype != "none"){
+	#generate the "Sequences that are present in more than one replicate" dataset
+	clonaltype.in.replicates = inputdata
+	clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$Functionality %in% c("productive (see comment)","productive"),]
+	clonaltype.in.replicates = clonaltype.in.replicates[!(is.na(clonaltype.in.replicates$ID) | is.na(clonaltype.in.replicates$Top.V.Gene) | is.na(clonaltype.in.replicates$Top.J.Gene)),]
+	clonaltype = unlist(strsplit(clonaltype, ","))
 
-clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[c(clonaltype, "Replicate")], sep = ":"))
+	clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[paste_columns], sep = ":"))
 
-clonaltype.in.replicates = clonaltype.in.replicates[!duplicated(clonaltype.in.replicates$clonaltype),]
+	clonaltype.in.replicates = clonaltype.in.replicates[!duplicated(clonaltype.in.replicates$clonaltype),]
 
-clonaltype = clonaltype[-which(clonaltype == "Sample")]
+	clonaltype = clonaltype[-which(clonaltype == "Sample")]
 
-clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[clonaltype], sep = ":"))
-clonaltype.in.replicates = clonaltype.in.replicates[,c("clonaltype","Replicate", "ID", "Sequence", "Sample")]
+	clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[clonaltype], sep = ":"))
+	clonaltype.in.replicates = clonaltype.in.replicates[,c("clonaltype","Replicate", "ID", "Sequence", "Sample")]
 
 
-write.table(clonaltype.in.replicates, "clonaltypes_replicates_before_table.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
+	write.table(clonaltype.in.replicates, "clonaltypes_replicates_before_table.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
 
-clonaltype.counts = data.frame(table(clonaltype.in.replicates$clonaltype))
+	clonaltype.counts = data.frame(table(clonaltype.in.replicates$clonaltype))
 
-write.table(clonaltype.counts, "clonaltypes_counts.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
+	write.table(clonaltype.counts, "clonaltypes_counts.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
 
-names(clonaltype.counts) = c("clonaltype", "coincidence")
+	names(clonaltype.counts) = c("clonaltype", "coincidence")
 
-clonaltype.counts = clonaltype.counts[clonaltype.counts$coincidence > 1,]
+	clonaltype.counts = clonaltype.counts[clonaltype.counts$coincidence > 1,]
 
-clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$clonaltype %in% clonaltype.counts$clonaltype,]
-clonaltype.in.replicates = merge(clonaltype.in.replicates, clonaltype.counts, by="clonaltype")
-clonaltype.in.replicates = clonaltype.in.replicates[order(-clonaltype.in.replicates$coincidence, clonaltype.in.replicates$clonaltype, clonaltype.in.replicates$Replicate),c("coincidence","clonaltype", "Sample", "Replicate", "ID", "Sequence")]
+	clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$clonaltype %in% clonaltype.counts$clonaltype,]
+	clonaltype.in.replicates = merge(clonaltype.in.replicates, clonaltype.counts, by="clonaltype")
+	clonaltype.in.replicates = clonaltype.in.replicates[order(-clonaltype.in.replicates$coincidence, clonaltype.in.replicates$clonaltype, clonaltype.in.replicates$Replicate),c("coincidence","clonaltype", "Sample", "Replicate", "ID", "Sequence")]
 
 
-write.table(clonaltype.in.replicates, "clonaltypes_replicates.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
+	write.table(clonaltype.in.replicates, "clonaltypes_replicates.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
+} else {
+	cat("No clonaltype", file="clonaltypes_replicates_before_table.txt")
+	cat("No clonaltype", file="clonaltypes_counts.txt")
+	cat("No clonaltype", file="clonaltypes_replicates.txt")
+}