-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_el_gato.nf
206 lines (162 loc) · 4.73 KB
/
run_el_gato.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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
params.reads_dir = false
params.assembly_dir = false
params.threads = 1
params.depth = 10
params.length = 0.3
params.sequence = 95.0
params.out = 'el_gato_out'
params.samfile = false
params.help = false
if ( params.help ) {
help = """run_el_gato.nf: A nextflow pipeline that runs el_gato.py
|Required arguments:
| Please specify either reads_dir OR assembly_dir
| --reads_dir Location of the directory containing Illumina
| paired-end samples. Sequence files can be gzipped.
| --assembly_dir Location of the directory contaning Legionella pneumophila
| genome assemblies.
|Optional arguments:
| --help Show this help message and exit
| --threads Number of threads per process (e.g. that el_gato will use per sample)
| [default: ${params.threads}]
| --depth Specify the minimum depth used to identify loci in paired-end reads
| [default: ${params.depth}]
| --length Specify the BLAST hit length threshold for identifying multiple loci
| in assembly [default: ${params.length}]
| --sequence Specify the BLAST hit percent identity threshold for identifying
| multiple loci in assembly [default: ${params.sequence}]
| --out Output folder name [default: ${params.out}]""".stripMargin()
// Print the help with the stripped margin and exit
println(help)
exit(0)
}
process RUN_EL_GATO_READS {
cpus params.threads
publishDir params.out, mode: 'copy', overwrite: true, pattern: '*_out/*'
label 'elgato'
input:
tuple val(sampleId), file(reads)
output:
path '*_out/*', emit: files
script:
r1 = reads[0]
r2 = reads[1]
if (params.samfile == true) {
"""
mkdir ${sampleId}_out/
el_gato.py \
-1 $r1 \
-2 $r2 \
-o ${sampleId}_out \
-t ${task.cpus} \
-d $params.depth \
-m \
-w > mlst.txt
mv mlst.txt ${sampleId}_out/
for file in \$(ls ${sampleId}_out/); do
mv ${sampleId}_out/\$file ${sampleId}_out/${sampleId}_\$file
done
"""
}else{
"""
mkdir ${sampleId}_out/
el_gato.py \
-1 $r1 \
-2 $r2 \
-o ${sampleId}_out \
-t ${task.cpus} \
-d $params.depth \
-w > mlst.txt
mv mlst.txt ${sampleId}_out/
for file in \$(ls ${sampleId}_out/); do
mv ${sampleId}_out/\$file ${sampleId}_out/${sampleId}_\$file
done
"""
}
}
process RUN_EL_GATO_ASSEMBLIES {
cpus 1
publishDir params.out, mode: 'copy', overwrite: true, pattern: '*_out/*'
label 'elgato'
input:
path assembly
float length
float sequence
output:
path '*_out/*', emit: files
script:
"""
sample_id=$assembly
sample_id=\${sample_id%.*}
el_gato.py \
-a $assembly \
-o \${sample_id}_out \
-t ${task.cpus} \
-l $params.length \
-q $params.sequence \
-w > mlst.txt
mv mlst.txt \${sample_id}_out/
for file in \$(ls \${sample_id}_out/); do
mv \${sample_id}_out/\$file \${sample_id}_out/\${sample_id}_\$file
done
"""
}
process CAT {
publishDir params.out, mode: 'copy', overwrite: true
input:
path files
output:
path 'all_mlst.txt'
"""
printf "Sample\tST\tflaA\tpilE\tasd\tmip\tmompS\tproA\tneuA_neuAH\n" > all_mlst.txt
cat \$(ls ${files} | grep mlst | grep -v possible_mlsts) >> all_mlst.txt
"""
}
process FINAL_JSON {
publishDir params.out, mode: 'copy', overwrite: true
input:
path files
output:
path 'report.json'
"""
echo "[" > report.tmp
cat \$(ls *.json | head -1) >> report.tmp
ls *.json | tail -n+2 | while read jfile; do
echo "," >> report.tmp;
cat \$jfile >> report.tmp;
done
echo "]" >> report.tmp
mv report.tmp report.json
"""
}
process FINAL_REPORT {
publishDir params.out, mode: 'copy', overwrite: true
input:
path files
output:
path 'report.pdf'
"""
elgato_report.py -i *.json -o report.pdf
"""
}
workflow {
if (params.reads_dir) {
readPairs = Channel.fromFilePairs(params.reads_dir + "/*R{1,2}*.fastq*", checkIfExists: true)
files = RUN_EL_GATO_READS(readPairs).collect()
CAT(files)
FINAL_JSON(files)
FINAL_REPORT(files)
} else {
if (params.assembly_dir) {
assemblies = Channel.fromPath(params.assembly_dir + '/*', checkIfExists: true)
files = RUN_EL_GATO_ASSEMBLIES(assemblies).collect()
CAT(files)
FINAL_JSON(files)
FINAL_REPORT(files)
} else {
print "Please provide the path to a directory containing paired reads using --reads_dir or the path to a directory containing assemblies using --assembly_dir."
}
}
}