-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
184 lines (151 loc) · 5.46 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
#!/usr/bin/env nextflow
def helpMessage() {
log.info nfcoreHeader()
log.info"""
Usage:
The typical command for running the pipeline is as follows:
Mandatory arguments:
--reads Path to input data (must be surrounded with quotes).
--csv CSV file with first column read file and second column protocol
--mirtrace_species 3 letter code for the species compatible with miRBase naming. 'hsa' for human.
--protocol Library preparation protocol. Default: "illumina". Can be set as "illumina", "nextflex", "qiaseq" or "cats"
Trimming options
--three_prime_adapter 3’ Adapter to trim. Default: None
--min_length [int] Discard reads that became shorter than length [int] because of either quality or adapter trimming. Default: 18
--clip_R1 [int] Instructs Trim Galore to remove bp from the 5' end of read 1
--three_prime_clip_R1 [int] Instructs Trim Galore to remove bp from the 3' end of read 1 AFTER adapter/quality trimming has been performed
Other options
--outdir The output directory where the results will be saved
--email Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits
-name Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic
""".stripIndent()
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Show help message
if (params.help){
helpMessage()
exit 0
}
if (params.csv){
Channel
.fromPath(params.csv, checkIfExists: true)
.splitCsv(header:false)
.map { row -> [file(row[0]), row[1]] }
.ifEmpty { exit 1, "params.csv was empty - no input files supplied" }
.set{raw_reads_trimgalore}
} else if (params.reads) {
Channel
.fromPath( params.reads )
.ifEmpty { exit 1, "Cannot find any reads matching: ${params.reads}" }
.set {raw_reads_trimgalore}
}
ch_multiqc_config = Channel.fromPath(params.multiqc_config, checkIfExists: true)
/*
* STEP 2 - Trim Galore!
*/
process trim_galore {
label 'process_low'
tag "$reads"
publishDir "${params.outdir}/trim_galore", mode: 'copy'
input:
set file(reads), val(protocol) from raw_reads_trimgalore
output:
file '*.gz' into reads_trimmed_ch
file '*trimming_report.txt' into trimgalore_results
file "*_fastqc.{zip,html}" into fastqc_results
script:
// Define regular variables so that they can be overwritten
clip_R1 = params.clip_R1
three_prime_clip_R1 = params.three_prime_clip_R1
three_prime_adapter = params.three_prime_adapter
// Presets
if (protocol == "illumina"){
clip_R1 = 0
three_prime_clip_R1 = 0
three_prime_adapter = "TGGAATTCTCGGGTGCCAAGG"
} else if (protocol == "nebnext"){
clip_R1 = 0
three_prime_clip_R1 = 0
three_prime_adapter = "AGATCGGAAGAGCACACGTCT"
} else if (protocol == "nextflex"){
clip_R1 = 4
three_prime_clip_R1 = 4
three_prime_adapter = "TGGAATTCTCGGGTGCCAAGG"
} else if (protocol == "qiaseq"){
clip_R1 = 0
three_prime_clip_R1 = 0
three_prime_adapter = "AACTGTAGGCACCATCAAT"
} else if (protocol == "cats"){
clip_R1 = 3
three_prime_clip_R1 = 0
// three_prime_adapter = "GATCGGAAGAGCACACGTCTG"
three_prime_adapter = "AAAAAAAA"
} else {
//custom protocol
clip_R1 = params.clip_R1
three_prime_clip_R1 = params.three_prime_clip_R1
three_prime_adapter = params.three_prime_adapter
protocol = params.protocol
}
tg_length = "--length 15"
c_r1 = clip_R1 > 0 ? "--clip_R1 ${clip_R1}" : ''
tpc_r1 = three_prime_clip_R1 > 0 ? "--three_prime_clip_R1 ${three_prime_clip_R1}" : ''
"""
trim_galore --adapter ${three_prime_adapter} $tg_length $c_r1 $tpc_r1 --max_length 40 --gzip $reads --fastqc
"""
}
/*
* STEP 7 - miRTrace
*/
process mirtrace {
tag "$reads"
publishDir "${params.outdir}/miRTrace", mode: 'copy'
input:
file reads from reads_trimmed_ch.collect()
output:
file '*mirtrace' into mirtrace_results
script:
"""
for i in $reads
do
path=\$(realpath \${i})
prefix=\$(echo \${i} | sed -e "s/.gz//" -e "s/.fastq//" -e "s/.fq//" -e "s/_val_1//" -e "s/_trimmed//" -e "s/_R1//" -e "s/.R1//")
echo \$path","\$prefix
done > mirtrace_config
mirtrace qc \\
--species $params.mirtrace_species \\
--config mirtrace_config \\
--write-fasta \\
--output-dir mirtrace \\
--force
"""
}
/*
* STEP 8 - MultiQC
*/
process multiqc {
publishDir "${params.outdir}/MultiQC", mode: 'copy'
input:
file ('fastqc/*') from fastqc_results.collect()
file ('trim_galore/*') from trimgalore_results.collect()
file multiqc_config from ch_multiqc_config
output:
file "*multiqc_report.html" into multiqc_report
file "*_data"
script:
"""
multiqc . --config $multiqc_config -f -m cutadapt -m fastqc
"""
}
/*
* Completion e-mail notification
*/
workflow.onComplete {
// Set up the e-mail variables
def subject = "[nf-core/smadann] Successful: $workflow.runName"
if(!workflow.success){
subject = "[nf-core/smadann] FAILED: $workflow.runName"
}
}