-
Notifications
You must be signed in to change notification settings - Fork 4
/
seurat-normalise-data.R
executable file
·102 lines (88 loc) · 3.19 KB
/
seurat-normalise-data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env Rscript
# Load optparse we need to check inputs
suppressPackageStartupMessages(require(optparse))
# Load common functions
suppressPackageStartupMessages(require(workflowscriptscommon))
# parse options
option_list = list(
make_option(
c("-i", "--input-object-file"),
action = "store",
default = NA,
type = 'character',
help = "File name in which a serialized R matrix object may be found."
),
make_option(
c("--input-format"),
action = "store",
default = "seurat",
type = 'character',
help = "Either loom, seurat, anndata or singlecellexperiment for the input format to read."
),
make_option(
c("--output-format"),
action = "store",
default = "seurat",
type = 'character',
help = "Either loom, seurat, anndata or singlecellexperiment for the output format."
),
make_option(
c("-n", "--normalization-method"),
action = "store",
default = 'LogNormalize',
type = 'character',
help = "Method for normalization. Default is log-normalization (LogNormalize). Can be 'CLR' or 'RC' additionally."
),
make_option(
c("-s", "--scale-factor"),
action = "store",
default = 10000,
type = 'integer',
help = "Sets the scale factor for cell-level normalization."
),
make_option(
c("-o", "--output-object-file"),
action = "store",
default = NA,
type = 'character',
help = "File name in which to store serialized R object of type 'Seurat'.'"
),
make_option(
c("--margin"),
action = "store",
default = 1,
type = 'integer',
help = "If performing CLR normalization, normalize across features (1) or cells (2)."
),
make_option(
c("--block-size"),
action = "store",
default = NULL,
type = 'integer',
help = "How many cells should be run in each chunk, will try to split evenly across threads"
)
)
opt <- wsc_parse_args(option_list, mandatory = c('input_object_file', 'output_object_file'))
# Check parameter values
if ( ! file.exists(opt$input_object_file)){
stop((paste('File', opt$input_object_file, 'does not exist')))
}
# Now we're hapy with the arguments, load Seurat and do the work
suppressPackageStartupMessages(require(Seurat))
if(opt$input_format == "loom" | opt$output_format == "loom") {
suppressPackageStartupMessages(require(SeuratDisk))
} else if(opt$input_format == "singlecellexperiment" | opt$output_format == "singlecellexperiment") {
suppressPackageStartupMessages(require(scater))
}
# Input from serialized R object
seurat_object <- read_seurat4_object(input_path = opt$input_object_file, format = opt$input_format)
normalised_seurat_object <- NormalizeData(seurat_object,
normalization.method = opt$normalization_method,
scale.factor = opt$scale_factor,
margin = opt$margin,
block.size = opt$block_size,
verbose = FALSE)
# Output to a serialized R object
write_seurat4_object(seurat_object = normalised_seurat_object,
output_path = opt$output_object_file,
format = opt$output_format)