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