Mercurial > repos > artbio > mutational_patterns
comparison mutational_patterns.R @ 8:abf0dc1bc5b1 draft
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
author | artbio |
---|---|
date | Mon, 25 Oct 2021 15:21:39 +0000 |
parents | 4a33d3b1b17c |
children | 134b19acf876 |
comparison
equal
deleted
inserted
replaced
7:4a33d3b1b17c | 8:abf0dc1bc5b1 |
---|---|
254 sbs_signatures <- subset(sbs_signatures, select = -c(Type)) | 254 sbs_signatures <- subset(sbs_signatures, select = -c(Type)) |
255 # reorder substitutions of sbs_signatures to match mut_mat | 255 # reorder substitutions of sbs_signatures to match mut_mat |
256 sbs_signatures <- sbs_signatures[match(row.names(mut_mat), row.names(sbs_signatures)), ] | 256 sbs_signatures <- sbs_signatures[match(row.names(mut_mat), row.names(sbs_signatures)), ] |
257 # arrange signature colors | 257 # arrange signature colors |
258 if (opt$colors == "intense") { | 258 if (opt$colors == "intense") { |
259 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3", "#d2ab00", | 259 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#c4bedf", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3", |
260 "#e36eff", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083", "#c0ce67", "#002981", | 260 "#d2ab00", "#e36eff", "#cad5b3", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083", |
261 "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec", "#ff233f", "#01b7b4", "#fd005c", | 261 "#c0ce67", "#002981", "#e6b8b3", "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec", |
262 "#019560", "#ff57a9", "#88d896", "#b80067", "#abd27f", "#dc8eff", "#667b00", "#fba3ff", "#093f00", "#ff6494", "#009791", | 262 "#ff233f", "#01b7b4", "#fd005c", "#019560", "#ff57a9", "#88d896", "#b80067", "#abd27f", "#dc8eff", "#667b00", "#fba3ff", |
263 "#c93200", "#4ac8ff", "#a60005", "#8fd4b6", "#ce0036", "#00634d", "#ff6035", "#2d1956", "#f0be6d", "#6a0058", "#957a00", | 263 "#093f00", "#ff6494", "#009791", "#c93200", "#4ac8ff", "#a60005", "#8fd4b6", "#ce0036", "#00634d", "#ff6035", "#2d1956", |
264 "#e4b4ff", "#4a5500", "#abc7fe", "#c95900", "#003d27", "#b10043", "#d5c68e", "#3e163e", "#b36b00", "#debaeb", "#605400", | 264 "#f0be6d", "#6a0058", "#957a00", "#e4b4ff", "#4a5500", "#abc7fe", "#c95900", "#003d27", "#b10043", "#d5c68e", "#3e163e", |
265 "#7a0044", "#ffa06d", "#4c0d21", "#ff9cb5", "#3f1d02", "#ff958f", "#634a66", "#775500", "#6e0028", "#717653", "#6c1000", | 265 "#b36b00", "#debaeb", "#605400", "#7a0044", "#ffa06d", "#4c0d21", "#ff9cb5", "#3f1d02", "#ff958f", "#634a66", "#775500", |
266 "#693600") | 266 "#6e0028", "#717653", "#6c1000", "#693600") |
267 } else { | 267 } else { |
268 signature_colors <- c("#7FC97F", "#BEAED4", "#FDC086", "#FFFF99", "#386CB0", "#F0027F", "#BF5B17", "#666666", "#1B9E77", "#D95F02", "#7570B3", | 268 signature_colors <- c("#7FC97F", "#BEAED4", "#FDC086", "#FFFF99", "#386CB0", "#F0027F", "#c4bedf", "#BF5B17", "#666666", "#1B9E77", "#D95F02", |
269 "#E7298A", "#66A61E", "#E6AB02", "#A6761D", "#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99", "#E31A1C", "#FDBF6F", | 269 "#7570B3", "#E7298A", "#cad5b3", "#66A61E", "#E6AB02", "#A6761D", "#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99", |
270 "#FF7F00", "#CAB2D6", "#6A3D9A", "#B15928", "#FBB4AE", "#B3CDE3", "#CCEBC5", "#DECBE4", "#FED9A6", "#FFFFCC", "#E5D8BD", | 270 "#E31A1C", "#B3E2CD", "#e6b8b3", "#FF7F00", "#CAB2D6", "#6A3D9A", "#B15928", "#FBB4AE", "#B3CDE3", "#CCEBC5", "#DECBE4", |
271 "#FDDAEC", "#F2F2F2", "#B3E2CD", "#FDCDAC", "#CBD5E8", "#F4CAE4", "#E6F5C9", "#FFF2AE", "#F1E2CC", "#CCCCCC", "#E41A1C", | 271 "#FED9A6", "#FFFFCC", "#E5D8BD", "#FDDAEC", "#F2F2F2", "#B3E2CD", "#FDCDAC", "#CBD5E8", "#F4CAE4", "#E6F5C9", "#FFF2AE", |
272 "#377EB8", "#4DAF4A", "#984EA3", "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", | 272 "#F1E2CC", "#CCCCCC", "#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5", |
273 "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3", "#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", "#80B1D3", "#FDB462", "#B3DE69", | 273 "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3", "#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", |
274 "#FCCDE5", "#D9D9D9", "#BC80BD", "#FFED6F", "#3f1d02", "#ff958f", "#634a66", "#775500", "#6e0028", "#717653", "#6c1000", | 274 "#80B1D3", "#FDB462", "#B3DE69", "#FCCDE5", "#D9D9D9", "#BC80BD", "#FFED6F", "#3f1d02", "#ff958f", "#634a66", "#775500", |
275 "#693600") | 275 "#6e0028", "#717653", "#6c1000", "#693600") |
276 } | 276 } |
277 signature_colors <- signature_colors[seq_len(ncol(sbs_signatures))] | 277 names(signature_colors) <- c("SBS1", "SBS2", "SBS3", "SBS4", "SBS5", "SBS6", "SBS7", "SBS7a", "SBS7b", "SBS7c", "SBS7d", |
278 names(signature_colors) <- colnames(sbs_signatures) | 278 "SBS8", "SBS9", "SBS10", "SBS10a", "SBS10b", "SBS10c", "SBS10d", "SBS11", "SBS12", "SBS13", "SBS14", |
279 "SBS15", "SBS16", "SBS17", "SBS17a", "SBS17b", "SBS18", "SBS19", "SBS20", "SBS21", "SBS22", "SBS23", | |
280 "SBS24", "SBS25", "SBS26", "SBS27", "SBS28", "SBS29", "SBS30", "SBS31", "SBS32", "SBS33", "SBS34", | |
281 "SBS35", "SBS36", "SBS37", "SBS38", "SBS39", "SBS40", "SBS41", "SBS42", "SBS43", "SBS44", "SBS45", | |
282 "SBS46", "SBS47", "SBS48", "SBS49", "SBS50", "SBS51", "SBS52", "SBS53", "SBS54", "SBS55", "SBS56", | |
283 "SBS57", "SBS58", "SBS59", "SBS60", "SBS84", "SBS85", "SBS86", "SBS87", "SBS88", "SBS89", "SBS90", | |
284 "SBS91", "SBS92", "SBS93", "SBS94") | |
285 | |
279 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures() | 286 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures() |
280 sbs_signatures <- as.matrix(sbs_signatures) | 287 sbs_signatures <- as.matrix(sbs_signatures) |
281 | 288 |
282 | 289 |
283 # Plot mutational profiles of the COSMIC signatures | 290 # Plot mutational profiles of the COSMIC signatures |
306 if (is.na(opt$levels)[1]) { # if there are NO levels to display in graphs | 313 if (is.na(opt$levels)[1]) { # if there are NO levels to display in graphs |
307 pc3_data <- pc3$data | 314 pc3_data <- pc3$data |
308 pc3 <- ggplot(pc3_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + | 315 pc3 <- ggplot(pc3_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + |
309 geom_bar(stat = "identity", position = "stack") + | 316 geom_bar(stat = "identity", position = "stack") + |
310 coord_flip() + | 317 coord_flip() + |
311 scale_fill_manual(name = tag, values = signature_colors[]) + | 318 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) + |
312 labs(x = "Samples", y = "Absolute contribution") + theme_bw() + | 319 labs(x = "Samples", y = "Absolute contribution") + theme_bw() + |
313 theme(panel.grid.minor.x = element_blank(), | 320 theme(panel.grid.minor.x = element_blank(), |
314 panel.grid.major.x = element_blank(), | 321 panel.grid.major.x = element_blank(), |
315 legend.position = "right", | 322 legend.position = "right", |
316 text = element_text(size = 8), | 323 text = element_text(size = 8), |
317 axis.text.x = element_text(angle = 90, hjust = 1)) | 324 axis.text.x = element_text(angle = 90, hjust = 1)) |
318 pc4_data <- pc4$data | 325 pc4_data <- pc4$data |
319 pc4 <- ggplot(pc4_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + | 326 pc4 <- ggplot(pc4_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + |
320 geom_bar(stat = "identity", position = "fill") + | 327 geom_bar(stat = "identity", position = "fill") + |
321 coord_flip() + | 328 coord_flip() + |
322 scale_fill_manual(name = tag, values = signature_colors) + | 329 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) + |
323 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + | 330 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + |
324 labs(x = "Samples", y = "Relative contribution") + theme_bw() + | 331 labs(x = "Samples", y = "Relative contribution") + theme_bw() + |
325 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position = "right", | 332 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position = "right", |
326 text = element_text(size = 8), | 333 text = element_text(size = 8), |
327 axis.text.x = element_text(angle = 90, hjust = 1)) | 334 axis.text.x = element_text(angle = 90, hjust = 1)) |
331 if (!is.na(opt$levels)[1]) { # if there are levels to display in graphs | 338 if (!is.na(opt$levels)[1]) { # if there are levels to display in graphs |
332 pc3_data <- pc3$data | 339 pc3_data <- pc3$data |
333 pc3_data <- merge(pc3_data, metadata_table[, c(1, 3)], by.x = "Sample", by.y = "element_identifier") | 340 pc3_data <- merge(pc3_data, metadata_table[, c(1, 3)], by.x = "Sample", by.y = "element_identifier") |
334 pc3 <- ggplot(pc3_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + | 341 pc3 <- ggplot(pc3_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + |
335 geom_bar(stat = "identity", position = "stack") + | 342 geom_bar(stat = "identity", position = "stack") + |
336 scale_fill_manual(name = tag, values = signature_colors) + | 343 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) + |
337 labs(x = "Samples", y = "Absolute contribution") + theme_bw() + | 344 labs(x = "Samples", y = "Absolute contribution") + theme_bw() + |
338 theme(panel.grid.minor.x = element_blank(), | 345 theme(panel.grid.minor.x = element_blank(), |
339 panel.grid.major.x = element_blank(), | 346 panel.grid.major.x = element_blank(), |
340 legend.position = "right", | 347 legend.position = "right", |
341 text = element_text(size = 8), | 348 text = element_text(size = 8), |
343 facet_grid(~level, scales = "free_x", space = "free") | 350 facet_grid(~level, scales = "free_x", space = "free") |
344 pc4_data <- pc4$data | 351 pc4_data <- pc4$data |
345 pc4_data <- merge(pc4_data, metadata_table[, c(1, 3)], by.x = "Sample", by.y = "element_identifier") | 352 pc4_data <- merge(pc4_data, metadata_table[, c(1, 3)], by.x = "Sample", by.y = "element_identifier") |
346 pc4 <- ggplot(pc4_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + | 353 pc4 <- ggplot(pc4_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) + |
347 geom_bar(stat = "identity", position = "fill") + | 354 geom_bar(stat = "identity", position = "fill") + |
348 scale_fill_manual(name = tag, values = signature_colors) + | 355 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) + |
349 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + | 356 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + |
350 labs(x = "Samples", y = "Relative contribution") + theme_bw() + | 357 labs(x = "Samples", y = "Relative contribution") + theme_bw() + |
351 theme(panel.grid.minor.x = element_blank(), | 358 theme(panel.grid.minor.x = element_blank(), |
352 panel.grid.major.x = element_blank(), | 359 panel.grid.major.x = element_blank(), |
353 legend.position = "right", | 360 legend.position = "right", |