annotate mutational_patterns.R @ 28:9a33a5a90a2c draft default tip

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