comparison report_clonality/RScript.r @ 3:beaa487ecf43 draft

Uploaded
author davidvanzessen
date Wed, 07 Dec 2016 08:36:23 -0500
parents 90a05ff900db
children
comparison
equal deleted inserted replaced
2:4f8a1d121384 3:beaa487ecf43
8 install.packages("ggplot2", repos="http://cran.xl-mirror.nl/") 8 install.packages("ggplot2", repos="http://cran.xl-mirror.nl/")
9 } 9 }
10 library(ggplot2) 10 library(ggplot2)
11 if (!("plyr" %in% rownames(installed.packages()))) { 11 if (!("plyr" %in% rownames(installed.packages()))) {
12 install.packages("plyr", repos="http://cran.xl-mirror.nl/") 12 install.packages("plyr", repos="http://cran.xl-mirror.nl/")
13 } 13 }
14 library(plyr) 14 library(plyr)
15 15
16 if (!("data.table" %in% rownames(installed.packages()))) { 16 if (!("data.table" %in% rownames(installed.packages()))) {
17 install.packages("data.table", repos="http://cran.xl-mirror.nl/") 17 install.packages("data.table", repos="http://cran.xl-mirror.nl/")
18 } 18 }
715 N2=mean(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 715 N2=mean(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
716 P4=mean(.SD$P5J.nt.nb, na.rm=T), 716 P4=mean(.SD$P5J.nt.nb, na.rm=T),
717 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), 717 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T),
718 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), 718 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)),
719 Total.N=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 719 Total.N=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
720 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T))), 720 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)),
721 Median.CDR3.l=median(.SD$CDR3.Length.DNA)),
721 by=c("Sample")]) 722 by=c("Sample")])
722 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) 723 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1)
723 write.table(newData, "junctionAnalysisProd_mean.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F) 724 write.table(newData, "junctionAnalysisProd_mean.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F)
724 725
725 newData = data.frame(data.table(PRODF)[,list(unique=.N, 726 newData = data.frame(data.table(PRODF)[,list(unique=.N,
733 N2=num_median(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 734 N2=num_median(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
734 P4=num_median(.SD$P5J.nt.nb, na.rm=T), 735 P4=num_median(.SD$P5J.nt.nb, na.rm=T),
735 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), 736 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T),
736 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), 737 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)),
737 Total.N=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 738 Total.N=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
738 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T))), 739 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)),
740 Median.CDR3.l=median(.SD$CDR3.Length.DNA)),
739 by=c("Sample")]) 741 by=c("Sample")])
740 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) 742 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1)
741 write.table(newData, "junctionAnalysisProd_median.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F) 743 write.table(newData, "junctionAnalysisProd_median.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F)
742 744
743 newData = data.frame(data.table(UNPROD)[,list(unique=.N, 745 newData = data.frame(data.table(UNPROD)[,list(unique=.N,
751 N2=mean(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 753 N2=mean(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
752 P4=mean(.SD$P5J.nt.nb, na.rm=T), 754 P4=mean(.SD$P5J.nt.nb, na.rm=T),
753 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), 755 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T),
754 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), 756 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)),
755 Total.N=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 757 Total.N=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
756 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T))), 758 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)),
759 Median.CDR3.l=median(.SD$CDR3.Length.DNA)),
757 by=c("Sample")]) 760 by=c("Sample")])
758 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) 761 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1)
759 write.table(newData, "junctionAnalysisUnProd_mean.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F) 762 write.table(newData, "junctionAnalysisUnProd_mean.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F)
760 763
761 newData = data.frame(data.table(UNPROD)[,list(unique=.N, 764 newData = data.frame(data.table(UNPROD)[,list(unique=.N,
769 N2=num_median(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 772 N2=num_median(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
770 P4=num_median(.SD$P5J.nt.nb, na.rm=T), 773 P4=num_median(.SD$P5J.nt.nb, na.rm=T),
771 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), 774 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T),
772 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), 775 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)),
773 Total.N=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), 776 Total.N=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)),
774 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T))), 777 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)),
778 Median.CDR3.l=median(.SD$CDR3.Length.DNA)),
775 by=c("Sample")]) 779 by=c("Sample")])
776 780
777 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) 781 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1)
778 write.table(newData, "junctionAnalysisUnProd_median.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F) 782 write.table(newData, "junctionAnalysisUnProd_median.csv" , sep=",",quote=F,na="-",row.names=F,col.names=F)
779 } 783 }