parser.R 3.86 KiB
#' Parse the command line arguments
#'
#' Parse the command line arguments and return an object through which all
#' given arguments are stored
#' @import argparser
#' @export
cli_function <- function() {
# Create a parser
p <- arg_parser(paste0(
"Wrapper to perform DESeq2 enrichment analysis "
))
# Add command line arguments
p <- add_argument(p, "design",
type = "character",
help = paste0("A file containing the design of interest")
)
p <- add_argument(p, "path",
type = "character",
help = paste0("The folder where the tsv file are stored (default .)"),
default = "."
)
p <- add_argument(p, "formula",
type = "character",
help = "The design formula for DESeq2"
)
p <- add_argument(p, "contrasts",
type = "character",
help = paste0(
"The comparisons to perform in the form of deseq2 contrasts : ",
"each comparisons must be composed of three feature separed by a",
" '-'. The first feature corresponds to a column given in the ",
"design file an present in the --formula, the two other are ",
"the names of the fold changes for the numerator, and the names ",
"of the fold changes for the denominator"
)
)
p <- add_argument(p, "--output",
short = "-o", type = "character",
help = "folder were the results will be created",
default = "."
)
p <- add_argument(p, "--filter",
short = "-f", type = "character",
help = "A file containg the genes id to keep", default = ""
)
p <- add_argument(p, "--gene_expression_threshold",
short = "-g", type = "integer",
help = "A threshold to keep genes with at least this average expression
across all samples prior to deseq2 analysis", default = 2
)
p <- add_argument(p, "--basemean_threshold",
short = "-b", type = "integer",
help = "A threshold to keep significant genes with at least this
baseMean (after deseq2 analysis)", default = 0
)
p <- add_argument(p, "--lfc_threshold",
short = "-l", type = "integer",
help = "A threshold to keep significant genes with at least this
log2fc", default = 0
)
p <- add_argument(p, "--gene_names",
short = "-c", type = "character",
help = paste0("Optional: A file containing the correspondance between geneIDs and gene names",
"The first colomn contains geneIDs and the header is 'gene'",
"The second colomn contains corresponding gene names and the header is 'gene_name"),
default = ""
)
p <- add_argument(p, "--norm",
short = "-n", type = "character",
help = paste0("A two column dataframe containing the",
"columns sample and size_factor. Sample",
" column must correspond to the samples",
" name given in design file. Size_factor",
"correspond to the scaling value to apply",
"to count data in deseq2"),
default = "")
# Parse de command line arguments
argv <- argparser::parse_args(p)
if (is.null(argv$design) || is.null(argv$formula) || is.null(argv$contrasts)) {
if (is.null(argv$design)) {
msg <- paste0(
"Argument --design is required !,",
" see --help for more information."
)
}
if (is.null(argv$formula)) {
msg <- paste0(
msg, "\n Argument --formula is required !,",
" see --help for more information."
)
}
stop(msg)
}
return(argv)
}