Mercurial > repos > davidvanzessen > mutation_analysis
comparison mutation_analysis.r @ 119:626a956f3811 draft
Uploaded
| author | davidvanzessen |
|---|---|
| date | Thu, 11 Aug 2016 10:35:52 -0400 |
| parents | ad7ca9c2b748 |
| children | 613278c1bde0 |
comparison
equal
deleted
inserted
replaced
| 118:ad7ca9c2b748 | 119:626a956f3811 |
|---|---|
| 274 transition2 = merge(transition2, base.order, by.x="id", by.y="base") | 274 transition2 = merge(transition2, base.order, by.x="id", by.y="base") |
| 275 transition2 = merge(transition2, base.order, by.x="variable", by.y="base") | 275 transition2 = merge(transition2, base.order, by.x="variable", by.y="base") |
| 276 | 276 |
| 277 transition2[is.na(transition2$value),]$value = 0 | 277 transition2[is.na(transition2$value),]$value = 0 |
| 278 | 278 |
| 279 png(filename=paste("transitions_stacked_", name, ".png", sep="")) | 279 if(!all(transition2$value == 0)){ #having rows of data but a transition table filled with 0 is bad |
| 280 p = ggplot(transition2, aes(factor(reorder(id, order.x)), y=value, fill=factor(reorder(variable, order.y)))) + geom_bar(position="fill", stat="identity") #stacked bar | 280 |
| 281 p = p + xlab("From base") + ylab("To base") + ggtitle("Mutations frequency from base to base") + guides(fill=guide_legend(title=NULL)) | 281 print("Plotting stacked transition") |
| 282 print(p) | 282 |
| 283 dev.off() | 283 print(transition2) |
| 284 | 284 |
| 285 png(filename=paste("transitions_heatmap_", name, ".png", sep="")) | 285 png(filename=paste("transitions_stacked_", name, ".png", sep="")) |
| 286 p = ggplot(transition2, aes(factor(reorder(id, order.x)), factor(reorder(variable, order.y)))) + geom_tile(aes(fill = value), colour="white") + scale_fill_gradient(low="white", high="steelblue") #heatmap | 286 p = ggplot(transition2, aes(factor(reorder(id, order.x)), y=value, fill=factor(reorder(variable, order.y)))) + geom_bar(position="fill", stat="identity") #stacked bar |
| 287 p = p + xlab("From base") + ylab("To base") + ggtitle("Mutations frequency from base to base") | 287 p = p + xlab("From base") + ylab("To base") + ggtitle("Mutations frequency from base to base") + guides(fill=guide_legend(title=NULL)) |
| 288 print(p) | 288 print(p) |
| 289 dev.off() | 289 dev.off() |
| 290 | |
| 291 print("Plotting heatmap transition") | |
| 292 | |
| 293 png(filename=paste("transitions_heatmap_", name, ".png", sep="")) | |
| 294 p = ggplot(transition2, aes(factor(reorder(id, order.x)), factor(reorder(variable, order.y)))) + geom_tile(aes(fill = value), colour="white") + scale_fill_gradient(low="white", high="steelblue") #heatmap | |
| 295 p = p + xlab("From base") + ylab("To base") + ggtitle("Mutations frequency from base to base") | |
| 296 print(p) | |
| 297 dev.off() | |
| 298 } else { | |
| 299 print("No data to plot") | |
| 300 } | |
| 290 } | 301 } |
| 291 | 302 |
| 292 #print(paste("writing value file: ", name, "_", fname, "_value.txt" ,sep="")) | 303 #print(paste("writing value file: ", name, "_", fname, "_value.txt" ,sep="")) |
| 293 | 304 |
| 294 write.table(x=transitionTable, file=paste("transitions_", name ,"_", fname, ".txt", sep=""), sep=",",quote=F,row.names=T,col.names=NA) | 305 write.table(x=transitionTable, file=paste("transitions_", name ,"_", fname, ".txt", sep=""), sep=",",quote=F,row.names=T,col.names=NA) |
