Skip to content

Commit

Permalink
reindent R code
Browse files Browse the repository at this point in the history
  • Loading branch information
drosofff committed Nov 7, 2024
1 parent 522b03b commit 743cf25
Showing 1 changed file with 55 additions and 54 deletions.
109 changes: 55 additions & 54 deletions tools/gsc_scran_normalize/scran-normalize.R
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -13,63 +14,63 @@ library(dynamicTreeCut)

# Arguments
option_list <- list(
make_option(
c("-d", "--data"),
default = NA,
type = "character",
help = "Input file that contains count values to transform"
),
make_option(
"--cluster",
default = FALSE,
action = "store_true",
type = "logical",
help = "Whether to calculate the size factor per cluster or on all cell"
),
make_option(
c("-m", "--method"),
default = "hclust",
type = "character",
help = "The clustering method to use for grouping cells into cluster : hclust or igraph [default : '%default' ]"
),
make_option(
"--size",
default = 100,
type = "integer",
help = "Minimal number of cells in each cluster : hclust or igraph [default : '%default' ]"
),
make_option(
c("-o", "--out"),
default = "res.tab",
type = "character",
help = "Output name [default : '%default' ]"
)
make_option(
c("-d", "--data"),
default = NA,
type = "character",
help = "Input file that contains count values to transform"
),
make_option(
"--cluster",
default = FALSE,
action = "store_true",
type = "logical",
help = "Whether to calculate the size factor per cluster or on all cell"
),
make_option(
c("-m", "--method"),
default = "hclust",
type = "character",
help = "The clustering method to use for grouping cells into cluster : hclust or igraph [default : '%default' ]"
),
make_option(
"--size",
default = 100,
type = "integer",
help = "Minimal number of cells in each cluster : hclust or igraph [default : '%default' ]"
),
make_option(
c("-o", "--out"),
default = "res.tab",
type = "character",
help = "Output name [default : '%default' ]"
)
)

opt <- parse_args(OptionParser(option_list = option_list),
args = commandArgs(trailingOnly = TRUE))
args = commandArgs(trailingOnly = TRUE)
)


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

## Import data as a SingleCellExperiment object
sce <- SingleCellExperiment(list(counts = as.matrix(data)))

if (opt$cluster) {
clusters <- quickCluster(sce, min.size = opt$size, method = opt$method)
clusters <- quickCluster(sce, min.size = opt$size, method = opt$method)

## Compute sum factors
sce <- computeSumFactors(sce, cluster = clusters)
## Compute sum factors
sce <- computeSumFactors(sce, cluster = clusters)
} else {

## Compute sum factors
sce <- computeSumFactors(sce)
## Compute sum factors
sce <- computeSumFactors(sce)
}

sce <- logNormCounts(sce)
Expand All @@ -78,10 +79,10 @@ logcounts <- data.frame(genes = rownames(sce), round(logcounts(sce), digits = 5)


write.table(
logcounts,
opt$out,
col.names = TRUE,
row.names = FALSE,
quote = FALSE,
sep = "\t"
logcounts,
opt$out,
col.names = TRUE,
row.names = FALSE,
quote = FALSE,
sep = "\t"
)

0 comments on commit 743cf25

Please sign in to comment.