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