Skip to content

Commit

Permalink
Merge pull request #705 from ARTbio/gsc_center_scale
Browse files Browse the repository at this point in the history
update gsc_center_scale
  • Loading branch information
drosofff authored Nov 7, 2024
2 parents c5b2e91 + 78050d9 commit 44d7e10
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 71 deletions.
1 change: 1 addition & 0 deletions tools/gsc_center_scale/.shed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ long_description: |
transcriptomic data, or any type of numerical data
categories:
- Statistics
- Single Cell
homepage_url: http://artbio.fr
remote_repository_url: https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_center_scale
toolshed:
Expand Down
146 changes: 76 additions & 70 deletions tools/gsc_center_scale/center_scale.R
Original file line number Diff line number Diff line change
@@ -1,95 +1,101 @@
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()
library(optparse)

# 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"
)
5 changes: 4 additions & 1 deletion tools/gsc_center_scale/center_scale.xml
Original file line number Diff line number Diff line change
@@ -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>
Expand Down

0 comments on commit 44d7e10

Please sign in to comment.