-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
executable file
·265 lines (205 loc) · 7.74 KB
/
main.nf
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env nextflow
// produce sce object for query dataset
QUERY_DIR = Channel.fromPath(params.query_10x_dir)
process create_query_sce {
conda "${baseDir}/envs/dropletutils.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 2
memory { 16.GB * task.attempt }
input:
file(query_dir) from QUERY_DIR
output:
file("query_sce.rds") into QUERY_SCE
"""
dropletutils-read-10x-counts.R\
--samples ${query_dir}\
--col-names ${params.col_names}\
--output-object-file query_sce.rds
"""
}
// produce sce object for reference dataset
REF_DIR = Channel.fromPath(params.reference_10x_dir)
REF_METADATA = Channel.fromPath(params.reference_metadata)
process create_reference_sce {
conda "${baseDir}/envs/dropletutils.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 2
memory { 16.GB * task.attempt }
input:
file(ref_metadata) from REF_METADATA
file(ref_dir) from REF_DIR
output:
file("reference_sce.rds") into REF_SCE
"""
dropletutils-read-10x-counts.R\
--samples ${ref_dir}\
--col-names ${params.col_names}\
--metadata-files ${ref_metadata}\
--cell-id-column ${params.cell_id_col}\
--metadata-columns ${params.cell_id_col},${params.cluster_col}\
--output-object-file reference_sce.rds
"""
}
// pre-process query dataset
process preprocess_query_sce {
conda "${baseDir}/envs/scmap.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
input:
file(query_sce) from QUERY_SCE
output:
file("query_sce_processed.rds") into QUERY_SCE_PROC
"""
scmap-preprocess-sce.R --input-object ${query_sce} --output-sce-object query_sce_processed.rds
"""
}
// pre-process reference dataset
process preprocess_ref_sce {
conda "${baseDir}/envs/scmap.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
input:
file(ref_sce) from REF_SCE
output:
file("ref_sce_processed.rds") into REF_SCE_PROC
"""
scmap-preprocess-sce.R --input-object ${ref_sce} --output-sce-object ref_sce_processed.rds
"""
}
// select relevant features for reference dataset
process select_ref_features {
publishDir "${baseDir}/data/output", mode: 'copy'
conda "${baseDir}/envs/scmap.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
input:
file(ref_sce) from REF_SCE_PROC
output:
file("ref_features.rds") into REF_FEATURES
"""
scmap-select-features.R\
--input-object-file ${ref_sce}\
--output-plot-file ${params.plot_file}\
--output-object-file ref_features.rds
"""
}
projection_method = params.projection_method
REF_CLUSTER = Channel.create()
REF_CELL = Channel.create()
// make a map to re-direct input into correct channel
channels = ["cluster":0, "cell":1]
REF_FEATURES.choice(REF_CLUSTER, REF_CELL){channels[projection_method]}
// obtain index for cluster-level projections
process index_cluster {
conda "${baseDir}/envs/scmap.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
input:
file(ref_features_sce) from REF_CLUSTER
output:
file("ref_index_cluster.rds") into REF_CLUSTER_INDEX
"""
scmap-index-cluster.R\
--input-object-file ${ref_features_sce}\
--cluster-col ${params.cluster_col}\
--output-object-file ref_index_cluster.rds
"""
}
// obtain index for cell-level projections
process index_cell {
conda "${baseDir}/envs/scmap.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
input:
file(ref_features_sce) from REF_CELL
output:
file("ref_index_cell.rds") into REF_CELL_INDEX
"""
scmap-index-cell.R\
--input-object-file ${ref_features_sce}\
--output-object-file ref_index_cell.rds
"""
}
// coerce queue channel into value channel for re-using
QUERY_SCE_PROC = QUERY_SCE_PROC.first()
// obtain cluster-level projections
process get_cluster_projections{
conda "${baseDir}/envs/scmap.yaml"
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
publishDir "${params.output_dir_cluster}", mode: 'copy'
input:
file(ref_cluster_index) from REF_CLUSTER_INDEX
file(query_sce) from QUERY_SCE_PROC
output:
file("cluster_projection_result_sce.rds") into PROJECTED_CLUSTERS_SCE
file("cluster_projection_result_file.txt") into PROJECTED_CLUSTERS_TXT
"""
scmap-scmap-cluster.R\
--index-object-file ${ref_cluster_index}\
--projection-object-file ${query_sce}\
--threshold ${params.threshold}\
--output-text-file cluster_projection_result_file.txt\
--output-object-file cluster_projection_result_sce.rds
"""
}
// obtain cell-level projections
process get_cell_projections {
conda "${baseDir}/envs/scmap.yaml"
publishDir "${params.output_dir_cell}", mode: 'copy'
errorStrategy { task.exitStatus == 130 || task.exitStatus == 137 ? 'retry' : 'finish' }
maxRetries 10
memory { 16.GB * task.attempt }
input:
file(ref_cell_index) from REF_CELL_INDEX
file(query_sce) from QUERY_SCE_PROC
output:
file("cell_projection_result_file.txt") into PROJECTED_CELLS_TXT
file("closest_cells.txt") into CLOSEST_CELLS
file("closest_cell_similarity.txt") into CLOSEST_CELLS_SIMILARITY
file("cell_projection_result_object.rds") into PROJECTED_CELLS_SCE
"""
scmap-scmap-cell.R\
--index-object-file ${ref_cell_index}\
--projection-object-file ${query_sce}\
--cluster-col ${params.cluster_col}\
--output-clusters-text-file cell_projection_result_file.txt\
--closest-cells-text-file closest_cells.txt\
--closest-cells-similarities-text-file closest_cell_similarity.txt\
--output-object-file cell_projection_result_object.rds
"""
}
process get_final_output_cluster{
conda "${baseDir}/envs/scmap.yaml"
publishDir "${params.results_dir}", mode: 'copy'
input:
file(predictions) from PROJECTED_CLUSTERS_TXT
output:
file("scmap-cluster_output.txt") into FINAL_TABLE_CLUSTERS
"""
scmap_get_std_output.R\
--predictions-file ${predictions}\
--tool "scmap-cluster"\
--output-table scmap-cluster_output.txt
"""
}
process get_final_output_cell{
conda "${baseDir}/envs/scmap.yaml"
publishDir "${params.results_dir}", mode: 'copy'
input:
file(predictions) from PROJECTED_CELLS_TXT
output:
file("scmap-cell_output.txt") into FINAL_TABLE_CELLS
"""
scmap_get_std_output.R\
--predictions-file ${predictions}\
--tool "scmap-cell"\
--output-table scmap-cell_output.txt
"""
}