Mercurial > repos > artbio > gsc_scran_normalize
comparison scran-normalize.R @ 3:cc768b0f41cf draft default tip
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_scran_normalize commit 9ab82433f375b37be5c9acb22e5deb798081dc3b
author | artbio |
---|---|
date | Thu, 07 Nov 2024 22:02:01 +0000 |
parents | 6864acb21714 |
children |
comparison
equal
deleted
inserted
replaced
2:6864acb21714 | 3:cc768b0f41cf |
---|---|
1 options(show.error.messages = FALSE, | 1 options( |
2 error = function() { | 2 show.error.messages = FALSE, |
3 cat(geterrmessage(), file = stderr()) | 3 error = function() { |
4 q("no", 1, FALSE) | 4 cat(geterrmessage(), file = stderr()) |
5 } | 5 q("no", 1, FALSE) |
6 } | |
6 ) | 7 ) |
7 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | 8 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
8 warnings() | 9 warnings() |
9 | 10 |
10 library(optparse) | 11 library(optparse) |
11 library(scran) | 12 library(scran) |
12 library(dynamicTreeCut) | 13 library(dynamicTreeCut) |
13 | 14 |
14 # Arguments | 15 # Arguments |
15 option_list <- list( | 16 option_list <- list( |
16 make_option( | 17 make_option( |
17 c("-d", "--data"), | 18 c("-d", "--data"), |
18 default = NA, | 19 default = NA, |
19 type = "character", | 20 type = "character", |
20 help = "Input file that contains count values to transform" | 21 help = "Input file that contains count values to transform" |
21 ), | 22 ), |
22 make_option( | 23 make_option( |
23 "--cluster", | 24 "--cluster", |
24 default = FALSE, | 25 default = FALSE, |
25 action = "store_true", | 26 action = "store_true", |
26 type = "logical", | 27 type = "logical", |
27 help = "Whether to calculate the size factor per cluster or on all cell" | 28 help = "Whether to calculate the size factor per cluster or on all cell" |
28 ), | 29 ), |
29 make_option( | 30 make_option( |
30 c("-m", "--method"), | 31 c("-m", "--method"), |
31 default = "hclust", | 32 default = "hclust", |
32 type = "character", | 33 type = "character", |
33 help = "The clustering method to use for grouping cells into cluster : hclust or igraph [default : '%default' ]" | 34 help = "The clustering method to use for grouping cells into cluster : hclust or igraph [default : '%default' ]" |
34 ), | 35 ), |
35 make_option( | 36 make_option( |
36 "--size", | 37 "--size", |
37 default = 100, | 38 default = 100, |
38 type = "integer", | 39 type = "integer", |
39 help = "Minimal number of cells in each cluster : hclust or igraph [default : '%default' ]" | 40 help = "Minimal number of cells in each cluster : hclust or igraph [default : '%default' ]" |
40 ), | 41 ), |
41 make_option( | 42 make_option( |
42 c("-o", "--out"), | 43 c("-o", "--out"), |
43 default = "res.tab", | 44 default = "res.tab", |
44 type = "character", | 45 type = "character", |
45 help = "Output name [default : '%default' ]" | 46 help = "Output name [default : '%default' ]" |
46 ) | 47 ) |
47 ) | 48 ) |
48 | 49 |
49 opt <- parse_args(OptionParser(option_list = option_list), | 50 opt <- parse_args(OptionParser(option_list = option_list), |
50 args = commandArgs(trailingOnly = TRUE)) | 51 args = commandArgs(trailingOnly = TRUE) |
52 ) | |
51 | 53 |
52 | 54 |
53 data <- read.table( | 55 data <- read.table( |
54 opt$data, | 56 opt$data, |
55 check.names = FALSE, | 57 check.names = FALSE, |
56 header = TRUE, | 58 header = TRUE, |
57 row.names = 1, | 59 row.names = 1, |
58 sep = "\t" | 60 sep = "\t" |
59 ) | 61 ) |
60 | 62 |
61 ## Import data as a SingleCellExperiment object | 63 ## Import data as a SingleCellExperiment object |
62 sce <- SingleCellExperiment(list(counts = as.matrix(data))) | 64 sce <- SingleCellExperiment(list(counts = as.matrix(data))) |
63 | 65 |
64 if (opt$cluster) { | 66 if (opt$cluster) { |
65 clusters <- quickCluster(sce, min.size = opt$size, method = opt$method) | 67 clusters <- quickCluster(sce, min.size = opt$size, method = opt$method) |
66 | 68 |
67 ## Compute sum factors | 69 ## Compute sum factors |
68 sce <- computeSumFactors(sce, cluster = clusters) | 70 sce <- computeSumFactors(sce, cluster = clusters) |
69 } else { | 71 } else { |
70 | 72 ## Compute sum factors |
71 ## Compute sum factors | 73 sce <- computeSumFactors(sce) |
72 sce <- computeSumFactors(sce) | |
73 } | 74 } |
74 | 75 |
75 sce <- logNormCounts(sce) | 76 sce <- logNormCounts(sce) |
76 | 77 |
77 logcounts <- data.frame(genes = rownames(sce), round(logcounts(sce), digits = 5), check.names = FALSE) | 78 logcounts <- data.frame(genes = rownames(sce), round(logcounts(sce), digits = 5), check.names = FALSE) |
78 | 79 |
79 | 80 |
80 write.table( | 81 write.table( |
81 logcounts, | 82 logcounts, |
82 opt$out, | 83 opt$out, |
83 col.names = TRUE, | 84 col.names = TRUE, |
84 row.names = FALSE, | 85 row.names = FALSE, |
85 quote = FALSE, | 86 quote = FALSE, |
86 sep = "\t" | 87 sep = "\t" |
87 ) | 88 ) |