-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.nf
153 lines (116 loc) · 4.19 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
#!/usr/bin/env nextflow
// Define common input files
params.transcriptome = "${baseDir}/data/transcriptome.fa"
params.reads = "${baseDir}/data/reads/*.fastq"
// Define email to send results
params.email = "[email protected]"
// Create channels for input files
transcriptome_file = file(params.transcriptome)
Channel
.fromFilePairs( params.reads, size: -1 )
.ifEmpty { error "Cannot find any reads matching: ${params.reads}" }
.into { read_filesA; read_filesB }
// Define which component(s) from the readMapping module we want to use
params.readMappingComponents = "kallisto,salmon,sailfish"
readMappingComponents = params.readMappingComponents.tokenize(",")
// Define a function for parsing component commandline options
def cmdLineArgParse(argObj) {
def cmdLineArg = ''
argObj.each {
if (it.value[0] == true && it.value[1] == true ) {
cmdLineArg = cmdLineArg + " "+ it.value[2]
}
else if (it.value[0] == true ) {
cmdLineArg = cmdLineArg + " "+ it.value[2] + "=" + it.value[1]
}
}
return cmdLineArg
}
// Define multiqc config dir
def multiqc = file(params.multiqc)
process fastqc {
container = "genomicpariscentre/fastqc"
tag { "FASTQC on ${sampleID}" }
input:
set val(sampleID), file(reads) from read_filesB
output:
file("fastqc_${sampleID}_logs") into fastqc_multiQC_ch
script:
"""
mkdir fastqc_${sampleID}_logs
fastqc -o fastqc_${sampleID}_logs -f fastq -q ${reads}
"""
}
process index {
container = { params.modules.readMapping."${component}".container }
tag { "Indexing ${transcriptome_file.getName()} with ${component}" }
input:
val(component) from readMappingComponents
file transcriptome_file
output:
set val("${component}"), file("${component}_index") into indexes
script:
argObj = params.modules.readMapping."${component}".index.commandlineOptions
cmdLineOptions = cmdLineArgParse(argObj)
template "$baseDir/modules/readMapping/components/${component}/index_${component}.sh"
}
indexes
.combine(read_filesA)
.set { read_files_and_index }
process quantification {
container = { params.modules.readMapping."${component}".container }
tag { "Quantifying ${sampleID} with ${component}" }
input:
set val(component), file('index'), val(sampleID), file(reads) from read_files_and_index
output:
set val("${component}"), val("${sampleID}"), file("${sampleID}") into quant
file("${component}_${sampleID}_logs") into quantification_multiQC_ch
script:
argObj = params.modules.readMapping."${component}".quantification.commandlineOptions
cmdLineOptions = cmdLineArgParse(argObj)
template "$baseDir/modules/readMapping/components/${component}/quantification_${component}.sh"
}
process results {
container = { params.modules.readMapping."${component}".container }
tag { "Parsing sample ${sampleID} results from ${component}" }
input:
set val(component), val(sampleID), file(quant_dir) from quant
output:
set val("${component}"), val("${sampleID}"), file("${component}_${sampleID}.quant") into results
script:
template "$baseDir/modules/readMapping/components/${component}/results_${component}.sh"
}
quantification_multiQC_ch
.mix(fastqc_multiQC_ch)
.collect()
.set {multiQC_ch}
process multiQC {
publishDir = "$baseDir/results"
container = "quay.io/biocontainers/multiqc:1.0--py35_4"
input:
file (multiqcDir) from multiqc
file('*') from multiQC_ch
output:
file ("multiqc_report.html") into multiQCreport
file ("multiqc_data") into multiQCdata
script:
"""
cp ${multiqc}/* .
multiqc .
"""
}
workflow.onComplete {
def subject = 'NF Modules Demo'
def recipient = "${params.email}"
def qc_report = "${baseDir}/results/multiqc_report.html"
['mail', '-a', qc_report, '-s', subject, recipient ].execute() << """
Pipeline execution summary
---------------------------
Completed at: ${workflow.complete}
Duration : ${workflow.duration}
Success : ${workflow.success}
workDir : ${workflow.workDir}
exit status : ${workflow.exitStatus}
Error report: ${workflow.errorReport ?: '-'}
"""
}