Mercurial > repos > artbio > mutational_patterns
annotate mutational_patterns.R @ 0:924c527fb379 draft
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
author | artbio |
---|---|
date | Sun, 13 Sep 2020 18:40:29 +0000 |
parents | |
children | aea952be68cb |
rev | line source |
---|---|
0
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
1 # load packages that are provided in the conda env |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
2 options( show.error.messages=F, |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
3 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
4 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
5 warnings() |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
6 library(optparse) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
7 library(rjson) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
8 library(MutationalPatterns) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
9 library(ggplot2) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
10 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
11 # Arguments |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
12 option_list = list( |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
13 make_option( |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
14 "--inputs", |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
15 default = NA, |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
16 type = 'character', |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
17 help = "json formatted dictionary of datasets and their paths" |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
18 ), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
19 make_option( |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
20 "--genome", |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
21 default = NA, |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
22 type = 'character', |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
23 help = "genome name in the BSgenome bioconductor package" |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
24 ), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
25 make_option( |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
26 "--levels", |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
27 default = NA, |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
28 type = 'character', |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
29 help = "path to the tab separated file describing the levels in function of datasets" |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
30 ), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
31 make_option( |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
32 "--signum", |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
33 default = 2, |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
34 type = 'integer', |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
35 help = "selects the N most significant signatures in samples to express mutational patterns" |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
36 ), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
37 make_option( |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
38 "--output", |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
39 default = NA, |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
40 type = 'character', |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
41 help = "path to output dataset" |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
42 ) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
43 ) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
44 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
45 opt = parse_args(OptionParser(option_list = option_list), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
46 args = commandArgs(trailingOnly = TRUE)) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
47 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
48 json_dict <- opt$inputs |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
49 parser <- newJSONParser() |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
50 parser$addData(json_dict) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
51 fileslist <- parser$getObject() |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
52 vcf_files <- attr(fileslist, "names") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
53 sample_names <- unname(unlist(fileslist)) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
54 pdf(opt$output, paper = "special", width = 11.69, height = 11.69) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
55 ref_genome <- opt$genome |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
56 library(ref_genome, character.only = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
57 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
58 # Load the VCF files into a GRangesList: |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
59 vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
60 levels_table <- read.delim(opt$levels, header=FALSE, col.names=c("sample_name","level")) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
61 vcf_table <- data.frame(path=vcf_files, sample_name=sample_names) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
62 metadata_table <- merge(vcf_table, levels_table, by.x=2, by.y=1) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
63 levels <- metadata_table$level |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
64 muts = mutations_from_vcf(vcfs[[1]]) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
65 types = mut_type(vcfs[[1]]) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
66 context = mut_context(vcfs[[1]], ref_genome) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
67 type_context = type_context(vcfs[[1]], ref_genome) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
68 type_occurrences <- mut_type_occurrences(vcfs, ref_genome) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
69 # p1 <- plot_spectrum(type_occurrences) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
70 # p2 <- plot_spectrum(type_occurrences, CT = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
71 # p3 <- plot_spectrum(type_occurrences, CT = TRUE, legend = FALSE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
72 # |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
73 # plot(p2) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
74 # p4 <- plot_spectrum(type_occurrences, by = levels, CT = TRUE, legend = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
75 # palette <- c("pink", "orange", "blue", "lightblue", "green", "red", "purple") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
76 # p5 <- plot_spectrum(type_occurrences, CT=TRUE, legend=TRUE, colors=palette) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
77 # |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
78 # plot(p4) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
79 mut_mat <- mut_matrix(vcf_list = vcfs, ref_genome = ref_genome) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
80 # plot_96_profile(mut_mat[,1:length(as.data.frame(mut_mat))], condensed = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
81 mut_mat <- mut_mat + 0.0001 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
82 # library("NMF") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
83 # estimate <- nmf(mut_mat, rank=2:5, method="brunet", nrun=100, seed=123456) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
84 # plot(estimate) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
85 # nmf_res <- extract_signatures(mut_mat, rank = 4, nrun = 100) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
86 # colnames(nmf_res$signatures) <- c("Signature A", "Signature B", "Signature C", "Signature D") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
87 # rownames(nmf_res$contribution) <- c("Signature A", "Signature B", "Signature C", "Signature D") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
88 # plot_96_profile(nmf_res$signatures, condensed = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
89 sp_url <- paste("https://cancer.sanger.ac.uk/cancergenome/assets/", "signatures_probabilities.txt", sep = "") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
90 cancer_signatures = read.table(sp_url, sep = "\t", header = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
91 new_order = match(row.names(mut_mat), cancer_signatures$Somatic.Mutation.Type) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
92 cancer_signatures = cancer_signatures[as.vector(new_order),] |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
93 row.names(cancer_signatures) = cancer_signatures$Somatic.Mutation.Type |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
94 cancer_signatures = as.matrix(cancer_signatures[,4:33]) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
95 # plot_96_profile(cancer_signatures, condensed = TRUE, ymax = 0.3) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
96 hclust_cosmic = cluster_signatures(cancer_signatures, method = "average") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
97 cosmic_order = colnames(cancer_signatures)[hclust_cosmic$order] |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
98 # plot(hclust_cosmic) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
99 cos_sim(mut_mat[,1], cancer_signatures[,1]) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
100 cos_sim_samples_signatures = cos_sim_matrix(mut_mat, cancer_signatures) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
101 plot_cosine_heatmap(cos_sim_samples_signatures, col_order = cosmic_order, cluster_rows = TRUE) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
102 fit_res <- fit_to_signatures(mut_mat, cancer_signatures) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
103 threshold <- tail(sort(unlist(rowSums(fit_res$contribution), use.names = FALSE)), opt$signum)[1] |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
104 select <- which(rowSums(fit_res$contribution) >= threshold) # ensure opt$signum best signatures in samples are retained, the others discarded |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
105 plot_contribution(fit_res$contribution[select,], cancer_signatures[,select], coord_flip = T, mode = "absolute") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
106 plot_contribution(fit_res$contribution[select,], cancer_signatures[,select], coord_flip = T, mode = "relative") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
107 plot_contribution_heatmap(fit_res$contribution, cluster_samples = TRUE, method = "complete") |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
108 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
109 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
110 sig5data <- as.data.frame(t(head(fit_res$contribution[select,]))) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
111 colnames(sig5data) <- gsub("nature", "", colnames(sig5data)) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
112 sig5data_percents <- sig5data / (apply(sig5data,1,sum)) * 100 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
113 sig5data_percents$sample <- rownames(sig5data_percents) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
114 library(reshape2) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
115 melted_sig5data_percents <-melt(data=sig5data_percents) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
116 melted_sig5data_percents$label <- sub("Sig.", "", melted_sig5data_percents$variable) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
117 melted_sig5data_percents$pos <- cumsum(melted_sig5data_percents$value) - melted_sig5data_percents$value/2 |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
118 ggplot(melted_sig5data_percents, aes(x="", y=value, group=variable, fill=variable)) + |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
119 geom_bar(width = 1, stat = "identity") + |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
120 geom_text(aes(label = label), position = position_stack(vjust = 0.5), color="black", size=3) + |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
121 coord_polar("y", start=0) + facet_wrap(~ sample) + |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
122 labs(x="", y="Samples", fill = "Signatures (Cosmic_v2,March 2015)") + |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
123 theme(axis.text = element_blank(), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
124 axis.ticks = element_blank(), |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
125 panel.grid = element_blank()) |
924c527fb379
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff
changeset
|
126 dev.off() |