comparison mutational_patterns.R @ 21:8a5aaa97dbd6 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 91415d0273efacfc605199a8fbebaf421da9df7e"
author artbio
date Wed, 20 Oct 2021 17:38:25 +0000
parents a2cb7dc9250a
children 00be8f0b2c89
comparison
equal deleted inserted replaced
20:a2cb7dc9250a 21:8a5aaa97dbd6
252 row.names(sbs_signatures) <- sbs_signatures$Type 252 row.names(sbs_signatures) <- sbs_signatures$Type
253 # drop column Type of sbs_signatures 253 # drop column Type of sbs_signatures
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 colnames(sbs_signatures) <- gsub("SBS", "", colnames(sbs_signatures))
258 # arrange signature colors 257 # arrange signature colors
259 if (opt$colors == "intense") { 258 if (opt$colors == "intense") {
260 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3", "#d2ab00", 259 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3", "#d2ab00",
261 "#e36eff", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083", "#c0ce67", "#002981", 260 "#e36eff", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083", "#c0ce67", "#002981",
262 "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec", "#ff233f", "#01b7b4", "#fd005c", 261 "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec", "#ff233f", "#01b7b4", "#fd005c",
390 } 389 }
391 390
392 colnames(worklist) <- c("signature", "sample", "value", "level") 391 colnames(worklist) <- c("signature", "sample", "value", "level")
393 worklist <- as.data.frame(worklist %>% group_by(sample) %>% mutate(value = value / sum(value) * 100)) 392 worklist <- as.data.frame(worklist %>% group_by(sample) %>% mutate(value = value / sum(value) * 100))
394 worklist$pos <- cumsum(worklist$value) - worklist$value / 2 393 worklist$pos <- cumsum(worklist$value) - worklist$value / 2
395 worklist$label <- factor(worklist$signature) 394 worklist$label <- factor(gsub("SBS", "", worklist$signature))
396 worklist$signature <- factor(worklist$signature) 395 worklist$signature <- factor(worklist$signature)
397 p7 <- ggplot(worklist, aes(x = "", y = value, group = signature, fill = signature)) + 396 p7 <- ggplot(worklist, aes(x = "", y = value, group = signature, fill = signature)) +
398 geom_bar(width = 1, stat = "identity") + 397 geom_bar(width = 1, stat = "identity") +
399 geom_text(aes(label = label), position = position_stack(vjust = 0.5), color = "black", size = 3) + 398 geom_text(aes(label = label), position = position_stack(vjust = 0.5), color = "white", size = 3) +
400 coord_polar("y", start = 0) + facet_wrap(.~sample) + 399 coord_polar("y", start = 0) + facet_wrap(.~sample) +
401 labs(x = "", y = "Samples", fill = tag) + 400 labs(x = "", y = "Samples", fill = tag) +
402 scale_fill_manual(name = paste0(opt$signum, " most contributing\nsignatures\n(in each label/tissue)"), 401 scale_fill_manual(name = paste0(opt$signum, " most contributing\nsignatures\n(in each label/tissue)"),
403 values = signature_colors[levels(worklist$signature)], 402 values = signature_colors[levels(worklist$signature)],
404 labels = names(signature_colors[levels(worklist$signature)])) + 403 labels = names(signature_colors[levels(worklist$signature)])) +