Mercurial > repos > artbio > gsc_center_scale
changeset 3:b7daf62bde65 draft default tip
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_center_scale commit 44d7e1048de3a58983e0559581264147090fefb0
author | artbio |
---|---|
date | Thu, 07 Nov 2024 18:54:17 +0000 |
parents | 163befe5f05b |
children | |
files | center_scale.R center_scale.xml |
diffstat | 2 files changed, 80 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/center_scale.R Sun Oct 15 16:16:16 2023 +0000 +++ b/center_scale.R Thu Nov 07 18:54:17 2024 +0000 @@ -1,8 +1,9 @@ -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") warnings() @@ -10,86 +11,91 @@ # Arguments option_list <- list( - make_option( - "--data", - default = NA, - type = "character", - help = "Input file that contains values to transform. Must be tabular separated, + make_option( + "--data", + default = NA, + type = "character", + help = "Input file that contains values to transform. Must be tabular separated, with columns and row names, variables in rows, observations in columns [default : '%default' ]" - ), - make_option( - "--center", - default = TRUE, - type = "logical", - help = "center data to the mean [default : '%default' ]" - ), - make_option( - "--scale", - default = TRUE, - type = "logical", - help = "scale data to standard deviation [default : '%default' ]" - ), - make_option( - "--factor", - default = "", - type = "character", - help = "A two-column observations|factor_levels table, to group observations to be transformed by levels [default : '%default' ]" - ), - make_option( - "--output", - default = "res.tab", - type = "character", - help = "Table of transformed values [default : '%default' ]" - ) + ), + make_option( + "--center", + default = TRUE, + type = "logical", + help = "center data to the mean [default : '%default' ]" + ), + make_option( + "--scale", + default = TRUE, + type = "logical", + help = "scale data to standard deviation [default : '%default' ]" + ), + make_option( + "--factor", + default = "", + type = "character", + help = "A two-column observations|factor_levels table, to group observations to be transformed by levels [default : '%default' ]" + ), + make_option( + "--output", + default = "res.tab", + type = "character", + help = "Table of transformed values [default : '%default' ]" + ) ) transform <- function(df, center = TRUE, scale = TRUE) { - transfo <- scale(t(df), - center = center, - scale = scale - ) - return(as.data.frame(t(transfo))) + transfo <- scale(t(df), + center = center, + scale = scale + ) + return(as.data.frame(t(transfo))) } opt <- parse_args(OptionParser(option_list = option_list), - args = commandArgs(trailingOnly = TRUE)) + args = commandArgs(trailingOnly = TRUE) +) data <- read.delim( - opt$data, - check.names = FALSE, - header = TRUE, - row.names = 1, - sep = "\t" + opt$data, + check.names = FALSE, + header = TRUE, + row.names = 1, + sep = "\t" ) if (opt$factor != "") { - data_factor <- read.delim( - opt$factor, - check.names = FALSE, - header = TRUE, - sep = "\t", - stringsAsFactors = TRUE - ) - colnames(data_factor) <- c("cellid", "level") - data_transformed <- data.frame(row.names = rownames(data)) - for (group in levels(data_factor$level)) { - subcells <- as.data.frame(subset(data_factor, level == group, select = cellid)) - subdata <- as.data.frame(subset(data, select = as.vector(subcells$cellid))) - subdata_transformed <- transform(subdata, center = as.logical(opt$center), - scale = as.logical(opt$scale)) - data_transformed <- cbind(data_transformed, subdata_transformed) - } + data_factor <- read.delim( + opt$factor, + check.names = FALSE, + header = TRUE, + sep = "\t", + stringsAsFactors = TRUE + ) + colnames(data_factor) <- c("cellid", "level") + data_transformed <- data.frame(row.names = rownames(data)) + for (group in levels(data_factor$level)) { + subcells <- as.data.frame(subset(data_factor, level == group, select = cellid)) + subdata <- as.data.frame(subset(data, select = as.vector(subcells$cellid))) + subdata_transformed <- transform(subdata, + center = as.logical(opt$center), + scale = as.logical(opt$scale) + ) + data_transformed <- cbind(data_transformed, subdata_transformed) + } } else { - data_transformed <- transform(data, center = as.logical(opt$center), - scale = as.logical(opt$scale)) + data_transformed <- transform(data, + center = as.logical(opt$center), + scale = as.logical(opt$scale) + ) } write.table( - cbind(gene = rownames(data_transformed), data_transformed), - opt$output, - col.names = TRUE, - row.names = FALSE, - quote = FALSE, - sep = "\t" + cbind(gene = rownames(data_transformed), data_transformed), + opt$output, + col.names = TRUE, + row.names = FALSE, + quote = FALSE, + sep = "\t" )
--- a/center_scale.xml Sun Oct 15 16:16:16 2023 +0000 +++ b/center_scale.xml Thu Nov 07 18:54:17 2024 +0000 @@ -1,5 +1,8 @@ -<tool id="center_scale" name="Center or scale (standardize) data" version="4.3.1+galaxy0" profile="21.01"> +<tool id="center_scale" name="Center or scale (standardize) data" version="4.3.1+galaxy1" profile="21.01"> <description></description> + <xrefs> + <xref type="bio.tools">galaxy_single_cell_suite</xref> + </xrefs> <requirements> <requirement type="package" version="1.7.3">r-optparse</requirement> </requirements>