annotate mutational_patterns.R @ 2:aea952be68cb draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
author artbio
date Wed, 16 Sep 2020 22:58:28 +0000
parents 924c527fb379
children e332cf9dfa06
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
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
2 options( show.error.messages=F,
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
3 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
4 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
5 warnings()
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
6 library(optparse)
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
7 library(rjson)
2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
8 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
9 library(gridExtra)
0
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
10
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
11 # Arguments
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
12 option_list = list(
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
13 make_option(
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
14 "--inputs",
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
15 default = NA,
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
16 type = 'character',
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
17 help = "json formatted dictionary of datasets and their paths"
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
18 ),
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
19 make_option(
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
20 "--genome",
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
21 default = NA,
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
22 type = 'character',
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
23 help = "genome name in the BSgenome bioconductor package"
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
24 ),
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
25 make_option(
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
26 "--levels",
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
27 default = NA,
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
28 type = 'character',
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
29 help = "path to the tab separated file describing the levels in function of datasets"
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
30 ),
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
31 make_option(
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
32 "--signum",
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
33 default = 2,
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
34 type = 'integer',
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
35 help = "selects the N most significant signatures in samples to express mutational patterns"
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
36 ),
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
37 make_option(
2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
38 "--nrun",
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
39 default = 2,
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
40 type = 'integer',
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
41 help = "Number of runs to fit signatures"
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
42 ),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
43 make_option(
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
44 "--rank",
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
45 default = 2,
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
46 type = 'integer',
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
47 help = "number of ranks to display for parameter optimization"
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
48 ),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
49 make_option(
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
50 "--newsignum",
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
51 default = 2,
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
52 type = 'integer',
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
53 help = "Number of new signatures to be captured"
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
54 ),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
55
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
56 make_option(
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
57 "--output_spectrum",
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
58 default = NA,
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
59 type = 'character',
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
60 help = "path to output dataset"
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
61 ),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
62 make_option(
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
63 "--output_denovo",
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
64 default = NA,
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
65 type = 'character',
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
66 help = "path to output dataset"
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
67 ),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
68 make_option(
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
69 "--output_cosmic",
0
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
70 default = NA,
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
71 type = 'character',
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
72 help = "path to output dataset"
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
73 )
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
74 )
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
75
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
76 opt = parse_args(OptionParser(option_list = option_list),
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
77 args = commandArgs(trailingOnly = TRUE))
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
78
2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
79 ################ 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
80 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
81 parser <- newJSONParser()
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
82 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
83 fileslist <- parser$getObject()
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
84 vcf_files <- attr(fileslist, "names")
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
85 sample_names <- unname(unlist(fileslist))
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
86 ref_genome <- opt$genome
2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
87 vcf_table <- data.frame(sample_name=sample_names, path=vcf_files)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
88
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
89 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
90 library(ref_genome, character.only = TRUE)
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
91
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
92 # Load the VCF files into a GRangesList:
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
93 vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome)
2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
94 if (!is.na(opt$levels)[1]) { # manage levels if there are
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
95 levels_table <- read.delim(opt$levels, header=FALSE, col.names=c("sample_name","level"))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
96 library(dplyr)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
97 metadata_table <- left_join(vcf_table, levels_table, by = "sample_name")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
98 # detach("package:dplyr", unload=TRUE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
99 tissue <- metadata_table$level
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
100 }
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
101
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
102 ##### 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
103 mut_mat <- mut_matrix(vcf_list = vcfs, ref_genome = ref_genome)
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
104
924c527fb379 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit e1f3ca871f13569401f41a5af9d0e281bf372540"
artbio
parents:
diff changeset
105
2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
106 ###### 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
107 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
108 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
109 type_occurrences <- mut_type_occurrences(vcfs, ref_genome)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
110
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
111 # mutation spectrum, total or by sample
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
112
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
113 if (is.na(opt$levels)[1]) {
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
114 p1 <- plot_spectrum(type_occurrences, CT = TRUE, legend=TRUE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
115 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
116 } else {
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
117 p2 <- plot_spectrum(type_occurrences, by = tissue, CT=TRUE, legend=TRUE) # by sample
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
118 p3 <- plot_spectrum(type_occurrences, CT=TRUE, legend=TRUE) # total
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
119 grid.arrange(p2, p3, ncol=2, widths=c(4,2.3), heights=c(4,1))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
120 }
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
121 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
122 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
123 }
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
124
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
125 ###### Section 2: De novo mutational signature extraction using NMF #######
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
126 if (!is.na(opt$output_denovo)[1]) {
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
127 mut_mat <- mut_mat + 0.0001 # First add a small psuedocount to the mutation count matrix
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
128 # 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
129 library("NMF")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
130 estimate <- nmf(mut_mat, rank=1:opt$rank+1, method="brunet", nrun=opt$nrun, seed=123456)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
131 # 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
132 pdf(opt$output_denovo, 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
133 p.trans <- plot(estimate)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
134 grid.arrange(p.trans)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
135 # 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
136 # (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
137 # to achieve stability and avoid local minima)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
138 nmf_res <- extract_signatures(mut_mat, rank=opt$rank, nrun=opt$nrun)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
139 # Assign signature names
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
140 colnames(nmf_res$signatures) <- paste0("NewSig_", 1:opt$rank)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
141 rownames(nmf_res$contribution) <- paste0("NewSig_", 1:opt$rank)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
142 # Plot the 96-profile of 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
143 p.trans <- plot_96_profile(nmf_res$signatures, 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
144 grid.arrange(p.trans)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
145 # Visualize the contribution of the signatures in a barplot
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
146 pc1 <- plot_contribution(nmf_res$contribution, nmf_res$signature, mode="relative", coord_flip = TRUE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
147 # Visualize the contribution of the signatures in absolute number of mutations
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
148 pc2 <- plot_contribution(nmf_res$contribution, nmf_res$signature, mode="absolute", coord_flip = TRUE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
149 # 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
150 grid.arrange(pc1, pc2)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
151
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
152 # 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
153 # 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
154 # 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
155 # 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
156 # Plot signature contribution as a heatmap with sample clustering dendrogram and a specified signature order:
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
157 pch1 <- plot_contribution_heatmap(nmf_res$contribution,
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
158 sig_order = paste0("NewSig_", 1:opt$rank))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
159 # Plot signature contribution as a heatmap without sample clustering:
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
160 pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples=FALSE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
161 #Combine the plots into one figure:
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
162 grid.arrange(pch1, pch2, ncol = 2, widths = c(2,1.6))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
163
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
164 # Compare the reconstructed mutational profile with the original mutational profile:
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
165 plot_compare_profiles(mut_mat[,1],
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
166 nmf_res$reconstructed[,1],
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
167 profile_names = c("Original", "Reconstructed"),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
168 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
169 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
170 }
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
171 ##### Section 3: Find optimal contribution of known signatures: COSMIC mutational signatures ####
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
172
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
173 if (!is.na(opt$output_cosmic)[1]) {
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
174 pdf(opt$output_cosmic, 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
175 sp_url <- paste("https://cancer.sanger.ac.uk/cancergenome/assets/", "signatures_probabilities.txt", sep = "")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
176 cancer_signatures = read.table(sp_url, sep = "\t", header = TRUE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
177 mut_mat <- mut_mat + 0.0001 # First add a small psuedocount to the mutation count matrix
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
178 new_order = match(row.names(mut_mat), cancer_signatures$Somatic.Mutation.Type)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
179 cancer_signatures = cancer_signatures[as.vector(new_order),]
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
180 row.names(cancer_signatures) = cancer_signatures$Somatic.Mutation.Type
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
181 cancer_signatures = as.matrix(cancer_signatures[,4:33])
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
182
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
183 # Plot mutational profiles of the COSMIC signatures
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
184 colnames(cancer_signatures) <- gsub("Signature.", "", colnames(cancer_signatures)) # shorten signature labels
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
185 p.trans <- plot_96_profile(cancer_signatures, condensed = TRUE, ymax = 0.3)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
186 grid.arrange(p.trans, top = textGrob("COSMIC signature profiles",gp=gpar(fontsize=12,font=3)))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
187
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
188 # Hierarchically cluster the COSMIC signatures based on their similarity with average linkage
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
189 # hclust_cosmic = cluster_signatures(cancer_signatures, method = "average")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
190 # store signatures in new order
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
191 # cosmic_order = colnames(cancer_signatures)[hclust_cosmic$order]
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
192 # plot(hclust_cosmic)
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 # Similarity between mutational profiles and COSMIC signatures
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
195
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
196
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
197 # The similarity between each mutational profile and each COSMIC signature, can be calculated
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
198 # with cos_sim_matrix, and visualized with plot_cosine_heatmap. The cosine similarity reflects
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
199 # how well each mutational profile can be explained by each signature individually. The advantage
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
200 # of this heatmap representation is that it shows in a glance the similarity in mutational
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
201 # profiles between samples, while at the same time providing information on which signatures
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
202 # are most prominent. The samples can be hierarchically clustered in plot_cosine_heatmap.
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
203 # The cosine similarity between two mutational profiles/signatures can be calculated with cos_sim :
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
204 # cos_sim(mut_mat[,1], cancer_signatures[,1])
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
205
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
206 # Calculate pairwise cosine similarity between mutational profiles and COSMIC signatures
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
207
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
208 # cos_sim_samples_signatures = cos_sim_matrix(mut_mat, cancer_signatures)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
209 # Plot heatmap with specified signature order
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
210 # p.trans <- plot_cosine_heatmap(cos_sim_samples_signatures, col_order = cosmic_order, cluster_rows = TRUE)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
211 # grid.arrange(p.trans)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
212
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
213 # Find optimal contribution of COSMIC signatures to reconstruct 96 mutational profiles
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
214 fit_res <- fit_to_signatures(mut_mat, cancer_signatures)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
215
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
216 # Select signatures with some contribution (above a threshold)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
217 threshold <- tail(sort(unlist(rowSums(fit_res$contribution), use.names = FALSE)), opt$signum)[1]
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
218 select <- which(rowSums(fit_res$contribution) >= threshold) # ensure opt$signum best signatures in samples are retained, the others discarded
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
219 # Plot contribution barplots
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
220 pc1 <- plot_contribution(fit_res$contribution[select,], cancer_signatures[,select], coord_flip = T, mode = "absolute")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
221 pc2 <- plot_contribution(fit_res$contribution[select,], cancer_signatures[,select], coord_flip = T, mode = "relative")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
222 # 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
223 grid.arrange(pc1, pc2)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
224 ## pie charts of comic signatures contributions in samples
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
225
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
226 sig_data_pie <- as.data.frame(t(head(fit_res$contribution[select,])))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
227 colnames(sig_data_pie) <- gsub("nature", "", colnames(sig_data_pie))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
228 sig_data_pie_percents <- sig_data_pie / (apply(sig_data_pie,1,sum)) * 100
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
229 sig_data_pie_percents$sample <- rownames(sig_data_pie_percents)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
230 library(reshape2)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
231 melted_sig_data_pie_percents <-melt(data=sig_data_pie_percents)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
232 melted_sig_data_pie_percents$label <- sub("Sig.", "", melted_sig_data_pie_percents$variable)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
233 melted_sig_data_pie_percents$pos <- cumsum(melted_sig_data_pie_percents$value) - melted_sig_data_pie_percents$value/2
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
234 library(ggplot2)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
235 p.trans <- ggplot(melted_sig_data_pie_percents, aes(x="", y=value, group=variable, fill=variable)) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
236 geom_bar(width = 1, stat = "identity") +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
237 geom_text(aes(label = label), position = position_stack(vjust = 0.5), color="black", size=3) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
238 coord_polar("y", start=0) + facet_wrap(~ sample) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
239 labs(x="", y="Samples", fill = "Signatures (Cosmic_v2,March 2015)") +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
240 theme(axis.text = element_blank(),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
241 axis.ticks = element_blank(),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
242 panel.grid = element_blank())
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
243 grid.arrange(p.trans)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
244
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
245 # Plot relative contribution of the cancer signatures in each sample as a heatmap with sample clustering
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
246 p.trans <- plot_contribution_heatmap(fit_res$contribution, cluster_samples = TRUE, method = "complete")
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
247 grid.arrange(p.trans)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
248
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
249 # Compare the reconstructed mutational profile of sample 1 with its original mutational profile
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
250 # plot_compare_profiles(mut_mat[,1], fit_res$reconstructed[,1],
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
251 # profile_names = c("Original", "Reconstructed"),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
252 # 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
253
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
254 # Calculate the cosine similarity between all original and reconstructed mutational profiles with
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
255 # `cos_sim_matrix`
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
256
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
257 # calculate all pairwise cosine similarities
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
258 cos_sim_ori_rec <- cos_sim_matrix(mut_mat, fit_res$reconstructed)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
259 # 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
260 cos_sim_ori_rec <- as.data.frame(diag(cos_sim_ori_rec))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
261
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
262 # 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
263 # 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
264 # 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
265 # 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
266 # 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
267 # the COSMIC signatures. You could use, for example, cosine similarity of 0.95 as a cutoff.
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
268
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
269 # Adjust data frame for plotting with gpplot
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
270 colnames(cos_sim_ori_rec) = "cos_sim"
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
271 cos_sim_ori_rec$sample = row.names(cos_sim_ori_rec)
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
272 # Make barplot
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
273 p.trans <- ggplot(cos_sim_ori_rec, aes(y=cos_sim, x=sample)) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
274 geom_bar(stat="identity", fill = "skyblue4") +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
275 coord_cartesian(ylim=c(0.8, 1)) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
276 # coord_flip(ylim=c(0.8,1)) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
277 ylab("Cosine similarity\n original VS reconstructed") +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
278 xlab("") +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
279 # Reverse order of the samples such that first is up
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
280 # xlim(rev(levels(factor(cos_sim_ori_rec$sample)))) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
281 theme_bw() +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
282 theme(panel.grid.minor.y=element_blank(),
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
283 panel.grid.major.y=element_blank()) +
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
284 # Add cut.off line
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
285 geom_hline(aes(yintercept=.95))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
286 grid.arrange(p.trans, top = textGrob("Similarity between true and reconstructed profiles (with all Cosmic sig.)",gp=gpar(fontsize=12,font=3)))
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
287
aea952be68cb "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mutational_patterns commit cd8f633245d53cf47eaf860a4e0ae8d806c34419"
artbio
parents: 0
diff changeset
288 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
289 }