diff report_clonality/RScript.r @ 32:7c33029fd63d draft

Uploaded
author davidvanzessen
date Tue, 28 Mar 2017 05:40:04 -0400
parents b50965edac24
children f37e072affc0
line wrap: on
line diff
--- a/report_clonality/RScript.r	Tue Mar 14 06:51:38 2017 -0400
+++ b/report_clonality/RScript.r	Tue Mar 28 05:40:04 2017 -0400
@@ -302,7 +302,9 @@
 
 png("VPlot.png",width = 1280, height = 720)
 pV
-dev.off();
+dev.off()
+
+ggsave("VPlot.pdf", pV, width=13, height=7)
 
 if(useD){
   pD = ggplot(PRODFD)
@@ -313,7 +315,9 @@
   
   png("DPlot.png",width = 800, height = 600)
   print(pD)
-  dev.off();
+  dev.off()
+  
+  ggsave("DPlot.pdf", pD, width=10, height=7)
 }
 
 pJ = ggplot(PRODFJ)
@@ -324,7 +328,9 @@
 
 png("JPlot.png",width = 800, height = 600)
 pJ
-dev.off();
+dev.off()
+
+ggsave("JPlot.pdf", pJ)
 
 # ---------------------- Now the frequency plots of the V, D and J families ----------------------
 
@@ -344,7 +350,9 @@
   theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank())
 png("VFPlot.png")
 VPlot
-dev.off();
+dev.off()
+ggsave("VFPlot.pdf", VPlot)
+
 write.table(x=VGenes, file="VFFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T)
 
 if(useD){
@@ -362,7 +370,9 @@
     theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank())
   png("DFPlot.png")
   print(DPlot)
-  dev.off();
+  dev.off()
+  
+  ggsave("DFPlot.pdf", DPlot)
   write.table(x=DGenes, file="DFFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T)
 }
 
@@ -384,6 +394,9 @@
 png("CDR3LengthPlot.png",width = 1280, height = 720)
 CDR3LengthPlot
 dev.off()
+
+ggsave("CDR3LengthPlot.pdf", CDR3LengthPlot, width=12, height=7)
+
 write.table(x=CDR3Length, file="CDR3LengthPlot.txt", sep="\t",quote=F,row.names=F,col.names=T)
 
 # ---------------------- Plot the heatmaps ----------------------
@@ -413,6 +426,9 @@
     png(paste("HeatmapVD_", unique(dat[3])[1,1] , ".png", sep=""), width=150+(15*length(Dchain$v.name)), height=100+(15*length(Vchain$v.name)))
     print(img)
     dev.off()
+    
+    ggsave(paste("HeatmapVD_", unique(dat[3])[1,1] , ".pdf", sep=""), img, height=13, width=8)
+    
     write.table(x=acast(dat, Top.V.Gene~Top.D.Gene, value.var="Length"), file=paste("HeatmapVD_", unique(dat[3])[1,1], ".txt", sep=""), sep="\t",quote=F,row.names=T,col.names=NA)
   }
   
@@ -463,6 +479,9 @@
   png(paste("HeatmapVJ_", unique(dat[3])[1,1] , ".png", sep=""), width=150+(15*length(Jchain$v.name)), height=100+(15*length(Vchain$v.name)))
   print(img)
   dev.off()
+  
+  ggsave(paste("HeatmapVJ_", unique(dat[3])[1,1] , ".pdf", sep=""), img, height=11, width=4)
+  
   write.table(x=acast(dat, Top.V.Gene~Top.J.Gene, value.var="Length"), file=paste("HeatmapVJ_", unique(dat[3])[1,1], ".txt", sep=""), sep="\t",quote=F,row.names=T,col.names=NA)
 }
 
@@ -512,6 +531,9 @@
     png(paste("HeatmapDJ_", unique(dat[3])[1,1] , ".png", sep=""), width=150+(15*length(Jchain$v.name)), height=100+(15*length(Dchain$v.name)))
     print(img)
     dev.off()
+    
+    ggsave(paste("HeatmapDJ_", unique(dat[3])[1,1] , ".pdf", sep=""), img, width=4, height=7)
+    
     write.table(x=acast(dat, Top.D.Gene~Top.J.Gene, value.var="Length"), file=paste("HeatmapDJ_", unique(dat[3])[1,1], ".txt", sep=""), sep="\t",quote=F,row.names=T,col.names=NA)
   }
   
@@ -903,7 +925,7 @@
 D.REGION.reading.frame
 dev.off()
 
-
+ggsave("DReadingFrame.pdf", D.REGION.reading.frame)
 
 
 # ---------------------- AA composition in CDR3 ----------------------
@@ -937,11 +959,14 @@
 AAfreqplot = AAfreqplot + annotate("rect", xmin = 5.5, xmax = 6.5, ymin = 0, ymax = Inf, fill = "blue", alpha = 0.2)
 AAfreqplot = AAfreqplot + annotate("rect", xmin = 6.5, xmax = 7.5, ymin = 0, ymax = Inf, fill = "red", alpha = 0.2)
 AAfreqplot = AAfreqplot + ggtitle("Amino Acid Composition in the CDR3") + xlab("Amino Acid, from Hydrophilic (left) to Hydrophobic (right)") + ylab("Percentage") + scale_fill_manual(values=sample.colors)
-AAfreqplot = AAfreqplot + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank())
+AAfreqplot = AAfreqplot + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank())
 
 png("AAComposition.png",width = 1280, height = 720)
 AAfreqplot
 dev.off()
+
+ggsave("AAComposition.pdf", AAfreqplot, width=12, height=7)
+
 write.table(AAfreq, "AAComposition.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T)
 
 # ---------------------- AA median CDR3 length ----------------------