comparison mutational_patterns.R @ 6:2c1d58f5c296 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 93dc5ba0403cb447a78e466f568234bd1be9e31a"
author artbio
date Fri, 09 Oct 2020 17:06:51 +0000
parents fe31d059a482
children 34626b2b9907
comparison
equal deleted inserted replaced
5:fe31d059a482 6:2c1d58f5c296
244 pc3 <- ggplot(pc3_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) + 244 pc3 <- ggplot(pc3_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) +
245 geom_bar(stat="identity", position='stack') + 245 geom_bar(stat="identity", position='stack') +
246 coord_flip() + 246 coord_flip() +
247 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) + 247 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) +
248 labs(x = "Samples", y = "Absolute contribution") + theme_bw() + 248 labs(x = "Samples", y = "Absolute contribution") + theme_bw() +
249 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right") 249 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right",
250 text = element_text(size=8),
251 axis.text.x = element_text(angle=90, hjust=1))
250 pc4_data <- pc4$data 252 pc4_data <- pc4$data
251 pc4 <- ggplot(pc4_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) + 253 pc4 <- ggplot(pc4_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) +
252 geom_bar(stat="identity", position='fill') + 254 geom_bar(stat="identity", position='fill') +
253 coord_flip() + 255 coord_flip() +
254 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) + 256 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) +
255 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + 257 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
256 labs(x = "Samples", y = "Relative contribution") + theme_bw() + 258 labs(x = "Samples", y = "Relative contribution") + theme_bw() +
257 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right") 259 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right",
260 text = element_text(size=8),
261 axis.text.x = element_text(angle=90, hjust=1))
258 ##### 262 #####
259 # ggplot2 alternative 263 # ggplot2 alternative
260 if (!is.na(opt$levels)[1]) { # if there are levels to display in graphs 264 if (!is.na(opt$levels)[1]) { # if there are levels to display in graphs
261 pc3_data <- pc3$data 265 pc3_data <- pc3$data
262 pc3_data <- merge (pc3_data, metadata_table[,c(1,3)], by.x="Sample", by.y="element_identifier") 266 pc3_data <- merge (pc3_data, metadata_table[,c(1,3)], by.x="Sample", by.y="element_identifier")
263 pc3 <- ggplot(pc3_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) + 267 pc3 <- ggplot(pc3_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) +
264 geom_bar(stat="identity", position='stack') + 268 geom_bar(stat="identity", position='stack') +
265 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) + 269 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) +
266 labs(x = "Samples", y = "Absolute contribution") + theme_bw() + 270 labs(x = "Samples", y = "Absolute contribution") + theme_bw() +
267 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right") + 271 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right",
272 text = element_text(size=8),
273 axis.text.x = element_text(angle=90, hjust=1)) +
268 facet_grid(~level, scales = "free_x") 274 facet_grid(~level, scales = "free_x")
269 pc4_data <- pc4$data 275 pc4_data <- pc4$data
270 pc4_data <- merge (pc4_data, metadata_table[,c(1,3)], by.x="Sample", by.y="element_identifier") 276 pc4_data <- merge (pc4_data, metadata_table[,c(1,3)], by.x="Sample", by.y="element_identifier")
271 pc4 <- ggplot(pc4_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) + 277 pc4 <- ggplot(pc4_data, aes(x=Sample, y=Contribution, fill=as.factor(Signature))) +
272 geom_bar(stat="identity", position='fill') + 278 geom_bar(stat="identity", position='fill') +
273 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) + 279 scale_fill_manual(name = "Cosmic\nSignatures", values = cosmic_colors) +
274 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + 280 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
275 labs(x = "Samples", y = "Relative contribution") + theme_bw() + 281 labs(x = "Samples", y = "Relative contribution") + theme_bw() +
276 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right") + 282 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position="right",
283 text = element_text(size=8),
284 axis.text.x = element_text(angle=90, hjust=1)) +
277 facet_grid(~level, scales = "free_x") 285 facet_grid(~level, scales = "free_x")
278 } 286 }
279 # Combine the two plots: 287 # Combine the two plots:
280 grid.arrange(pc3, pc4, top = textGrob("Absolute and Relative Contributions of Cosmic signatures to mutational patterns",gp=gpar(fontsize=12,font=3))) 288 grid.arrange(pc3, pc4, top = textGrob("Absolute and Relative Contributions of Cosmic signatures to mutational patterns",gp=gpar(fontsize=12,font=3)))
281 289