annotate scran-normalize.R @ 2:6864acb21714 draft

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