|
| 1 | +#!/usr/bin/env Rscript |
| 2 | + |
| 3 | +suppressPackageStartupMessages(library("optparse")) |
| 4 | +suppressPackageStartupMessages(library("readr")) |
| 5 | +suppressPackageStartupMessages(library("dplyr")) |
| 6 | +suppressPackageStartupMessages(library("magrittr")) |
| 7 | + |
| 8 | +if (!interactive()) { |
| 9 | + options(warn = -1, error = quote({ traceback(); q('no', status = 1) })) |
| 10 | +} |
| 11 | + |
| 12 | +optList = list(make_option("--option", default = NA, type = 'character', help = "analysis type"), |
| 13 | + make_option("--sample_names", default = NA, type = 'character', help = "sample names")) |
| 14 | +parser = OptionParser(usage = "%prog", option_list = optList) |
| 15 | +arguments = parse_args(parser, positional_arguments = T) |
| 16 | +opt = arguments$options |
| 17 | + |
| 18 | +if (as.numeric(opt$option)==1) { |
| 19 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 20 | + metrics = list() |
| 21 | + for (i in 1:length(sample_names)) { |
| 22 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".idx_stats.txt"), |
| 23 | + col_names = FALSE, col_types = cols(.default = col_character()))[-85,,drop=FALSE] %>% |
| 24 | + readr::type_convert() %>% |
| 25 | + dplyr::select(CHROMOSOME = X1, |
| 26 | + LENGTH = X2, |
| 27 | + ALIGNED_READS = X3) %>% |
| 28 | + dplyr::mutate(CHROMOSOME = gsub(pattern=" length=", replacement="", x=CHROMOSOME), |
| 29 | + ALIGNED_READS = gsub(pattern="Aligned= ", replacement="", x=ALIGNED_READS), |
| 30 | + SAMPLE_NAME = sample_names[i]) |
| 31 | + } |
| 32 | + metrics = do.call(rbind, metrics) |
| 33 | + write_tsv(metrics, path="summary/idx_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 34 | + |
| 35 | +} else if (as.numeric(opt$option)==2) { |
| 36 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 37 | + metrics = list() |
| 38 | + for (i in 1:length(sample_names)) { |
| 39 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".aln_metrics.txt"), |
| 40 | + skip = 6, col_names = TRUE, col_types = cols(.default = col_character())) %>% |
| 41 | + readr::type_convert() %>% |
| 42 | + dplyr::select(-SAMPLE, -READ_GROUP) %>% |
| 43 | + dplyr::mutate(SAMPLE_NAME = sample_names[i]) |
| 44 | + } |
| 45 | + metrics = do.call(rbind, metrics) |
| 46 | + write_tsv(metrics, path="summary/aln_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 47 | + |
| 48 | +} else if (as.numeric(opt$option)==3) { |
| 49 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 50 | + metrics = list() |
| 51 | + for (i in 1:length(sample_names)) { |
| 52 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".insert_metrics.txt"), |
| 53 | + skip = 6, n_max = 1, col_names = TRUE, col_types = cols(.default = col_character())) %>% |
| 54 | + readr::type_convert() %>% |
| 55 | + dplyr::select(-SAMPLE, -READ_GROUP) %>% |
| 56 | + dplyr::mutate(SAMPLE_NAME = sample_names[i]) |
| 57 | + } |
| 58 | + metrics = do.call(rbind, metrics) |
| 59 | + write_tsv(metrics, path="summary/insert_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 60 | + |
| 61 | +} else if (as.numeric(opt$option)==4) { |
| 62 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 63 | + metrics = list() |
| 64 | + for (i in 1:length(sample_names)) { |
| 65 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".oxog_metrics.txt"), |
| 66 | + skip = 6, col_names = TRUE, col_types = cols(.default = col_character())) %>% |
| 67 | + readr::type_convert() %>% |
| 68 | + dplyr::rename(SAMPLE_NAME = SAMPLE_ALIAS) |
| 69 | + } |
| 70 | + metrics = do.call(rbind, metrics) |
| 71 | + write_tsv(metrics, path="summary/oxog_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 72 | + |
| 73 | +} else if (as.numeric(opt$option)==5) { |
| 74 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 75 | + metrics = list() |
| 76 | + for (i in 1:length(sample_names)) { |
| 77 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".gc_metrics.txt"), |
| 78 | + skip = 6, col_names = TRUE, col_types = cols(.default = col_character())) %>% |
| 79 | + readr::type_convert() %>% |
| 80 | + dplyr::mutate(SAMPLE_NAME = sample_names[i]) |
| 81 | + } |
| 82 | + metrics = do.call(rbind, metrics) |
| 83 | + write_tsv(metrics, path="summary/gc_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 84 | + |
| 85 | +} else if (as.numeric(opt$option)==6) { |
| 86 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 87 | + metrics = list() |
| 88 | + for (i in 1:length(sample_names)) { |
| 89 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".wgs_metrics.txt"), |
| 90 | + skip = 6, n_max = 1, col_names = TRUE, col_types = cols(.default = col_character())) %>% |
| 91 | + readr::type_convert() %>% |
| 92 | + dplyr::mutate(SAMPLE_NAME = sample_names[i]) |
| 93 | + } |
| 94 | + metrics = do.call(rbind, metrics) |
| 95 | + write_tsv(metrics, path="summary/wgs_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 96 | + |
| 97 | +} else if (as.numeric(opt$option)==7) { |
| 98 | + sample_names = unlist(strsplit(x=as.character(opt$sample_names), split=" ", fixed=TRUE)) |
| 99 | + metrics = list() |
| 100 | + for (i in 1:length(sample_names)) { |
| 101 | + metrics[[i]] = readr::read_tsv(file = paste0("metrics/", sample_names[i], ".duplicate_metrics.txt"), |
| 102 | + skip = 6, n_max = 1, col_names = TRUE, col_types = cols(.default = col_character())) %>% |
| 103 | + readr::type_convert() %>% |
| 104 | + dplyr::mutate(SAMPLE_NAME = sample_names[i]) |
| 105 | + } |
| 106 | + metrics = do.call(rbind, metrics) |
| 107 | + write_tsv(metrics, path="summary/duplicate_metrics.txt", na = "NA", append = FALSE, col_names = TRUE) |
| 108 | + |
| 109 | +} |
0 commit comments