changeset 43:77a7ac76c7b9 draft

Uploaded
author davidvanzessen
date Tue, 11 Apr 2017 08:02:17 -0400
parents 1cf60ae234b4
children 716622f5bb4f
files plot_pdf.r shm_csr.py shm_csr.r wrapper.sh
diffstat 4 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plot_pdf.r	Tue Apr 11 08:02:17 2017 -0400
@@ -0,0 +1,17 @@
+library(ggplot2)
+
+args <- commandArgs(trailingOnly = TRUE)
+print(args)
+
+input = args[1]
+outputdir = args[2]
+setwd(outputdir)
+
+load(input)
+
+print(names(pdfplots))
+
+for(n in names(pdfplots)){
+    print(paste("n:", n))
+    ggsave(pdfplots[[n]], file=n, device="pdf")
+}
--- a/shm_csr.py	Tue Mar 28 08:25:36 2017 -0400
+++ b/shm_csr.py	Tue Apr 11 08:02:17 2017 -0400
@@ -80,7 +80,7 @@
 		
 		IDlist += [ID]
 
-print mutationList, linecount
+#print mutationList, linecount
 
 AALength = (int(max(mutationList, key=lambda i: int(i[4]) if i[4] else 0)[4]) + 1)  # [4] is the position of the AA mutation, None if silent
 if AALength < 60:
--- a/shm_csr.r	Tue Mar 28 08:25:36 2017 -0400
+++ b/shm_csr.r	Tue Apr 11 08:02:17 2017 -0400
@@ -124,6 +124,8 @@
 	regions = c("CDR2", "FR3")
 }
 
+pdfplots = list() #save() this later to create the pdf plots in another script (maybe avoids the "address (nil), cause memory not mapped")
+
 sum_by_row = function(x, columns) { sum(as.numeric(x[columns]), na.rm=T) }
 
 print("aggregating data into new columns")
@@ -308,7 +310,7 @@
 			print(p)
 			dev.off()
 			
-			ggsave(paste("transitions_stacked_", name, ".pdf", sep=""))
+			pdfplots[[paste("transitions_stacked_", name, ".pdf", sep="")]] <<- p
 			
 			png(filename=paste("transitions_heatmap_", name, ".png", sep=""))
 			p = ggplot(transition2, aes(factor(reorder(variable, -order.y)), factor(reorder(id, -order.x)))) + geom_tile(aes(fill = value)) + scale_fill_gradient(low="white", high="steelblue") #heatmap
@@ -316,7 +318,7 @@
 			print(p)
 			dev.off()
 			
-			ggsave(paste("transitions_heatmap_", name, ".pdf", sep=""))
+			pdfplots[[paste("transitions_heatmap_", name, ".pdf", sep="")]] <<- p
 		} else {
 			#print("No data to plot")
 		}
@@ -400,7 +402,7 @@
 	print(pc)
 	dev.off()
 	
-	ggsave("IGA.pdf", pc)
+	pdfplots[["IGA.pdf"]] <- pc	
 }
 
 print("Plotting IGG piechart")
@@ -423,7 +425,7 @@
 	print(pc)
 	dev.off()
 	
-	ggsave("IGG.pdf", pc)
+	pdfplots[["IGG.pdf"]] <- pc	
 }
 
 print("Plotting scatterplot")
@@ -445,7 +447,7 @@
 print(p)
 dev.off()
 
-ggsave("scatter.pdf", p)
+pdfplots[["scatter.pdf"]] <- p
 
 write.table(dat[,c("Sequence.ID", "best_match", "VRegionMutations", "VRegionNucleotides", "percentage_mutations")], "scatter.txt", sep="\t",quote=F,row.names=F,col.names=T)
 
@@ -471,7 +473,9 @@
 print(p)
 dev.off()
 
-ggsave("frequency_ranges.pdf", p)
+pdfplots[["frequency_ranges.pdf"]] <- p
+
+save(pdfplots, file="pdfplots.RData")
 
 frequency_bins_data_by_class = frequency_bins_data
 
--- a/wrapper.sh	Tue Mar 28 08:25:36 2017 -0400
+++ b/wrapper.sh	Tue Apr 11 08:02:17 2017 -0400
@@ -176,6 +176,13 @@
 echo "R mutation analysis"
 Rscript $dir/shm_csr.r $outdir/merged.txt $classes $outdir ${empty_region_filter} 2>&1
 
+echo "---------------- plot_pdfs.r ----------------"
+echo "---------------- plot_pdfs.r ----------------<br />" >> $log
+
+echo "Rscript $dir/shm_csr.r $outdir/pdfplots.RData $outdir 2>&1"
+
+Rscript $dir/plot_pdf.r "$outdir/pdfplots.RData" "$outdir" 2>&1
+
 echo "---------------- shm_csr.py ----------------"
 echo "---------------- shm_csr.py ----------------<br />" >> $log
 
@@ -249,7 +256,7 @@
 	echo "---------------- pattern_plots.r ----------------"
 	echo "---------------- pattern_plots.r ----------------<br />" >> $log
 
-	Rscript $dir/pattern_plots.r $outdir/data_${func}.txt $outdir/aid_motives $outdir/relative_mutations $outdir/abolute_mutations $outdir/shm_overview.txt 2>&1
+	Rscript $dir/pattern_plots.r $outdir/data_${func}.txt $outdir/aid_motives $outdir/relative_mutations $outdir/absolute_mutations $outdir/shm_overview.txt 2>&1
 	
 	echo "<table class='pure-table pure-table-striped'>" >> $output
 	echo "<thead><tr><th>info</th>" >> $output
@@ -300,7 +307,7 @@
 
 echo "<a href='aid_motives.pdf'><img src='aid_motives.png' /></a><br />" >> $output
 echo "<a href='relative_mutations.pdf'><img src='relative_mutations.png' /></a><br />" >> $output
-echo "<a href='abolute_mutations.pdf'><img src='abolute_mutations.png' /></a><br />" >> $output
+echo "<a href='absolute_mutations.pdf'><img src='absolute_mutations.png' /></a><br />" >> $output
 echo "<br />" >> $output
 cat $dir/shm_overview.htm >> $output
 echo "</div>" >> $output #SHM overview tab end
@@ -657,7 +664,7 @@
 echo "<tr><td>Base count for every sequence</td><td><a href='base_overview.html'>View</a></td></tr>" >> $output
 echo "<tr><td>The data used to generate the percentage of mutations in AID and pol eta motives plot</td><td><a href='aid_motives.txt' download='aid_motives.txt' >Download</a></td></tr>" >> $output
 echo "<tr><td>The data used to generate the relative mutation patterns plot</td><td><a href='relative_mutations.txt' download='relative_mutations.txt' >Download</a></td></tr>" >> $output
-echo "<tr><td>The data used to generate the absolute mutation patterns plot</td><td><a href='absolute_mutations.txt' download='abolute_mutations.txt' >Download</a></td></tr>" >> $output
+echo "<tr><td>The data used to generate the absolute mutation patterns plot</td><td><a href='absolute_mutations.txt' download='absolute_mutations.txt' >Download</a></td></tr>" >> $output
 
 echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>SHM Frequency</td></tr>" >> $output
 echo "<tr><td>The data  generate the frequency scatter plot</td><td><a href='scatter.txt' download='scatter.txt' >Download</a></td></tr>" >> $output