changeset 24:9955b23db68c draft

Uploaded
author davidvanzessen
date Fri, 02 Dec 2016 05:51:13 -0500
parents 81453585dfc3
children 8d1c4c75f81b
files shm_csr.r
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/shm_csr.r	Thu Dec 01 09:32:06 2016 -0500
+++ b/shm_csr.r	Fri Dec 02 05:51:13 2016 -0500
@@ -177,7 +177,8 @@
 
 write.table(dat, input, sep="\t",quote=F,row.names=F,col.names=T)
 
-base.order = data.frame(base=c("A", "T", "C", "G"), order=1:4)
+base.order.x = data.frame(base=c("A", "C", "G", "T"), order.x=1:4)
+base.order.y = data.frame(base=c("T", "G", "C", "A"), order.y=1:4)
 
 calculate_result = function(i, gene, dat, matrx, f, fname, name){
 	tmp = dat[grepl(paste("^", gene, ".*", sep=""), dat$best_match),]
@@ -291,24 +292,24 @@
 		
 		transition2 = melt(transition, id.vars="id")
 
-		transition2 = merge(transition2, base.order, by.x="id", by.y="base")
+		transition2 = merge(transition2, base.order.x, by.x="id", by.y="base")
 
-		transition2 = merge(transition2, base.order, by.x="variable", by.y="base")
+		transition2 = merge(transition2, base.order.y, by.x="variable", by.y="base")
 
 		transition2[is.na(transition2$value),]$value = 0
 		
-		if(any(transition2$value != 0)){ #having rows of data but a transition table filled with 0 is bad
+		if(any(transition2$value != 0)){ #having a transition table filled with 0 is bad
 			print("Plotting heatmap and transition")
 			png(filename=paste("transitions_stacked_", name, ".png", sep=""))
 			p = ggplot(transition2, aes(factor(reorder(id, order.x)), y=value, fill=factor(reorder(variable, order.y)))) + geom_bar(position="fill", stat="identity", colour="black") #stacked bar
-			p = p + xlab("From base") + ylab("To base") + ggtitle("Mutations frequency from base to base") + guides(fill=guide_legend(title=NULL))
+			p = p + xlab("From base") + ylab("") + ggtitle("Mutations frequency from base to base") + guides(fill=guide_legend(title=NULL))
 			p = p + theme(panel.background = element_rect(fill = "white", colour="black"), text = element_text(size=16, colour="black")) + scale_fill_manual(values=c("A" = "blue4", "G" = "lightblue1", "C" = "olivedrab3", "T" = "olivedrab4"))
 			#p = p + scale_colour_manual(values=c("A" = "black", "G" = "black", "C" = "black", "T" = "black"))
 			print(p)
 			dev.off()
 			png(filename=paste("transitions_heatmap_", name, ".png", sep=""))
-			p = ggplot(transition2, aes(factor(reorder(id, order.x)), factor(reorder(variable, order.y)))) + geom_tile(aes(fill = value)) + scale_fill_gradient(low="white", high="steelblue") #heatmap
-			p = p + xlab("From base") + ylab("To base") + ggtitle("Mutations frequency from base to base")  + theme(panel.background = element_rect(fill = "white", colour="black"), text = element_text(size=13, colour="black"))
+			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
+			p = p + xlab("To base") + ylab("From Base") + ggtitle("Mutations frequency from base to base")  + theme(panel.background = element_rect(fill = "white", colour="black"), text = element_text(size=13, colour="black"))
 			print(p)
 			dev.off()
 		} else {