comparison mutational_patterns.R @ 20:a2cb7dc9250a draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
author artbio
date Tue, 19 Oct 2021 06:16:32 +0000
parents 69f09dff98f9
children 8a5aaa97dbd6
comparison
equal deleted inserted replaced
19:69f09dff98f9 20:a2cb7dc9250a
96 make_option( 96 make_option(
97 "--sig_contrib_matrix", 97 "--sig_contrib_matrix",
98 default = NA, 98 default = NA,
99 type = "character", 99 type = "character",
100 help = "path to signature contribution matrix" 100 help = "path to signature contribution matrix"
101 ),
102 make_option(
103 "--colors",
104 default = NA,
105 type = "character",
106 help = "color palette to display signatures"
101 ), 107 ),
102 make_option( 108 make_option(
103 c("-r", "--rdata"), 109 c("-r", "--rdata"),
104 type = "character", 110 type = "character",
105 default = NULL, 111 default = NULL,
189 # Extract 4 (PARAMETIZE) mutational signatures from the mutation count matrix with extract_signatures 195 # Extract 4 (PARAMETIZE) mutational signatures from the mutation count matrix with extract_signatures
190 # (For larger datasets it is wise to perform more iterations by changing the nrun parameter 196 # (For larger datasets it is wise to perform more iterations by changing the nrun parameter
191 # to achieve stability and avoid local minima) 197 # to achieve stability and avoid local minima)
192 nmf_res <- extract_signatures(pseudo_mut_mat, rank = opt$newsignum, nrun = opt$nrun) 198 nmf_res <- extract_signatures(pseudo_mut_mat, rank = opt$newsignum, nrun = opt$nrun)
193 # Assign signature names 199 # Assign signature names
194 colnames(nmf_res$signatures) <- paste0("NewSig_", 1:opt$newsignum) 200 colnames(nmf_res$signatures) <- paste0("SBS", 1:opt$newsignum)
195 rownames(nmf_res$contribution) <- paste0("NewSig_", 1:opt$newsignum) 201 rownames(nmf_res$contribution) <- paste0("SBS", 1:opt$newsignum)
196 # Plot the 96-profile of the signatures: 202 # Plot the 96-profile of the signatures:
197 p5 <- plot_96_profile(nmf_res$signatures, condensed = TRUE) 203 p5 <- plot_96_profile(nmf_res$signatures, condensed = TRUE)
198 new_sig_matrix <- reshape2::dcast(p5$data, substitution + context ~ sample, value.var = "freq") 204 new_sig_matrix <- reshape2::dcast(p5$data, substitution + context ~ sample, value.var = "freq")
199 new_sig_matrix <- format(new_sig_matrix, scientific = TRUE) 205 new_sig_matrix <- format(new_sig_matrix, scientific = TRUE)
200 write.table(new_sig_matrix, file = opt$sigmatrix, quote = FALSE, row.names = FALSE, sep = "\t") 206 write.table(new_sig_matrix, file = opt$sigmatrix, quote = FALSE, row.names = FALSE, sep = "\t")
239 tag <- paste(gsub("BSgenome.Hsapiens.UCSC.", "", opt$genome), "COSMIC", opt$cosmic_version, sep = " ") 245 tag <- paste(gsub("BSgenome.Hsapiens.UCSC.", "", opt$genome), "COSMIC", opt$cosmic_version, sep = " ")
240 } 246 }
241 # Prepare user-defined signatures 247 # Prepare user-defined signatures
242 if (!is.na(opt$own_signatures)) { 248 if (!is.na(opt$own_signatures)) {
243 sbs_signatures <- read.table(opt$own_signatures, sep = "\t", header = TRUE) 249 sbs_signatures <- read.table(opt$own_signatures, sep = "\t", header = TRUE)
244 tag <- paste(opt$genome, "User-Defined Signatures", sep = " ") 250 tag <- paste(gsub("BSgenome.Hsapiens.UCSC.", "", opt$genome), "User-Defined Signatures", sep = " ")
245 } 251 }
246 row.names(sbs_signatures) <- sbs_signatures$Type 252 row.names(sbs_signatures) <- sbs_signatures$Type
247 # drop column Type of sbs_signatures 253 # drop column Type of sbs_signatures
248 sbs_signatures <- subset(sbs_signatures, select = -c(Type)) 254 sbs_signatures <- subset(sbs_signatures, select = -c(Type))
249 # reorder substitutions of sbs_signatures to match mut_mat 255 # reorder substitutions of sbs_signatures to match mut_mat
250 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)), ]
251 colnames(sbs_signatures) <- gsub("SBS", "", colnames(sbs_signatures)) 257 colnames(sbs_signatures) <- gsub("SBS", "", colnames(sbs_signatures))
252 # arrange signature colors 258 # arrange signature colors
253 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3", "#d2ab00", 259 if (opt$colors == "intense") {
254 "#e36eff", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083", "#c0ce67", "#002981", 260 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3", "#d2ab00",
255 "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec", "#ff233f", "#01b7b4", "#fd005c", 261 "#e36eff", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083", "#c0ce67", "#002981",
256 "#019560", "#ff57a9", "#88d896", "#b80067", "#abd27f", "#dc8eff", "#667b00", "#fba3ff", "#093f00", "#ff6494", "#009791", 262 "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec", "#ff233f", "#01b7b4", "#fd005c",
257 "#c93200", "#4ac8ff", "#a60005", "#8fd4b6", "#ce0036", "#00634d", "#ff6035", "#2d1956", "#f0be6d", "#6a0058", "#957a00", 263 "#019560", "#ff57a9", "#88d896", "#b80067", "#abd27f", "#dc8eff", "#667b00", "#fba3ff", "#093f00", "#ff6494", "#009791",
258 "#e4b4ff", "#4a5500", "#abc7fe", "#c95900", "#003d27", "#b10043", "#d5c68e", "#3e163e", "#b36b00", "#debaeb", "#605400", 264 "#c93200", "#4ac8ff", "#a60005", "#8fd4b6", "#ce0036", "#00634d", "#ff6035", "#2d1956", "#f0be6d", "#6a0058", "#957a00",
259 "#7a0044", "#ffa06d", "#4c0d21", "#ff9cb5", "#3f1d02", "#ff958f", "#634a66", "#775500", "#6e0028", "#717653", 265 "#e4b4ff", "#4a5500", "#abc7fe", "#c95900", "#003d27", "#b10043", "#d5c68e", "#3e163e", "#b36b00", "#debaeb", "#605400",
260 "#6c1000", "#693600") 266 "#7a0044", "#ffa06d", "#4c0d21", "#ff9cb5", "#3f1d02", "#ff958f", "#634a66", "#775500", "#6e0028", "#717653", "#6c1000",
267 "#693600")
268 } else {
269 signature_colors <- c("#7FC97F", "#BEAED4", "#FDC086", "#FFFF99", "#386CB0", "#F0027F", "#BF5B17", "#666666", "#1B9E77", "#D95F02", "#7570B3",
270 "#E7298A", "#66A61E", "#E6AB02", "#A6761D", "#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99", "#E31A1C", "#FDBF6F",
271 "#FF7F00", "#CAB2D6", "#6A3D9A", "#B15928", "#FBB4AE", "#B3CDE3", "#CCEBC5", "#DECBE4", "#FED9A6", "#FFFFCC", "#E5D8BD",
272 "#FDDAEC", "#F2F2F2", "#B3E2CD", "#FDCDAC", "#CBD5E8", "#F4CAE4", "#E6F5C9", "#FFF2AE", "#F1E2CC", "#CCCCCC", "#E41A1C",
273 "#377EB8", "#4DAF4A", "#984EA3", "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3",
274 "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3", "#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", "#80B1D3", "#FDB462", "#B3DE69",
275 "#FCCDE5", "#D9D9D9", "#BC80BD", "#FFED6F", "#3f1d02", "#ff958f", "#634a66", "#775500", "#6e0028", "#717653", "#6c1000",
276 "#693600")
277 }
261 signature_colors <- signature_colors[seq_len(ncol(sbs_signatures))] 278 signature_colors <- signature_colors[seq_len(ncol(sbs_signatures))]
262 names(signature_colors) <- colnames(sbs_signatures) 279 names(signature_colors) <- colnames(sbs_signatures)
263 # To drop signature_colors <- signature_colors[colnames(sbs_signatures)]
264 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures() 280 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures()
265 sbs_signatures <- as.matrix(sbs_signatures) 281 sbs_signatures <- as.matrix(sbs_signatures)
266 282
267 283
268 # Plot mutational profiles of the COSMIC signatures 284 # Plot mutational profiles of the COSMIC signatures