annotate signac-createAssayObject.R @ 0:6e0b320d8b6a draft default tip

"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
author gaelcge
date Tue, 02 Aug 2022 19:11:27 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
1 #!/usr/bin/env Rscript
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
2
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
3 # Load optparse we need to check inputs
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
4
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
5 suppressPackageStartupMessages(require(optparse))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
6
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
7 # Load common functions
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
8
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
9 suppressPackageStartupMessages(require(workflowscriptscommon))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
10
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
11 # parse options
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
12 option_list = list(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
13 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
14 c("--signac-object"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
15 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
16 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
17 type = 'character',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
18 help = "A Seurat object."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
19 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
20 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
21 c("--counts"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
22 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
23 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
24 type = 'character',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
25 help = "Counts Matrix."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
26 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
27 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
28 c("--name"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
29 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
30 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
31 type = 'character',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
32 help = "Assay Name."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
33 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
34 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
35 c("--min-cells"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
36 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
37 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
38 type = 'numeric',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
39 help = "Min Cells."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
40 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
41 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
42 c("--min-features"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
43 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
44 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
45 type = 'numeric',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
46 help = "Min Features."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
47 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
48 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
49 c("--method"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
50 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
51 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
52 type = 'character',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
53 help = "Method for normalization."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
54 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
55 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
56 c("--scale-factor"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
57 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
58 default = 10000,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
59 type = 'numeric',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
60 help = "Sets the scale factor for cell-level normalization."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
61 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
62 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
63 c("--margin"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
64 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
65 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
66 type = 'character',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
67 help = "If performing CLR normalization, normalize across features (1) or cells (2)."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
68 ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
69 make_option(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
70 c("--output-object-file"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
71 action = "store",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
72 default = NA,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
73 type = 'numeric',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
74 help = "File name in which to store serialized R matrix object."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
75 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
76 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
77 opt <- wsc_parse_args(option_list)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
78
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
79 suppressPackageStartupMessages(require(Seurat))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
80 suppressPackageStartupMessages(require(Signac))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
81
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
82 set.seed(1234)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
83
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
84 if (! file.exists(opt$signac_object)){
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
85 stop((paste('File', opt$signac_object, 'does not exist')))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
86 }
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
87 if (! file.exists(opt$counts)){
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
88 stop((paste('File', opt$counts, 'does not exist')))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
89 }
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
90
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
91 signac_object <- readRDS(file = opt$signac_object)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
92 counts <- readRDS(opt$counts)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
93
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
94 signac_object[[opt$name]] <- CreateAssayObject(counts = counts)#, min.cells = opt$min_cells, min.features = opt$min_features)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
95
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
96 signac_object <- NormalizeData(object = signac_object, normalization.method = opt$method, scale.factor = opt$scale_factor, margin = opt$margin, assay = opt$name)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
97
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
98 saveRDS(signac_object, file = opt$output_object_file)