-
Notifications
You must be signed in to change notification settings - Fork 5
/
seurat-map-query.R
executable file
·193 lines (163 loc) · 6.39 KB
/
seurat-map-query.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env Rscript
# This script has been automatically generated through
#
# YAML2RScript.py -i ../r-seurat-scripts/cli-generated/manually_crafted_YAML/seurat-map-query.yaml -o ../r-seurat-scripts/seurat-map-query.R
#
# to change this file edit the input YAML and re-run the above command
suppressPackageStartupMessages(require(workflowscriptscommon))
suppressPackageStartupMessages(require(Seurat))
suppressPackageStartupMessages(require(optparse))
suppressPackageStartupMessages(require(scater))
suppressPackageStartupMessages(require(SeuratDisk))
option_list <- list(
make_option(
c("-q", "--query-object-file"),
action = "store",
metavar = "Input file",
type = "character",
help = "Query file with Seurat object in either RDS-Seurat, Loom or SCE"
),
make_option(
c("--query-format"),
action = "store",
default = "seurat",
metavar = "Input format",
type = "character",
help = "Either loom, seurat, anndata or singlecellexperiment for the input format to read."
),
make_option(
c("-a", "--anchors-object-file"),
action = "store",
metavar = "Seurat transfer anchors file",
type = "character",
help = "Input file with Seurat object with anchors in either RDS-Seurat, Loom or SCE"
),
make_option(
c("--anchors-format"),
action = "store",
default = "seurat",
metavar = "Anchors format",
type = "character",
help = "Either loom, seurat, anndata or singlecellexperiment for the anchors format to read."
),
make_option(
c("-r", "--reference-object-file"),
action = "store",
default = NULL,
metavar = "Seurat reference object file",
type = "character",
help = "Input file with Seurat object with reference (and UMAP) in either RDS-Seurat, Loom or SCE"
),
make_option(
c("--reference-format"),
action = "store",
default = "seurat",
metavar = "Anchors format",
type = "character",
help = "Either loom, seurat, anndata or singlecellexperiment for the reference format to read."
),
make_option(
c("--refdata-field-or-assay"),
action = "store",
type = "character",
help = "The name of the metadata field or assay from the reference object provided. This requires the reference parameter to be specified."
),
make_option(
c("--new-reduction-name"),
action = "store",
default = NULL,
type = "character",
help = "Name for new integrated dimensional reduction."
),
make_option(
c("--reference-reduction"),
action = "store",
default = NULL,
type = "character",
help = "Name of reduction to use from the reference for neighbor finding"
),
make_option(
c("--reduction-model"),
action = "store",
default = NULL,
type = "character",
help = "DimReduc object name that contains the umap model"
),
make_option(
c("--transferdata-args"),
action = "store",
default = NULL,
type = "character",
help = "A named list of additional arguments to TransferData, written in R syntax .ie list( argument = 'value' )"
),
make_option(
c("--integrated-embedding-args"),
action = "store",
default = NULL,
type = "character",
help = "A named list of additional arguments to IntegrateEmbeddings, written in R syntax .ie list( argument = 'value' )"
),
make_option(
c("--project-umap-args"),
action = "store",
default = NULL,
type = "character",
help = "A named list of additional arguments to ProjectUMAP, written in R syntax .ie list( argument = 'value' )"
),
make_option(
c("-o", "--output-object-file"),
action = "store",
type = "character",
help = "FILE IN"
),
make_option(
c("--output-format"),
action = "store",
default = "seurat",
type = "character",
help = "Either loom, seurat, anndata or singlecellexperiment for the anchors format to read.'"
)
)
opt <- wsc_parse_args(option_list,
mandatory = c("query_object_file", "anchors_object_file", "refdata_field_or_assay", "output_object_file"))
if (!file.exists(opt$query_object_file)) {
stop((paste("File", opt$query_object_file, "does not exist")))
}
if (!file.exists(opt$anchors_object_file)) {
stop((paste("File", opt$anchors_object_file, "does not exist")))
}
if (!file.exists(opt$reference_object_file)) {
stop((paste("File", opt$reference_object_file, "does not exist")))
}
if (!is.null(opt$refdata_field_or_assay)) {
opt$refdata_field_or_assay <- eval(parse(text = opt$refdata_field_or_assay))
}
if (!is.null(opt$transferdata_args)) {
opt$transferdata_args <- eval(parse(text = opt$transferdata_args))
}
if (!is.null(opt$integrated_embedding_args)) {
opt$integrated_embedding_args <- eval(parse(text = opt$integrated_embedding_args))
}
if (!is.null(opt$project_umap_args)) {
opt$project_umap_args <- eval(parse(text = opt$project_umap_args))
}
load_seurat4_packages_for_format(formats = c(opt$query_format, opt$anchors_format, opt$reference_format))
seurat_object <- read_seurat4_object(input_path = opt$query_object_file,
format = opt$query_format)
anchors_object <- read_seurat4_object(input_path = opt$anchors_object_file,
format = opt$anchors_format)
reference_object <- read_seurat4_object(input_path = opt$reference_object_file,
format = opt$reference_format)
mapped_object <- MapQuery(query = seurat_object,
anchorset = anchors_object,
reference = reference_object,
refdata = opt$refdata_field_or_assay,
new.reduction.name = opt$new_reduction_name,
reference.reduction = opt$reference_reduction,
reduction.model = opt$reduction_model,
transferdata.args = opt$transferdata_args,
integrateembeddings.args = opt$integrated_embedding_args,
projectumap.args = opt$project_umap_args)
write_seurat4_object(seurat_object = mapped_object,
output_path = opt$output_object_file,
format = opt$output_format)