comparison mutational_patterns.R @ 23:83f8c93c34b4 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
author artbio
date Wed, 27 Oct 2021 00:46:47 +0000
parents 00be8f0b2c89
children ca6c19ee7da0
comparison
equal deleted inserted replaced
22:00be8f0b2c89 23:83f8c93c34b4
90 make_option( 90 make_option(
91 "--output_sigpattern", 91 "--output_sigpattern",
92 default = NA, 92 default = NA,
93 type = "character", 93 type = "character",
94 help = "path to output dataset" 94 help = "path to output dataset"
95 ),
96 make_option(
97 "--display_signatures",
98 default = NA,
99 type = "character",
100 help = "display input signature profiles if set to yes"
95 ), 101 ),
96 make_option( 102 make_option(
97 "--sig_contrib_matrix", 103 "--sig_contrib_matrix",
98 default = NA, 104 default = NA,
99 type = "character", 105 type = "character",
201 rownames(nmf_res$contribution) <- paste0("SBS", 1:opt$newsignum) 207 rownames(nmf_res$contribution) <- paste0("SBS", 1:opt$newsignum)
202 # Plot the 96-profile of the signatures: 208 # Plot the 96-profile of the signatures:
203 p5 <- plot_96_profile(nmf_res$signatures, condensed = TRUE) 209 p5 <- plot_96_profile(nmf_res$signatures, condensed = TRUE)
204 new_sig_matrix <- reshape2::dcast(p5$data, substitution + context ~ sample, value.var = "freq") 210 new_sig_matrix <- reshape2::dcast(p5$data, substitution + context ~ sample, value.var = "freq")
205 new_sig_matrix <- format(new_sig_matrix, scientific = TRUE) 211 new_sig_matrix <- format(new_sig_matrix, scientific = TRUE)
212 newcol <- paste0(gsub("\\..", "", new_sig_matrix$context, perl = T),
213 "[", new_sig_matrix$substitution, "]",
214 gsub("^.\\.", "", new_sig_matrix$context, perl = T))
215 new_sig_matrix <- cbind(Type = newcol, new_sig_matrix[, seq_along(new_sig_matrix)[-c(1, 2)]])
206 write.table(new_sig_matrix, file = opt$sigmatrix, quote = FALSE, row.names = FALSE, sep = "\t") 216 write.table(new_sig_matrix, file = opt$sigmatrix, quote = FALSE, row.names = FALSE, sep = "\t")
207 grid.arrange(p5) 217 grid.arrange(p5)
208 # Visualize the contribution of the signatures in a barplot 218 # Visualize the contribution of the signatures in a barplot
209 pc1 <- plot_contribution(nmf_res$contribution, nmf_res$signature, mode = "relative", coord_flip = TRUE) 219 pc1 <- plot_contribution(nmf_res$contribution, nmf_res$signature, mode = "relative", coord_flip = TRUE)
210 # Visualize the contribution of the signatures in absolute number of mutations 220 # Visualize the contribution of the signatures in absolute number of mutations
281 "SBS35", "SBS36", "SBS37", "SBS38", "SBS39", "SBS40", "SBS41", "SBS42", "SBS43", "SBS44", "SBS45", 291 "SBS35", "SBS36", "SBS37", "SBS38", "SBS39", "SBS40", "SBS41", "SBS42", "SBS43", "SBS44", "SBS45",
282 "SBS46", "SBS47", "SBS48", "SBS49", "SBS50", "SBS51", "SBS52", "SBS53", "SBS54", "SBS55", "SBS56", 292 "SBS46", "SBS47", "SBS48", "SBS49", "SBS50", "SBS51", "SBS52", "SBS53", "SBS54", "SBS55", "SBS56",
283 "SBS57", "SBS58", "SBS59", "SBS60", "SBS84", "SBS85", "SBS86", "SBS87", "SBS88", "SBS89", "SBS90", 293 "SBS57", "SBS58", "SBS59", "SBS60", "SBS84", "SBS85", "SBS86", "SBS87", "SBS88", "SBS89", "SBS90",
284 "SBS91", "SBS92", "SBS93", "SBS94") 294 "SBS91", "SBS92", "SBS93", "SBS94")
285 295
296 # if signature names provided are not compliant with cosmic nomenclature,
297 # we attribute these names to the active signature_colors vector, adjusted to the length
298 # of the signature names.
299
300 if (! all(colnames(sbs_signatures) %in% names(signature_colors))) { # provided signature are not all included in cosmic names
301 signature_colors <- signature_colors[seq_along(sbs_signatures)]
302 names(signature_colors) <- colnames(sbs_signatures)
303 }
304
286 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures() 305 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures()
287 sbs_signatures <- as.matrix(sbs_signatures) 306 sbs_signatures <- as.matrix(sbs_signatures)
288 307
289 308
290 # Plot mutational profiles of the COSMIC signatures 309 # Plot mutational profiles of the COSMIC signatures
291 310
292 pdf(opt$output_sigpattern, paper = "special", width = 11.69, height = 11.69) 311 pdf(opt$output_sigpattern, paper = "special", width = 11.69, height = 11.69)
293 for (i in head(seq(1, ncol(sbs_signatures), by = 20), -1)) { 312 if (opt$display_signatures == "yes") {
294 p6 <- plot_96_profile(sbs_signatures[, i:(i + 19)], condensed = TRUE, ymax = 0.3) 313 for (i in head(seq(1, ncol(sbs_signatures), by = 20), -1)) {
295 grid.arrange(p6, top = textGrob(paste0(tag, " profiles (", trunc((i + 1) / 20) + 1, " of ", 314 p6 <- plot_96_profile(sbs_signatures[, i:(i + 19)], condensed = TRUE, ymax = 0.3)
315 grid.arrange(p6, top = textGrob(paste0(tag, " profiles (", trunc((i + 1) / 20) + 1, " of ",
316 trunc(ncol(sbs_signatures) / 20) + 1, " pages)"),
317 gp = gpar(fontsize = 12, font = 3)))
318 }
319 p6 <- plot_96_profile(sbs_signatures[, (trunc(ncol(sbs_signatures) / 20) * 20):(ncol(sbs_signatures))],
320 condensed = TRUE, ymax = 0.3)
321 grid.arrange(p6, top = textGrob(paste0(tag, " profiles (", trunc(ncol(sbs_signatures) / 20) + 1, " of ",
296 trunc(ncol(sbs_signatures) / 20) + 1, " pages)"), 322 trunc(ncol(sbs_signatures) / 20) + 1, " pages)"),
297 gp = gpar(fontsize = 12, font = 3))) 323 gp = gpar(fontsize = 12, font = 3)))
298 } 324 }
299 p6 <- plot_96_profile(sbs_signatures[, (trunc(ncol(sbs_signatures) / 20) * 20):(ncol(sbs_signatures))],
300 condensed = TRUE, ymax = 0.3)
301 grid.arrange(p6, top = textGrob(paste0(tag, " profiles (", trunc(ncol(sbs_signatures) / 20) + 1, " of ",
302 trunc(ncol(sbs_signatures) / 20) + 1, " pages)"),
303 gp = gpar(fontsize = 12, font = 3)))
304 325
305 326
306 # Find optimal contribution of COSMIC signatures to reconstruct 96 mutational profiles 327 # Find optimal contribution of COSMIC signatures to reconstruct 96 mutational profiles
307 pseudo_mut_mat <- mut_mat + 0.0001 # First add a small pseudocount to the mutation count matrix 328 pseudo_mut_mat <- mut_mat + 0.0001 # First add a small pseudocount to the mutation count matrix
308 fit_res <- fit_to_signatures(pseudo_mut_mat, sbs_signatures) 329 fit_res <- fit_to_signatures(pseudo_mut_mat, sbs_signatures)