This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
329 lines (234 loc) · 13.3 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#! /usr/bin/env nextflow
nextflow.enable.dsl=2
//------------------------------------------------------------------------
// Intro message
//------------------------------------------------------------------------
Date date = new Date()
String datePart = date.format("yyyy-dd-MM -- ")
String timePart = date.format("HH:mm:ss")
def start_date = datePart + timePart
println ""
println "\u001B[33m========================================================================================================================="
println "Pipeline: sc_preprocess"
println "GitHub: https://github.com/ATpoint/sc_preprocess"
println "Documentation: https://github.com/ATpoint/sc_preprocess/README.md"
println "Author: Alexander Toenges (@ATpoint)"
println "Runname: $workflow.runName"
println "Profile: $workflow.profile"
println "Start: $start_date"
println "=========================================================================================================================\u001B[0m"
//------------------------------------------------------------------------
// Validate input params via schema.nf
//------------------------------------------------------------------------
evaluate(new File("${baseDir}/functions/validate_schema_params.nf"))
//------------------------------------------------------------------------
// Load the modules and pass params
//------------------------------------------------------------------------
include { ParseExonIntronTx } from './modules/parse_exon_intron_tx.nf' addParams(gene_id: params.gene_id,
gene_name: params.gene_name,
gene_type: params.gene_type,
read_length: params.read_length,
chrM: params.chrM,
rrna: params.rrna,
outdir: params.idx_outdir)
//------------------------------------------------------------------------
include { AlevinIndex } from './modules/alevin_index' addParams(outdir: params.idx_outdir, additional: params.idx_args)
//------------------------------------------------------------------------
include {ValidateSamplesheet } from './modules/validate_samplesheet.nf'
//------------------------------------------------------------------------
include { Quant } from './modules/alevin_quant' addParams(outdir: params.quant_outdir,
r1_type: params.r1_type,
r2_type: params.r2_type,
args: params.quant_args)
//------------------------------------------------------------------------
include { AlevinIndexFB } from './modules/alevin_index' addParams(outdir: params.idx_outdir)
//------------------------------------------------------------------------
include { QuantFB } from './modules/alevin_quant' addParams(outdir: params.quant_outdir,
r1_type: params.r1_type,
r2_type: params.r2_type_fb,
args: params.quant_args_fb)
//------------------------------------------------------------------------
include { Mtx } from './modules/write_mtx' addParams(outdir: params.mtx_outdir)
//------------------------------------------------------------------------
include { AlevinQC } from './modules/alevin_qc' addParams(outdir: params.qc_outdir)
//------------------------------------------------------------------------
include { WriteNcells } from './modules/summary_cells' addParams(outdir: params.qc_outdir)
//------------------------------------------------------------------------
include{ CommandLines } from './modules/commandline' addParams(outdir: params.pipe_dir)
//------------------------------------------------------------------------
workflow INDEXING {
take:
genome
gtf
main:
ParseExonIntronTx (genome, gtf)
AlevinIndex(genome, ParseExonIntronTx.out.txtome, params.idx_name)
emit:
idx = AlevinIndex.out.idx
tgmap = ParseExonIntronTx.out.tgmap
rrnagenes = ParseExonIntronTx.out.rrnagenes
mtgenes = ParseExonIntronTx.out.mtgenes
features = ParseExonIntronTx.out.features
gene2type = ParseExonIntronTx.out.gene2type
versions = ParseExonIntronTx.out.versions.concat(AlevinIndex.out.versions)
}
workflow VALIDATE {
take:
samplesheet_unvalidated
main:
ValidateSamplesheet(samplesheet_unvalidated)
tuple_fastq = ValidateSamplesheet.out.samplesheet
.splitCsv(header:true)
.map {
// Samplesheet allows Nextflow variables to be used, replace by absolute path
r1 = it['r1']
.replaceAll('\\$baseDir|\\$\\{baseDir\\}', new String("${baseDir}/"))
.replaceAll('\\$launchDir|\\$\\{launchDir\\}', new String("${launchDir}/"))
.replaceAll('\\$projectDir|\\$\\{projectDir\\}', new String("${projectDir}/"))
rx = it['r2']
.replaceAll('\\$baseDir|\\$\\{baseDir\\}', new String("${baseDir}/"))
.replaceAll('\\$launchDir|\\$\\{launchDir\\}', new String("${launchDir}/"))
.replaceAll('\\$projectDir|\\$\\{projectDir\\}', new String("${projectDir}/"))
r2 = rx.toString()=='' ? '.' : rx
// Make sure fastq file paths exist
is_error = false
r1_file = file(r1).exists()
if(!r1_file){
ErrorMessenger("$r1 does not exist")
is_error = true
}
if(r2!=".") {
r2_file = file(r2).exists()
if(!r1_file){
ErrorMessenger("$r2 does not exist")
is_error = true
}
}
// Libtype and whether the fastq file is a gne expression or feature barcode readout
libtype = it['libtype']
is_fb = it['is_fb']
// meta map inspired by nf-core
meta = [id:it['sample'], libtype: libtype, is_fb: is_fb]
reads = [r1: r1, r2: r2]
if(!is_error){
return tuple(meta, reads)
} else {
return null
}
}
.groupTuple(by:0)
emit:
tuple_fastq = tuple_fastq
versions = ValidateSamplesheet.out.versions
}
workflow {
//--------------------------------------------------------------------
// Indexing of transcriptome
//--------------------------------------------------------------------
if(params.idx==''){
INDEXING(params.genome, params.gtf)
indexing_versions = INDEXING.out.versions
indexing_idx = INDEXING.out.idx
indexing_tgmap = INDEXING.out.tgmap
indexing_rrnagenes = INDEXING.out.rrnagenes
indexing_mtgenes = INDEXING.out.mtgenes
indexing_features = INDEXING.out.features
indexing_gene2type = INDEXING.out.gene2type
} else {
indexing_versions = Channel.empty()
indexing_idx = params.idx
indexing_tgmap = params.tgmap
indexing_rrnagenes = params.rrnagenes
indexing_mtgenes = params.mtgenes
indexing_features = params.features
indexing_gene2type = params.gene2type
}
if(!params.only_idx){
//--------------------------------------------------------------------
// Samplesheet validation
//--------------------------------------------------------------------
VALIDATE(params.samplesheet)
validate_versions = VALIDATE.out.versions
ch_geneExpression = VALIDATE.out.tuple_fastq.map{
aa = it[0]
r1 = it[1].r1.toList().flatten()
r2 = it[1].r2.toList().flatten()
if(aa.is_fb=='false') return [aa, r1, r2] else return null
}
ch_featureBarcode = VALIDATE.out.tuple_fastq.map{
aa = it[0]
r1 = it[1].r1.toList().flatten()
r2 = it[1].r2.toList().flatten()
if(aa.is_fb=='true') return [aa, r1, r2] else return null
}
//--------------------------------------------------------------------
// Quantification of gene expression reads
//--------------------------------------------------------------------
Quant(ch_geneExpression, indexing_idx.collect(), indexing_tgmap.collect(), indexing_rrnagenes.collect(), indexing_mtgenes.collect())
quant_versions = Quant.out.versions
//--------------------------------------------------------------------
// Indexing of feature barcodes
//--------------------------------------------------------------------
if(params.features_file != ''){
AlevinIndexFB(params.features_file, "idx_fb")
indexfb_versions = AlevinIndexFB.out.versions
} else {
indexfb_versions = Channel.empty()
}
//--------------------------------------------------------------------
// Quantification of feature barcode reads
//--------------------------------------------------------------------
if(params.features_file != ''){
QuantFB(ch_featureBarcode, AlevinIndexFB.out.idx.collect(), AlevinIndexFB.out.tgmap.collect())
quant_fb_channel = QuantFB.out.quants
quantfb_versions = QuantFB.out.versions
} else {
quant_fb_channel = Channel.empty()
quantfb_versions = Channel.empty()
}
//--------------------------------------------------------------------
// Splitting of quants into spliced and unspliced counts.
// If feature barcodes were present for a given sample then
// retain only barcodes of the FB that made it to the gene expression
// matrix. Perform barcode translation if set in the params.
//--------------------------------------------------------------------
ch_for_mtx = Quant.out.quants.concat(quant_fb_channel)
.map{ [[id: "${it[0].id}"], it[1]] }.groupTuple(by: 0) // retain only .id and the quants channel as part of the tuple
Mtx(ch_for_mtx, indexing_features.collect(), indexing_gene2type.collect(), params.translate_list)
mtx_versions = Mtx.out.versions
//--------------------------------------------------------------------
// AlevinQC reports and cell summary
//--------------------------------------------------------------------
ch_for_aqc = Quant.out.quants.concat(quant_fb_channel).map{
ii = it[0].is_fb=='true' ? [[id: "${it[0].id}_fb"], it[1]] : [[id: "${it[0].id}"], it[1]]
return ii
}
AlevinQC(ch_for_aqc)
alevinqc_versions = AlevinQC.out.versions
WriteNcells(Mtx.out.ncells.collect())
ncells_versions = WriteNcells.out.versions
} else {
validate_versions = Channel.empty()
quant_versions = Channel.empty()
alevinqc_versions = Channel.empty()
indexfb_versions = Channel.empty()
quantfb_versions = Channel.empty()
mtx_versions = Channel.empty()
ncells_versions = Channel.empty()
}
//--------------------------------------------------------------------
// Command lines and software versions
//--------------------------------------------------------------------
x_commands = validate_versions.concat(indexing_versions, quant_versions, alevinqc_versions, indexfb_versions, quantfb_versions,
mtx_versions, ncells_versions)
.map {it [1]}.flatten().collect()
x_versions = validate_versions.concat(indexing_versions.first(),
quant_versions.first(),
alevinqc_versions.first(),
indexfb_versions,
quantfb_versions.first(),
mtx_versions.first(),
ncells_versions)
.map {it [0]}.flatten().collect()
CommandLines(x_commands, x_versions)
}