annotate sequenza_to_hrdtools_input.R @ 2:e0724d649885 draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 116f2555558a283190cd1dd60ee25b359bcda51e
author artbio
date Fri, 20 May 2022 17:07:54 +0000
parents b77d7a0a45e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
1 options(show.error.messages = F, error = function() {
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
2 cat(geterrmessage(), file = stderr()); q("no", 1, F) })
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
3
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
4 # load packages that are provided in the conda env
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
5
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
6 library(optparse)
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
7 library(tidyverse)
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
8
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
9 option_list <- list(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
10 make_option(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
11 c("-i", "--input"),
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
12 default = NA,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
13 type = "character",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
14 help = "Path to Sequenza output segments file"
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
15 ),
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
16 make_option(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
17 c("-o", "--output"),
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
18 default = NA,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
19 type = "character",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
20 help = "output file, to be used as input for HRDetect"
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
21 ),
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
22 make_option(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
23 c("-s", "--solutions"),
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
24 default = NA,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
25 type = "character",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
26 help = "Path to Sequenza list of alternative solutions"
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
27 )
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
28 )
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
29
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
30 opt <- parse_args(OptionParser(option_list = option_list),
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
31 args = commandArgs(trailingOnly = TRUE))
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
32
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
33 sequenza_data <- as_tibble(read.delim(opt$input, header = TRUE))
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
34 solutions_data <- as_tibble(read.delim(opt$solutions, header = TRUE))
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
35
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
36
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
37 ploidy <- round(solutions_data$ploidy[1])
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
38 cellularity <- solutions_data$cellularity[1]
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
39
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
40 reformatted <- sequenza_data %>%
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
41 select(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
42 chr = chromosome,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
43 start = start.pos,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
44 end = end.pos,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
45 copynumber = CNt,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
46 A, B
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
47 ) %>%
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
48 mutate(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
49 ploidy = ploidy,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
50 cellularity = cellularity,
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
51 lohtype = case_when(
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
52 copynumber == 0 ~ "HOMD",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
53 B == 0 & A == ploidy ~ "NLOH",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
54 B == 0 & A < ploidy & A > 0 ~ "DLOH",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
55 copynumber > ploidy & A > B ~ "ASCNA",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
56 copynumber > ploidy & A == B ~ "BCNA",
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
57 TRUE ~ "HET"
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
58 )
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
59 )
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
60
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
61 message("Preview of output:")
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
62 print(reformatted)
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
63
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
64 reformatted %>%
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
65 write.table(opt$output, quote = F, row.names = F, sep = "\t")
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
66
b77d7a0a45e8 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/snvtocnv commit 10ad3a0ca7cd23ad1e0940844147e1d1b3d069f0"
artbio
parents:
diff changeset
67 message(sprintf("Output written to %s", opt$output))