annotate mutational_patterns.R @ 9:134b19acf876 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:07 +0000
parents abf0dc1bc5b1
children 2823044430c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
1 # load packages that are provided in the conda env
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
2 options(show.error.messages = F,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
3 error = function() {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
4 cat(geterrmessage(), file = stderr()); q("no", 1, F)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
5 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
6 )
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
7 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
8 warnings()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
9 library(optparse)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
10 library(rjson)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
11 library(grid)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
12 library(gridExtra)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
13 library(scales)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
14 library(RColorBrewer)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
15
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
16 # Arguments
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
17 option_list <- list(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
18 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
19 "--inputs",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
20 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
21 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
22 help = "json formatted dictionary of datasets and their paths"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
23 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
24 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
25 "--genome",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
26 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
27 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
28 help = "genome name in the BSgenome bioconductor package"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
29 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
30 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
31 "--levels",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
32 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
33 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
34 help = "path to the tab separated file describing the levels in function of datasets"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
35 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
36 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
37 "--cosmic_version",
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
38 default = NA,
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
39 type = "character",
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
40 help = "Version of the Cosmic Signature set to be used to express mutational profiles"
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
41 ),
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
42 make_option(
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
43 "--own_signatures",
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
44 default = NA,
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
45 type = "character",
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
46 help = "Path to the user-defined signature matrix"
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
47 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
48 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
49 "--signum",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
50 default = 2,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
51 type = "integer",
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
52 help = "selects the N most significant signatures in samples to express mutational profiles"
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
53 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
54 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
55 "--nrun",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
56 default = 2,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
57 type = "integer",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
58 help = "Number of runs to fit signatures"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
59 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
60 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
61 "--rank",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
62 default = 2,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
63 type = "integer",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
64 help = "number of ranks to display for parameter optimization"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
65 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
66 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
67 "--newsignum",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
68 default = 2,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
69 type = "integer",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
70 help = "Number of new signatures to be captured"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
71 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
72 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
73 "--output_spectrum",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
74 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
75 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
76 help = "path to output dataset"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
77 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
78 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
79 "--output_denovo",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
80 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
81 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
82 help = "path to output dataset"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
83 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
84 make_option(
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
85 "--sigmatrix",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
86 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
87 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
88 help = "path to signature matrix"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
89 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
90 make_option(
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
91 "--output_sigpattern",
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
92 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
93 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
94 help = "path to output dataset"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
95 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
96 make_option(
9
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
97 "--display_signatures",
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
98 default = NA,
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
99 type = "character",
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
100 help = "display input signature profiles if set to yes"
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
101 ),
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
102 make_option(
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
103 "--sig_contrib_matrix",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
104 default = NA,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
105 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
106 help = "path to signature contribution matrix"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
107 ),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
108 make_option(
6
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
109 "--colors",
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
110 default = NA,
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
111 type = "character",
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
112 help = "color palette to display signatures"
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
113 ),
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
114 make_option(
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
115 c("-r", "--rdata"),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
116 type = "character",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
117 default = NULL,
3
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
118 help = "Path to RData output file"
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
119 ),
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
120 make_option(
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
121 c("-t", "--tooldir"),
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
122 type = "character",
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
123 default = NULL,
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
124 help = "Path to tool directory, where tool data are stored")
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
125
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
126 )
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
127
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
128 opt <- parse_args(OptionParser(option_list = option_list),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
129 args = commandArgs(trailingOnly = TRUE))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
130
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
131 ################ Manage input data ####################
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
132 json_dict <- opt$inputs
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
133 parser <- newJSONParser()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
134 parser$addData(json_dict)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
135 fileslist <- parser$getObject()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
136 vcf_paths <- attr(fileslist, "names")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
137 element_identifiers <- unname(unlist(fileslist))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
138 ref_genome <- opt$genome
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
139 vcf_table <- data.frame(element_identifier = as.character(element_identifiers), path = vcf_paths)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
140
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
141 library(MutationalPatterns)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
142 library(ref_genome, character.only = TRUE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
143 library(ggplot2)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
144
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
145 # Load the VCF files into a GRangesList:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
146 vcfs <- read_vcfs_as_granges(vcf_paths, element_identifiers, ref_genome)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
147 library(plyr)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
148 if (!is.na(opt$levels)[1]) { # manage levels if there are
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
149 levels_table <- read.delim(opt$levels, header = FALSE,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
150 col.names = c("element_identifier", "level"))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
151 } else {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
152 levels_table <- data.frame(element_identifier = vcf_table$element_identifier,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
153 level = rep("nolabels", length(vcf_table$element_identifier)))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
154 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
155 metadata_table <- join(vcf_table, levels_table, by = "element_identifier")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
156 tissue <- as.vector(metadata_table$level)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
157 detach(package:plyr)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
158
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
159 ##### This is done for any section ######
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
160 mut_mat <- mut_matrix(vcf_list = vcfs, ref_genome = ref_genome)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
161 qual_col_pals <- brewer.pal.info[brewer.pal.info$category == "qual", ]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
162
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
163 ###### Section 1 Mutation characteristics and spectrums #############
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
164 if (!is.na(opt$output_spectrum)[1]) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
165 pdf(opt$output_spectrum, paper = "special", width = 11.69, height = 11.69)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
166 type_occurrences <- mut_type_occurrences(vcfs, ref_genome)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
167
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
168 # mutation spectrum, total or by sample
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
169
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
170 if (length(levels(factor(levels_table$level))) == 1) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
171 p1 <- plot_spectrum(type_occurrences, CT = TRUE, legend = TRUE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
172 plot(p1)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
173 } else {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
174 p2 <- plot_spectrum(type_occurrences, by = tissue, CT = TRUE) # by levels
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
175 p3 <- plot_spectrum(type_occurrences, CT = TRUE, legend = TRUE) # total
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
176 grid.arrange(p2, p3, ncol = 2, widths = c(4, 2.3), heights = c(4, 1))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
177 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
178 plot_96_profile(mut_mat, condensed = TRUE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
179 dev.off()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
180 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
181
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
182 ###### Section 2: De novo mutational signature extraction using NMF #######
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
183 # opt$rank cannot be higher than the number of samples and
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
184 # likewise, opt$signum cannot be higher thant the number of samples
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
185 if (!is.na(opt$output_denovo)[1]) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
186
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
187 if (opt$rank > length(element_identifiers)) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
188 opt$rank <- length(element_identifiers)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
189 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
190 if (opt$signum > length(element_identifiers)) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
191 opt$signum <- length(element_identifiers)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
192 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
193 pseudo_mut_mat <- mut_mat + 0.0001 # First add a small pseudocount to the mutation count matrix
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
194 # Use the NMF package to generate an estimate rank plot
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
195 library("NMF")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
196 estimate <- nmf(pseudo_mut_mat, rank = 1:opt$rank, method = "brunet", nrun = opt$nrun, seed = 123456)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
197 # And plot it
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
198 pdf(opt$output_denovo, paper = "special", width = 11.69, height = 11.69)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
199 p4 <- plot(estimate)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
200 grid.arrange(p4)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
201 # Extract 4 (PARAMETIZE) mutational signatures from the mutation count matrix with extract_signatures
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
202 # (For larger datasets it is wise to perform more iterations by changing the nrun parameter
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
203 # to achieve stability and avoid local minima)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
204 nmf_res <- extract_signatures(pseudo_mut_mat, rank = opt$newsignum, nrun = opt$nrun)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
205 # Assign signature names
6
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
206 colnames(nmf_res$signatures) <- paste0("SBS", 1:opt$newsignum)
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
207 rownames(nmf_res$contribution) <- paste0("SBS", 1:opt$newsignum)
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
208 # Plot the 96-profile of the signatures:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
209 p5 <- plot_96_profile(nmf_res$signatures, condensed = TRUE)
1
c73aa7cc4c4b "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 6ca5597637439c87b61af2dbd6c38089b29eca37"
artbio
parents: 0
diff changeset
210 new_sig_matrix <- reshape2::dcast(p5$data, substitution + context ~ sample, value.var = "freq")
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
211 new_sig_matrix <- format(new_sig_matrix, scientific = TRUE)
9
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
212 newcol <- paste0(gsub("\\..", "", new_sig_matrix$context, perl = T),
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
213 "[", new_sig_matrix$substitution, "]",
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
214 gsub("^.\\.", "", new_sig_matrix$context, perl = T))
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
215 new_sig_matrix <- cbind(Type = newcol, new_sig_matrix[, seq_along(new_sig_matrix)[-c(1, 2)]])
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
216 write.table(new_sig_matrix, file = opt$sigmatrix, quote = FALSE, row.names = FALSE, sep = "\t")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
217 grid.arrange(p5)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
218 # Visualize the contribution of the signatures in a barplot
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
219 pc1 <- plot_contribution(nmf_res$contribution, nmf_res$signature, mode = "relative", coord_flip = TRUE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
220 # Visualize the contribution of the signatures in absolute number of mutations
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
221 pc2 <- plot_contribution(nmf_res$contribution, nmf_res$signature, mode = "absolute", coord_flip = TRUE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
222 # Combine the two plots:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
223 grid.arrange(pc1, pc2)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
224
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
225 # The relative contribution of each signature for each sample can also be plotted as a heatmap with
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
226 # plot_contribution_heatmap, which might be easier to interpret and compare than stacked barplots.
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
227 # The samples can be hierarchically clustered based on their euclidean dis- tance. The signatures
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
228 # can be plotted in a user-specified order.
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
229 # Plot signature contribution as a heatmap with sample clustering dendrogram and a specified signature order:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
230 pch1 <- plot_contribution_heatmap(nmf_res$contribution,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
231 sig_order = paste0("NewSig_", 1:opt$newsignum))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
232 # Plot signature contribution as a heatmap without sample clustering:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
233 pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
234 #Combine the plots into one figure:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
235 grid.arrange(pch1, pch2, ncol = 2, widths = c(2, 1.6))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
236
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
237 # Compare the reconstructed mutational profile with the original mutational profile:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
238 plot_compare_profiles(pseudo_mut_mat[, 1],
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
239 nmf_res$reconstructed[, 1],
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
240 profile_names = c("Original", "Reconstructed"),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
241 condensed = TRUE)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
242 dev.off()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
243 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
244
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
245 ##### Section 3: Find optimal contribution of known signatures: COSMIC or OWN mutational signatures ####
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
246
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
247 if (!is.na(opt$output_sigpattern)[1]) {
3
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
248 # Prepare cosmic signatures
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
249 if (!is.na(opt$cosmic_version)) {
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
250 cosmic_urls <- read.delim(paste0(opt$tooldir, "cosmic_urls.tsv"), sep = "\t", header = TRUE)
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
251 cosmic_sbs_file <- cosmic_urls$url[cosmic_urls$genome == opt$genome &
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
252 cosmic_urls$cosmic_version == opt$cosmic_version]
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
253 sbs_signatures <- read.table(paste0(opt$tooldir, cosmic_sbs_file),
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
254 sep = "\t", header = TRUE)
5
80645bff1893 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit db5fd077ec6c840b7b6eda331820999f85fd7c26"
artbio
parents: 4
diff changeset
255 tag <- paste(gsub("BSgenome.Hsapiens.UCSC.", "", opt$genome), "COSMIC", opt$cosmic_version, sep = " ")
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
256 }
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
257 # Prepare user-defined signatures
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
258 if (!is.na(opt$own_signatures)) {
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
259 sbs_signatures <- read.table(opt$own_signatures, sep = "\t", header = TRUE)
6
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
260 tag <- paste(gsub("BSgenome.Hsapiens.UCSC.", "", opt$genome), "User-Defined Signatures", sep = " ")
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
261 }
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
262 row.names(sbs_signatures) <- sbs_signatures$Type
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
263 # drop column Type of sbs_signatures
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
264 sbs_signatures <- subset(sbs_signatures, select = -c(Type))
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
265 # reorder substitutions of sbs_signatures to match mut_mat
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
266 sbs_signatures <- sbs_signatures[match(row.names(mut_mat), row.names(sbs_signatures)), ]
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
267 # arrange signature colors
6
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
268 if (opt$colors == "intense") {
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
269 signature_colors <- c("#3f4100", "#6f53ff", "#6dc400", "#9d1fd7", "#009c06", "#001fae", "#c4bedf", "#8adb4d", "#5a67ff", "#d8c938", "#024bc3",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
270 "#d2ab00", "#e36eff", "#cad5b3", "#00ac44", "#d000b0", "#01b071", "#ff64e2", "#006b21", "#b70090", "#60dc9f", "#5f0083",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
271 "#c0ce67", "#002981", "#e6b8b3", "#ffb53e", "#44005f", "#b59600", "#7d95ff", "#f47600", "#017bc4", "#ff2722", "#02cfec",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
272 "#ff233f", "#01b7b4", "#fd005c", "#019560", "#ff57a9", "#88d896", "#b80067", "#abd27f", "#dc8eff", "#667b00", "#fba3ff",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
273 "#093f00", "#ff6494", "#009791", "#c93200", "#4ac8ff", "#a60005", "#8fd4b6", "#ce0036", "#00634d", "#ff6035", "#2d1956",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
274 "#f0be6d", "#6a0058", "#957a00", "#e4b4ff", "#4a5500", "#abc7fe", "#c95900", "#003d27", "#b10043", "#d5c68e", "#3e163e",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
275 "#b36b00", "#debaeb", "#605400", "#7a0044", "#ffa06d", "#4c0d21", "#ff9cb5", "#3f1d02", "#ff958f", "#634a66", "#775500",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
276 "#6e0028", "#717653", "#6c1000", "#693600")
6
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
277 } else {
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
278 signature_colors <- c("#7FC97F", "#BEAED4", "#FDC086", "#FFFF99", "#386CB0", "#F0027F", "#c4bedf", "#BF5B17", "#666666", "#1B9E77", "#D95F02",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
279 "#7570B3", "#E7298A", "#cad5b3", "#66A61E", "#E6AB02", "#A6761D", "#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
280 "#E31A1C", "#B3E2CD", "#e6b8b3", "#FF7F00", "#CAB2D6", "#6A3D9A", "#B15928", "#FBB4AE", "#B3CDE3", "#CCEBC5", "#DECBE4",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
281 "#FED9A6", "#FFFFCC", "#E5D8BD", "#FDDAEC", "#F2F2F2", "#B3E2CD", "#FDCDAC", "#CBD5E8", "#F4CAE4", "#E6F5C9", "#FFF2AE",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
282 "#F1E2CC", "#CCCCCC", "#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
283 "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3", "#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
284 "#80B1D3", "#FDB462", "#B3DE69", "#FCCDE5", "#D9D9D9", "#BC80BD", "#FFED6F", "#3f1d02", "#ff958f", "#634a66", "#775500",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
285 "#6e0028", "#717653", "#6c1000", "#693600")
6
a68f0c9ecd95 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit b07cf2662a36d88f80dc08ef4f46454dbc133094"
artbio
parents: 5
diff changeset
286 }
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
287 names(signature_colors) <- c("SBS1", "SBS2", "SBS3", "SBS4", "SBS5", "SBS6", "SBS7", "SBS7a", "SBS7b", "SBS7c", "SBS7d",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
288 "SBS8", "SBS9", "SBS10", "SBS10a", "SBS10b", "SBS10c", "SBS10d", "SBS11", "SBS12", "SBS13", "SBS14",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
289 "SBS15", "SBS16", "SBS17", "SBS17a", "SBS17b", "SBS18", "SBS19", "SBS20", "SBS21", "SBS22", "SBS23",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
290 "SBS24", "SBS25", "SBS26", "SBS27", "SBS28", "SBS29", "SBS30", "SBS31", "SBS32", "SBS33", "SBS34",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
291 "SBS35", "SBS36", "SBS37", "SBS38", "SBS39", "SBS40", "SBS41", "SBS42", "SBS43", "SBS44", "SBS45",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
292 "SBS46", "SBS47", "SBS48", "SBS49", "SBS50", "SBS51", "SBS52", "SBS53", "SBS54", "SBS55", "SBS56",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
293 "SBS57", "SBS58", "SBS59", "SBS60", "SBS84", "SBS85", "SBS86", "SBS87", "SBS88", "SBS89", "SBS90",
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
294 "SBS91", "SBS92", "SBS93", "SBS94")
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
295
9
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
296 # if signature names provided are not compliant with cosmic nomenclature,
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
297 # we attribute these names to the active signature_colors vector, adjusted to the length
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
298 # of the signature names.
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
299
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
300 if (! all(colnames(sbs_signatures) %in% names(signature_colors))) { # provided signature are not all included in cosmic names
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
301 signature_colors <- signature_colors[seq_along(sbs_signatures)]
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
302 names(signature_colors) <- colnames(sbs_signatures)
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
303 }
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
304
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
305 # This is IMPORTANT since in Galaxy we do not use the embeded function get_known_signatures()
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
306 sbs_signatures <- as.matrix(sbs_signatures)
3
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
307
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
308
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
309 # Plot mutational profiles of the COSMIC signatures
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
310
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
311 pdf(opt$output_sigpattern, paper = "special", width = 11.69, height = 11.69)
9
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
312 if (opt$display_signatures == "yes") {
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
313 for (i in head(seq(1, ncol(sbs_signatures), by = 20), -1)) {
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
314 p6 <- plot_96_profile(sbs_signatures[, i:(i + 19)], condensed = TRUE, ymax = 0.3)
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
315 grid.arrange(p6, top = textGrob(paste0(tag, " profiles (", trunc((i + 1) / 20) + 1, " of ",
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
316 trunc(ncol(sbs_signatures) / 20) + 1, " pages)"),
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
317 gp = gpar(fontsize = 12, font = 3)))
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
318 }
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
319 p6 <- plot_96_profile(sbs_signatures[, (trunc(ncol(sbs_signatures) / 20) * 20):(ncol(sbs_signatures))],
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
320 condensed = TRUE, ymax = 0.3)
134b19acf876 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 3c4d96db0a3c54ed68bf782f08b89b6959255d58"
artbio
parents: 8
diff changeset
321 grid.arrange(p6, top = textGrob(paste0(tag, " profiles (", trunc(ncol(sbs_signatures) / 20) + 1, " of ",
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
322 trunc(ncol(sbs_signatures) / 20) + 1, " pages)"),
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
323 gp = gpar(fontsize = 12, font = 3)))
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
324 }
5
80645bff1893 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit db5fd077ec6c840b7b6eda331820999f85fd7c26"
artbio
parents: 4
diff changeset
325
80645bff1893 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit db5fd077ec6c840b7b6eda331820999f85fd7c26"
artbio
parents: 4
diff changeset
326
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
327 # Find optimal contribution of COSMIC signatures to reconstruct 96 mutational profiles
3
843f654e1752 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e5d498dfc5a6a9aaea3d09037dea5d15c2d85dd2"
artbio
parents: 2
diff changeset
328 pseudo_mut_mat <- mut_mat + 0.0001 # First add a small pseudocount to the mutation count matrix
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
329 fit_res <- fit_to_signatures(pseudo_mut_mat, sbs_signatures)
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
330
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
331 # Plot contribution barplots
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
332 pc3 <- plot_contribution(fit_res$contribution, sbs_signatures, coord_flip = T, mode = "absolute")
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
333 pc4 <- plot_contribution(fit_res$contribution, sbs_signatures, coord_flip = T, mode = "relative")
1
c73aa7cc4c4b "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 6ca5597637439c87b61af2dbd6c38089b29eca37"
artbio
parents: 0
diff changeset
334 if (is.na(opt$levels)[1]) { # if there are NO levels to display in graphs
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
335 pc3_data <- pc3$data
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
336 pc3 <- ggplot(pc3_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
337 geom_bar(stat = "identity", position = "stack") +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
338 coord_flip() +
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
339 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
340 labs(x = "Samples", y = "Absolute contribution") + theme_bw() +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
341 theme(panel.grid.minor.x = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
342 panel.grid.major.x = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
343 legend.position = "right",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
344 text = element_text(size = 8),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
345 axis.text.x = element_text(angle = 90, hjust = 1))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
346 pc4_data <- pc4$data
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
347 pc4 <- ggplot(pc4_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
348 geom_bar(stat = "identity", position = "fill") +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
349 coord_flip() +
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
350 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
351 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
352 labs(x = "Samples", y = "Relative contribution") + theme_bw() +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
353 theme(panel.grid.minor.x = element_blank(), panel.grid.major.x = element_blank(), legend.position = "right",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
354 text = element_text(size = 8),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
355 axis.text.x = element_text(angle = 90, hjust = 1))
1
c73aa7cc4c4b "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 6ca5597637439c87b61af2dbd6c38089b29eca37"
artbio
parents: 0
diff changeset
356 }
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
357 #####
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
358 # ggplot2 alternative
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
359 if (!is.na(opt$levels)[1]) { # if there are levels to display in graphs
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
360 pc3_data <- pc3$data
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
361 pc3_data <- merge(pc3_data, metadata_table[, c(1, 3)], by.x = "Sample", by.y = "element_identifier")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
362 pc3 <- ggplot(pc3_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
363 geom_bar(stat = "identity", position = "stack") +
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
364 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
365 labs(x = "Samples", y = "Absolute contribution") + theme_bw() +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
366 theme(panel.grid.minor.x = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
367 panel.grid.major.x = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
368 legend.position = "right",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
369 text = element_text(size = 8),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
370 axis.text.x = element_text(angle = 90, hjust = 1)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
371 facet_grid(~level, scales = "free_x", space = "free")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
372 pc4_data <- pc4$data
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
373 pc4_data <- merge(pc4_data, metadata_table[, c(1, 3)], by.x = "Sample", by.y = "element_identifier")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
374 pc4 <- ggplot(pc4_data, aes(x = Sample, y = Contribution, fill = as.factor(Signature))) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
375 geom_bar(stat = "identity", position = "fill") +
8
abf0dc1bc5b1 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 13d907bd98700858433fc28c6bf2d92e9012bfb2"
artbio
parents: 7
diff changeset
376 scale_fill_manual(name = tag, values = signature_colors[colnames(sbs_signatures)]) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
377 scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
378 labs(x = "Samples", y = "Relative contribution") + theme_bw() +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
379 theme(panel.grid.minor.x = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
380 panel.grid.major.x = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
381 legend.position = "right",
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
382 text = element_text(size = 8),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
383 axis.text.x = element_text(angle = 90, hjust = 1)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
384 facet_grid(~level, scales = "free_x", space = "free")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
385 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
386 # Combine the two plots:
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
387 grid.arrange(pc3, pc4,
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
388 top = textGrob("Absolute and Relative Contributions of elementary signatures to mutational profiles",
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
389 gp = gpar(fontsize = 12, font = 3)))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
390
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
391 #### pie charts of comic signatures contributions in samples ###
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
392 library(reshape2)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
393 library(dplyr)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
394 if (length(levels(factor(levels_table$level))) < 2) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
395 fit_res_contrib <- as.data.frame(fit_res$contribution)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
396 worklist <- cbind(signature = rownames(fit_res$contribution),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
397 level = rep("nolabels", length(fit_res_contrib[, 1])),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
398 fit_res_contrib,
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
399 sum = rowSums(fit_res_contrib))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
400 worklist <- worklist[order(worklist[, "sum"], decreasing = T), ]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
401 worklist <- worklist[1:opt$signum, ]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
402 worklist <- worklist[, -length(worklist[1, ])]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
403 worklist <- melt(worklist)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
404 worklist <- worklist[, c(1, 3, 4, 2)]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
405 } else {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
406 worklist <- list()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
407 for (i in levels(factor(levels_table$level))) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
408 fit_res$contribution[, levels_table$element_identifier[levels_table$level == i]] -> worklist[[i]]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
409 sum <- rowSums(as.data.frame(worklist[[i]]))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
410 worklist[[i]] <- cbind(worklist[[i]], sum)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
411 worklist[[i]] <- worklist[[i]][order(worklist[[i]][, "sum"], decreasing = T), ]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
412 worklist[[i]] <- worklist[[i]][1:opt$signum, ]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
413 worklist[[i]] <- worklist[[i]][, -length(as.data.frame(worklist[[i]]))]
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
414 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
415 worklist <- as.data.frame(melt(worklist))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
416 worklist[, 2] <- paste0(worklist[, 4], " - ", worklist[, 2])
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
417 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
418
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
419 colnames(worklist) <- c("signature", "sample", "value", "level")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
420 worklist <- as.data.frame(worklist %>% group_by(sample) %>% mutate(value = value / sum(value) * 100))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
421 worklist$pos <- cumsum(worklist$value) - worklist$value / 2
7
4a33d3b1b17c "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 91415d0273efacfc605199a8fbebaf421da9df7e"
artbio
parents: 6
diff changeset
422 worklist$label <- factor(gsub("SBS", "", worklist$signature))
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
423 worklist$signature <- factor(worklist$signature)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
424 p7 <- ggplot(worklist, aes(x = "", y = value, group = signature, fill = signature)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
425 geom_bar(width = 1, stat = "identity") +
7
4a33d3b1b17c "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 91415d0273efacfc605199a8fbebaf421da9df7e"
artbio
parents: 6
diff changeset
426 geom_text(aes(label = label), position = position_stack(vjust = 0.5), color = "white", size = 3) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
427 coord_polar("y", start = 0) + facet_wrap(.~sample) +
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
428 labs(x = "", y = "Samples", fill = tag) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
429 scale_fill_manual(name = paste0(opt$signum, " most contributing\nsignatures\n(in each label/tissue)"),
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
430 values = signature_colors[levels(worklist$signature)],
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
431 labels = names(signature_colors[levels(worklist$signature)])) +
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
432 theme(axis.text = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
433 axis.ticks = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
434 panel.grid = element_blank())
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
435 grid.arrange(p7)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
436
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
437 # Plot relative contribution of the cancer signatures in each sample as a heatmap with sample clustering
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
438 if (length(vcf_paths) > 1) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
439 p8 <- plot_contribution_heatmap(fit_res$contribution, cluster_samples = TRUE, method = "complete")
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
440 grid.arrange(p8)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
441 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
442
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
443 # export relative contribution matrix
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
444 if (!is.na(opt$sig_contrib_matrix)) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
445 output_table <- t(fit_res$contribution) / rowSums(t(fit_res$contribution))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
446 if (length(levels(factor(levels_table$level))) > 1) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
447 output_table <- data.frame(sample = paste0(metadata_table[metadata_table$element_identifier == colnames(fit_res$contribution),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
448 3], "-", colnames(fit_res$contribution)),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
449 output_table)
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
450 colnames(output_table) <- gsub("X", "SBS", colnames(output_table))
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
451 } else {
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
452 output_table <- data.frame(sample = rownames(output_table), output_table)
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
453 colnames(output_table) <- gsub("X", "SBS", colnames(output_table))
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
454 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
455 write.table(output_table, file = opt$sig_contrib_matrix, sep = "\t", quote = F, row.names = F)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
456 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
457
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
458 # calculate all pairwise cosine similarities
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
459 cos_sim_ori_rec <- cos_sim_matrix(pseudo_mut_mat, fit_res$reconstructed)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
460 # extract cosine similarities per sample between original and reconstructed
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
461 cos_sim_ori_rec <- as.data.frame(diag(cos_sim_ori_rec))
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
462
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
463 # We can use ggplot to make a barplot of the cosine similarities between the original and
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
464 # reconstructed mutational profile of each sample. This clearly shows how well each mutational
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
465 # profile can be reconstructed with the COSMIC mutational signatures. Two identical profiles
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
466 # have a cosine similarity of 1. The lower the cosine similarity between original and
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
467 # reconstructed, the less well the original mutational profile can be reconstructed with
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
468 # the COSMIC signatures. You could use, for example, cosine similarity of 0.95 as a cutoff.
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
469
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
470 # Adjust data frame for plotting with gpplot
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
471 colnames(cos_sim_ori_rec) <- "cos_sim"
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
472 cos_sim_ori_rec$sample <- row.names(cos_sim_ori_rec)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
473 # Make barplot
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
474 p9 <- ggplot(cos_sim_ori_rec, aes(y = cos_sim, x = sample)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
475 geom_bar(stat = "identity", fill = "skyblue4") +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
476 coord_cartesian(ylim = c(0.8, 1)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
477 # coord_flip(ylim=c(0.8,1)) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
478 ylab("Cosine similarity\n original VS reconstructed") +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
479 xlab("") +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
480 # Reverse order of the samples such that first is up
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
481 # xlim(rev(levels(factor(cos_sim_ori_rec$sample)))) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
482 theme_bw() +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
483 theme(panel.grid.minor.y = element_blank(),
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
484 panel.grid.major.y = element_blank()) +
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
485 # Add cut.off line
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
486 geom_hline(aes(yintercept = .95))
4
cc970189f369 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 1cb9c8fd0c74943a8e6de4c63ac5e4a84ef27430"
artbio
parents: 3
diff changeset
487 grid.arrange(p9, top = textGrob("Similarity between true profiles and profiles reconstructed with elementary signatures", gp = gpar(fontsize = 12, font = 3)))
0
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
488 dev.off()
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
489 }
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
490
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
491
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
492 # Output RData file
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
493 if (!is.null(opt$rdata)) {
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
494 save.image(file = opt$rdata)
d585f369bfad "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit 518fb067e8206ecafbf673a5e4cf375ccead11e3"
artbio
parents:
diff changeset
495 }