Skip to content

Commit

Permalink
Upgrade Center_scale tool (#644)
Browse files Browse the repository at this point in the history
* bump tool version

* change dev repo url

* upgrade R environnement

* fix center_scale.R code
  • Loading branch information
drosofff authored Oct 15, 2023
1 parent 40b5e58 commit 41ba543
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 67 deletions.
4 changes: 2 additions & 2 deletions tools/gsc_center_scale/.shed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ long_description: |
Mean centers, standard deviation rescales, or does both operations on single cell
transcriptomic data, or any type of numerical data
categories:
- Transcriptomics
- Statistics
homepage_url: http://artbio.fr
remote_repository_url: https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_center_scale
remote_repository_url: https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_center_scale
toolshed:
- toolshed
116 changes: 54 additions & 62 deletions tools/gsc_center_scale/center_scale.R
Original file line number Diff line number Diff line change
@@ -1,103 +1,95 @@
options( show.error.messages=F,
error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
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()
library(optparse)

# Arguments
option_list = list(
option_list <- list(
make_option(
'--data',
"--data",
default = NA,
type = 'character',
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',
"--center",
default = TRUE,
type = 'logical',
type = "logical",
help = "center data to the mean [default : '%default' ]"
),
make_option(
'--scale',
"--scale",
default = TRUE,
type = 'logical',
type = "logical",
help = "scale data to standard deviation [default : '%default' ]"
),
make_option(
'--factor',
default = '',
type = 'character',
"--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',
"--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)))
transform <- function(df, center = TRUE, scale = TRUE) {
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))
opt <- parse_args(OptionParser(option_list = option_list),
args = commandArgs(trailingOnly = TRUE))

data = read.table(
opt$data,
check.names = FALSE,
header = TRUE,
row.names = 1,
sep = '\t'
data <- read.delim(
opt$data,
check.names = FALSE,
header = TRUE,
row.names = 1,
sep = "\t"
)

if (opt$factor != '') {
data.factor = read.table(
opt$factor,
check.names = FALSE,
header = TRUE,
sep = '\t'
)
colnames(data.factor) <- c("cellid", "level")
data.transformed <- data.frame(row.names=rownames(data), stringsAsFactors=FALSE)
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)
}
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)
}
} 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),
cbind(gene = rownames(data_transformed), data_transformed),
opt$output,
col.names = TRUE,
row.names = FALSE,
quote = F,
quote = FALSE,
sep = "\t"
)












6 changes: 3 additions & 3 deletions tools/gsc_center_scale/center_scale.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tool id="center_scale" name="Center or scale (standardize) data" version="0.9.5">
<tool id="center_scale" name="Center or scale (standardize) data" version="4.3.1+galaxy0" profile="21.01">
<description></description>
<requirements>
<requirement type="package" version="1.6.0">r-optparse</requirement>
<requirement type="package" version="1.7.3">r-optparse</requirement>
</requirements>
<stdio>
<exit_code range="1:" level="fatal" description="Tool exception" />
Expand Down Expand Up @@ -94,7 +94,7 @@
The tool perform various normalization operations on a data table, including mean centering,
standard deviation rescaling, or both (standardization).

In addition, these operations can be performed on subsets of observations, is the user provides
In addition, these operations can be performed on subsets of observations, if the user provides
a two-column table that maps observations to groups (factor levels).

**Inputs**
Expand Down

0 comments on commit 41ba543

Please sign in to comment.