comparison sequenza_to_hrdtools_input.R @ 0:b77d7a0a45e8 draft

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