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

Uploaded
author davidvanzessen
date Thu, 26 Oct 2017 09:58:05 -0400
parents 9a47d7a552d6
children 1d8728f3ff37
comparison
equal deleted inserted replaced
42:9a47d7a552d6 43:2325074a8461
986 # ---------------------- AA median CDR3 length ---------------------- 986 # ---------------------- AA median CDR3 length ----------------------
987 987
988 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")]) 988 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")])
989 write.table(median.aa.l, "AAMedianBySample.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) 989 write.table(median.aa.l, "AAMedianBySample.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F)
990 990
991 991 if(clonaltype != "none"){
992 #generate the "Sequences that are present in more than one replicate" dataset 992 #generate the "Sequences that are present in more than one replicate" dataset
993 clonaltype.in.replicates = inputdata 993 clonaltype.in.replicates = inputdata
994 clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$Functionality %in% c("productive (see comment)","productive"),] 994 clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$Functionality %in% c("productive (see comment)","productive"),]
995 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)),] 995 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)),]
996 clonaltype = unlist(strsplit(clonaltype, ",")) 996 clonaltype = unlist(strsplit(clonaltype, ","))
997 997
998 clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[c(clonaltype, "Replicate")], sep = ":")) 998 clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[paste_columns], sep = ":"))
999 999
1000 clonaltype.in.replicates = clonaltype.in.replicates[!duplicated(clonaltype.in.replicates$clonaltype),] 1000 clonaltype.in.replicates = clonaltype.in.replicates[!duplicated(clonaltype.in.replicates$clonaltype),]
1001 1001
1002 clonaltype = clonaltype[-which(clonaltype == "Sample")] 1002 clonaltype = clonaltype[-which(clonaltype == "Sample")]
1003 1003
1004 clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[clonaltype], sep = ":")) 1004 clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[clonaltype], sep = ":"))
1005 clonaltype.in.replicates = clonaltype.in.replicates[,c("clonaltype","Replicate", "ID", "Sequence", "Sample")] 1005 clonaltype.in.replicates = clonaltype.in.replicates[,c("clonaltype","Replicate", "ID", "Sequence", "Sample")]
1006 1006
1007 1007
1008 write.table(clonaltype.in.replicates, "clonaltypes_replicates_before_table.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) 1008 write.table(clonaltype.in.replicates, "clonaltypes_replicates_before_table.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
1009 1009
1010 clonaltype.counts = data.frame(table(clonaltype.in.replicates$clonaltype)) 1010 clonaltype.counts = data.frame(table(clonaltype.in.replicates$clonaltype))
1011 1011
1012 write.table(clonaltype.counts, "clonaltypes_counts.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) 1012 write.table(clonaltype.counts, "clonaltypes_counts.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
1013 1013
1014 names(clonaltype.counts) = c("clonaltype", "coincidence") 1014 names(clonaltype.counts) = c("clonaltype", "coincidence")
1015 1015
1016 clonaltype.counts = clonaltype.counts[clonaltype.counts$coincidence > 1,] 1016 clonaltype.counts = clonaltype.counts[clonaltype.counts$coincidence > 1,]
1017 1017
1018 clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$clonaltype %in% clonaltype.counts$clonaltype,] 1018 clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$clonaltype %in% clonaltype.counts$clonaltype,]
1019 clonaltype.in.replicates = merge(clonaltype.in.replicates, clonaltype.counts, by="clonaltype") 1019 clonaltype.in.replicates = merge(clonaltype.in.replicates, clonaltype.counts, by="clonaltype")
1020 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")] 1020 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")]
1021 1021
1022 1022
1023 write.table(clonaltype.in.replicates, "clonaltypes_replicates.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) 1023 write.table(clonaltype.in.replicates, "clonaltypes_replicates.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
1024 1024 } else {
1025 1025 cat("No clonaltype", file="clonaltypes_replicates_before_table.txt")
1026 1026 cat("No clonaltype", file="clonaltypes_counts.txt")
1027 1027 cat("No clonaltype", file="clonaltypes_replicates.txt")
1028 1028 }
1029 1029
1030 1030
1031 1031
1032 1032
1033 1033
1034 1034
1035 1035
1036 1036
1037 1037
1038 1038
1039 1039
1040 1040
1041 1041
1042 1042
1043 1043
1044 1044
1045 1045
1046 1046
1047
1048
1049
1050
1051