-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.nf
372 lines (316 loc) · 11.2 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/usr/bin/env nextflow
/*
Copyright Institut Curie 2019-2022
This software is a computer program whose purpose is to analyze high-throughput sequencing data.
You can use, modify and/ or redistribute the software under the terms of license (see the LICENSE file for more details).
The software is distributed in the hope that it will be useful, but "AS IS" WITHOUT ANY WARRANTY OF ANY KIND.
Users are therefore encouraged to test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data.
The fact that you are presently reading this means that you have had knowledge of the license and that you accept its terms.
*/
/*
========================================================================================
ANNOTATION MAKER
========================================================================================
Analysis Pipeline DSL2 template.
https://patorjk.com/software/taag/
----------------------------------------------------------------------------------------
*/
nextflow.enable.dsl=2
// Initialize lintedParams and paramsWithUsage
NFTools.welcome(workflow, params)
// Use lintedParams as default params object
paramsWithUsage = NFTools.readParamsFromJsonSettings("${projectDir}/parameters.settings.json")
params.putAll(NFTools.lint(params, paramsWithUsage))
// Run name
customRunName = NFTools.checkRunName(workflow.runName, params.name)
// Custom functions/variables
mqcReport = []
include {checkAlignmentPercent} from './lib/functions'
/*
===================================
SET UP CONFIGURATION VARIABLES
===================================
*/
// Genome-based variables
if (!params.genome){
exit 1, "No genome provided. The --genome option is mandatory"
}
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
exit 1, "The provided genome '${params.genome}' is not available in the genomes file. Currently the available genomes are ${params.genomes.keySet().join(", ")}"
}
// Initialize variable from the genome.conf file
//params.bowtie2Index = NFTools.getGenomeAttribute(params, 'bowtie2')
// Stage config files
outputDocsCh = Channel.fromPath("$projectDir/docs/output.md")
//outputDocsImagesCh = file("$projectDir/docs/images/", checkIfExists: true)
/*
==========================
VALIDATE INPUTS
==========================
*/
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
exit 1, "The provided genome '${params.genome}' is not available in the genomes file. Currently the available genomes are ${params.genomes.keySet().join(", ")}"
}
def defineAligners() {
return [
'bwa',
'bwamem2',
'dragmap',
'star',
'bowtie2',
'hisat2',
'cellranger',
'kallisto',
'salmon',
'none']
}
// Compare each parameter with a list of parameters
static def checkParameterExistence(it, list) {
if (!list.contains(it)) {
println("Unknown parameter: ${it}")
return false
}
return true
}
def checkParameterList(list, realList) {
return list.every{ checkParameterExistence(it, realList) }
}
alignersList = defineAligners()
def aligners = params.indexes || params.indexes == 'none' ? params.indexes == 'all' ? alignersList : params.indexes.split(',').collect{it.trim().toLowerCase()} : []
if (!checkParameterList(aligners, alignersList)) exit 1, 'Unknown Aligner(s), see --help for more information'
// Star version label
params.starLabel = "star" + params.starVersion.replaceAll('\\.','_');
/*
==========================
BUILD CHANNELS
==========================
*/
// Reference Genome
chFasta = Channel.empty()
chFastaURL = Channel.empty()
wasFastaURL = false
if (params.fasta){
chFasta = Channel.fromPath("${params.fasta}").ifEmpty { exit 1, "Reference Genome not found: ${params.fasta}" }
}else if (params.genome){
fasta = params.genome ? params.genomes[ params.genome ].fasta ?: false : false
if (fasta){
if (fasta.startsWith("http") || fasta.startsWith("ftp")){
chFastaURL = Channel.from(fasta)
wasFastaURL = true
}else{
chFasta = Channel.fromPath(fasta).ifEmpty { exit 1, "Reference Genome not found: ${fasta}" }
}
}else{
exit 1, "Fasta file not found for ${params.genome} : ${fasta}"
}
}
// Transcriptome
chTrsFasta = Channel.empty()
chTrsURL = Channel.empty()
wasTrsURL = false
if (params.transcripts){
chTrsFasta = Channel.fromPath("${params.transcripts}").ifEmpty { exit 1, "Reference Genome not found: ${params.transcripts}" }
}else if (params.genome){
transcriptome = params.genome ? params.genomes[ params.genome ].transcripts ?: false : false
if (transcriptome){
if (transcriptome.startsWith("http") || transcriptome.startsWith("ftp")){
wasTrsURL = true
chTrsURL = Channel.from(transcriptome)
}else{
chTrsFasta = Channel.fromPath(transcriptome).ifEmpty { exit 1, "Reference annotation file not found: ${transcriptome}" }
}
}else{
log.warn("No transcripts file detected for ${params.genome}")
}
}
// GTF
gff=false
gtf=false
chGtf = Channel.empty()
chGff = Channel.empty()
chGtfURL = Channel.empty()
chGffURL = Channel.empty()
wasGtfURL = false
wasGffURL = false
if (params.gtf){
chGtf = Channel.fromPath(params.gtf).ifEmpty { exit 1, "GTF annotation file not found: ${params.gtf}" }
}else if (params.gff){
chGff = Channel.fromPath(params.gff).ifEmpty { exit 1, "GFF annotation file not found: ${params.gtf}" }
}else if (params.genome){
gtf = params.genome ? params.genomes[ params.genome ].gtf ?: false : false
gff = params.genome ? params.genomes[ params.genome ].gff ?: false : false
if ( gtf && gff ){
log.info "Both GTF and GFF have been provided: Using GTF."
}else if ( gtf ){
if (gtf.startsWith("http") || gtf.startsWith("ftp")){
wasGtfURL = true
chGtfURL = Channel.from(gtf)
}else{
chGtf = Channel.fromPath(gtf).ifEmpty { exit 1, "GTF annotation file not found: ${gtf}" }
}
}else if ( gff ){
if ( gff.startsWith("http") || gff.startsWith("ftp")){
wasGffURL = true
chGffURL = Channel.from(gff)
}else{
chGff = Channel.fromPath(gff).ifEmpty { exit 1, "GFF annotation file not found: ${gff}" }
}
}else{
log.warn("No GTF/GFF information detected for ${params.genome}")
}
}
if ( params.build ){
build = params.build
}else if (params.genome){
build = params.genome
}else{
fafile = file(params.fasta)
build = fafile.baseName - ~/(\.fa)?(\.fasta)?(\.gz)?$/
}
chBuild = Channel.of(build)
/*
===========================
SUMMARY
===========================
*/
summary = [
'Pipeline Release': workflow.revision ?: null,
'Build': build,
'Fasta' : params.fasta ?: params.genome ? fasta : "",
'Transcripts' : params.transcripts ?: params.genome ? transcriptome : null,
'Gtf' : params.gtf ?: params.genome ? gtf : null,
'Gff' : params.gff ?: params.genome ? gff : null,
'Indexes' : aligners,
'STAR version' : "star" in aligners ? params.starLabel : null,
'Max Resources': "${params.maxMemory} memory, ${params.maxCpus} cpus, ${params.maxTime} time per job",
'Container': workflow.containerEngine && workflow.container ? "${workflow.containerEngine} - ${workflow.container}" : null,
'Profile' : workflow.profile,
'OutDir' : params.outDir,
'WorkDir': workflow.workDir,
'CommandLine': workflow.commandLine
].findAll{ it.value != null }
workflowSummaryCh = NFTools.summarize(summary, workflow, params)
/*
==================================
INCLUDE
==================================
*/
// Workflows
include { fastaProcessingFlow } from './nf-modules/local/subworkflow/fastaProcessing'
include { gtfProcessingFlow } from './nf-modules/local/subworkflow/gtfProcessing'
include { hisat2IndexFlow } from './nf-modules/local/subworkflow/hisat2Index'
include { cellrangerIndexFlow } from './nf-modules/local/subworkflow/cellrangerIndex'
include { kallistoIndexFlow } from './nf-modules/local/subworkflow/kallistoIndex'
// Processes
include { getSoftwareVersions } from './nf-modules/common/process/utils/getSoftwareVersions'
include { getDataFromURL as getTranscriptome } from './nf-modules/common/process/custom/getDataFromURL'
include { getDataFromURL as getAnnotation } from './nf-modules/common/process/custom/getDataFromURL'
include { getFastaFromURL } from './nf-modules/common/process/custom/getFastaFromURL'
include { gffreads } from './nf-modules/common/process/gffreads/gffreads'
include { bowtie2Index } from './nf-modules/common/process/bowtie2/bowtie2Index'
include { starIndex } from './nf-modules/common/process/star/starIndex'
include { bwaIndex } from './nf-modules/common/process/bwa/bwaIndex'
include { bwamem2Index } from './nf-modules/common/process/bwamem2/bwamem2Index'
include { dragmapIndex } from './nf-modules/common/process/dragmap/dragmapIndex'
include { salmonIndex } from './nf-modules/common/process/salmon/salmonIndex'
/*
=====================================
WORKFLOW
=====================================
*/
workflow {
versionsCh = Channel.empty()
main:
//************************************
// Download
getFastaFromURL(
chFastaURL,
chBuild
)
chFasta = wasFastaURL ? getFastaFromURL.out.fasta : chFasta
getTranscriptome(
chTrsURL,
Channel.of('fa')
)
chTrsFasta = wasTrsURL ? getTranscriptome.out.output : chTrsFasta
getAnnotation(
chGffURL.concat(chGtfURL),
Channel.of('gtf','gff')
)
if (wasGtfURL){
chGtf = getAnnotation.out.output
}else if (wasGffURL){
chGff = getAnnotation.out.output
}
if ((params.gff || gff) && (!params.gtf && !gtf)){
gffreads(
getAnnotation.out.output
)
chGtf = gffreads.out.gtf
}
//**********************************
// Fasta processing
fastaProcessingFlow(
chFasta,
chBuild
)
versionsCh = versionsCh.mix(fastaProcessingFlow.out.versions)
//**********************************
// Generate genome indexes
bwaIndex(
chFasta
)
versionsCh = versionsCh.mix(bwaIndex.out.versions)
bwamem2Index(
chFasta
)
versionsCh = versionsCh.mix(bwamem2Index.out.versions)
dragmapIndex(
chFasta
)
versionsCh = versionsCh.mix(dragmapIndex.out.versions)
starIndex(
chFasta,
fastaProcessingFlow.out.chromSizes,
Channel.value([])
)
versionsCh = versionsCh.mix(starIndex.out.versions)
bowtie2Index(
chFasta
)
versionsCh = versionsCh.mix(bowtie2Index.out.versions)
hisat2IndexFlow(
chFasta,
chGtf
)
versionsCh = versionsCh.mix(hisat2IndexFlow.out.versions)
cellrangerIndexFlow(
chFasta,
chGtf,
chBuild
)
versionsCh = versionsCh.mix(cellrangerIndexFlow.out.versions)
kallistoIndexFlow(
chTrsFasta
)
versionsCh = versionsCh.mix(kallistoIndexFlow.out.versions)
salmonIndex(
chFasta,
chTrsFasta
)
versionsCh = versionsCh.mix(salmonIndex.out.versions)
//**********************************
// Process GTF file
gtfProcessingFlow(
chGtf
)
versionsCh = versionsCh.mix(gtfProcessingFlow.out.versions)
//**********************************
// subroutines
getSoftwareVersions(
versionsCh.unique().collectFile()
)
}
workflow.onComplete {
NFTools.makeReports(workflow, params, summary, customRunName, mqcReport)
}