diff --git a/tools/gsc_filter_genes/.shed.yml b/tools/gsc_filter_genes/.shed.yml index d417ce709..1b4b55bdf 100644 --- a/tools/gsc_filter_genes/.shed.yml +++ b/tools/gsc_filter_genes/.shed.yml @@ -5,6 +5,7 @@ description: Filter genes that are detected in less than a fraction of libraries long_description: categories: - Transcriptomics + - Single Cell homepage_url: http://artbio.fr remote_repository_url: https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_filter_genes toolshed: diff --git a/tools/gsc_filter_genes/filter_genes.R b/tools/gsc_filter_genes/filter_genes.R index 3fadd69d6..407fbbfaf 100644 --- a/tools/gsc_filter_genes/filter_genes.R +++ b/tools/gsc_filter_genes/filter_genes.R @@ -4,83 +4,84 @@ # Rscript filter_genes.R -f -o # load packages that are provided in the conda env -options(show.error.messages = FALSE, - error = function() { - cat(geterrmessage(), file = stderr()) - q("no", 1, FALSE) - } +options( + show.error.messages = FALSE, + error = function() { + cat(geterrmessage(), file = stderr()) + q("no", 1, FALSE) + } ) loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") library(optparse) # Arguments option_list <- list( - make_option( - c("-f", "--input"), - default = NA, - type = "character", - help = "Input file that contains count values to filter" - ), - make_option( - c("-s", "--sep"), - default = "\t", - type = "character", - help = "File separator [default : '%default' ]" - ), - make_option( - c("-c", "--colnames"), - default = TRUE, - type = "logical", - help = "first line is a header [default : '%default' ]" - ), - make_option( - "--percentile_detection", - default = 0, - type = "numeric", - help = "Include genes with detected expression in at least \ + make_option( + c("-f", "--input"), + default = NA, + type = "character", + help = "Input file that contains count values to filter" + ), + make_option( + c("-s", "--sep"), + default = "\t", + type = "character", + help = "File separator [default : '%default' ]" + ), + make_option( + c("-c", "--colnames"), + default = TRUE, + type = "logical", + help = "first line is a header [default : '%default' ]" + ), + make_option( + "--percentile_detection", + default = 0, + type = "numeric", + help = "Include genes with detected expression in at least \ this fraction of cells [default : '%default' ]" - ), - make_option( - "--absolute_detection", - default = 0, - type = "numeric", - help = "Include genes with detected expression in at least \ + ), + make_option( + "--absolute_detection", + default = 0, + type = "numeric", + help = "Include genes with detected expression in at least \ this number of cells [default : '%default' ]" - ), - make_option( - c("-o", "--output"), - default = NA, - type = "character", - help = "Output name [default : '%default' ]" - ) + ), + make_option( + c("-o", "--output"), + default = NA, + type = "character", + help = "Output name [default : '%default' ]" + ) ) opt <- parse_args(OptionParser(option_list = option_list), - args = commandArgs(trailingOnly = TRUE)) + args = commandArgs(trailingOnly = TRUE) +) if (opt$sep == "tab") { - opt$sep <- "\t" + opt$sep <- "\t" } if (opt$sep == "comma") { - opt$sep <- "," + opt$sep <- "," } # Open files data.counts <- read.delim( - opt$input, - h = opt$colnames, - row.names = 1, - sep = opt$sep, - check.names = FALSE + opt$input, + h = opt$colnames, + row.names = 1, + sep = opt$sep, + check.names = FALSE ) # note the [if else] below, to handle percentile_detection=absolute_detection=0 # Search for genes that are expressed in a certain percent of cells if (opt$percentile_detection > 0) { - kept_genes <- rowSums(data.counts != 0) >= (opt$percentile_detection * ncol(data.counts)) + kept_genes <- rowSums(data.counts != 0) >= (opt$percentile_detection * ncol(data.counts)) } else { - - # Search for genes that are expressed in more than an absolute number of cells - kept_genes <- rowSums(data.counts != 0) >= (opt$absolute_detection) + # Search for genes that are expressed in more than an absolute number of cells + kept_genes <- rowSums(data.counts != 0) >= (opt$absolute_detection) } # Filter matrix @@ -89,10 +90,10 @@ data.counts <- cbind(Genes = rownames(data.counts), data.counts) # Save filtered matrix write.table( - data.counts, - opt$output, - sep = "\t", - quote = FALSE, - col.names = TRUE, - row.names = FALSE + data.counts, + opt$output, + sep = "\t", + quote = FALSE, + col.names = TRUE, + row.names = FALSE ) diff --git a/tools/gsc_filter_genes/filter_genes.xml b/tools/gsc_filter_genes/filter_genes.xml index f3322131b..e30b9eef9 100644 --- a/tools/gsc_filter_genes/filter_genes.xml +++ b/tools/gsc_filter_genes/filter_genes.xml @@ -1,5 +1,8 @@ - + which are detected in less that a given fraction of the libraries + + galaxy_single_cell_suite + r-optparse