-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse_wg_ncbi.nf
276 lines (211 loc) · 6.89 KB
/
analyse_wg_ncbi.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
params.groupe='Mammalia'
params.workpath='/pasteur/appa/scratch/jfumey/busco/work/'
//params.resultspath='/pasteur/appa/homes/jfumey/didier/busco_try/'
params.resultspath='/pasteur/appa/scratch/jfumey/busco/results/'
params.ncbiapikey="84413ef210acc86d928b322060eb89aa1808"
params.buscoRefFile="mammalia_odb10"
params.buscoDLpath="/pasteur/appa/homes/jfumey/busco/busco_downloads/"
groupe=params.groupe
resultsDir=file(params.resultspath)
ncbiapikey=params.ncbiapikey
buscoRefFile=params.buscoRefFile
buscoDLpath=params.buscoDLpath
process listGenome{
label 'ncbi'
input:
val groupToStudy from groupe
output:
file('uid_list.txt') into list_id
script:
"""
export NCBI_API_KEY=$ncbiapikey
esearch -db assembly -query ${groupToStudy} | efetch -format uid > uid_list.txt
"""
}
list_id.splitText().map{it -> it.trim()}.into{ids1; ids2}
process getSummaryGenome{
publishDir "${resultsDir}/01_genome_summary", mode: 'copy'
label 'ncbi'
maxForks = 10
input:
val(genomeId) from ids1
output:
file('*summary.txt') into summary
script:
"""
export NCBI_API_KEY=$ncbiapikey
esummary -db assembly -id ${genomeId} > ${genomeId}_summary.txt
sleep 1
"""
}
process getDownloadLink{
//publishDir "${resultsDir}", mode: 'link'
label 'selectDLlink'
input:
file(s) from summary
output:
file('genome_info.csv') optional true into all_info, all_info2, all_info3
file('nogenome.csv') optional true into nogenome
script:
"""
if grep -q suppressed ${s}
then
touch nogenome.csv
elif grep -q excluded-from-refseq ${s}
then
touch nogenome.csv
elif grep -q FtpPath_Assembly_rpt ${s}
then
if grep "<FtpPath_Assembly_rpt></FtpPath_Assembly_rpt>" ${s}
then
touch nogenome.csv
else
selectDLlink.sh ${s} > genome_info.csv
fi
else
touch nogenome.csv
fi
"""
}
process gatherGenomeInfo{
publishDir "${resultsDir}/Info", mode:'copy'
input:
file(allinfo) from all_info3.collectFile()
output:
file "info_all_genome.txt" into all_info_publish
script:
"""
cat ${allinfo} > info_all_genome.txt
"""
}
process removeAltGenome{
//publishDir "${resultsDir}", mode: 'link'
scratch '/pasteur/appa/scratch/jfumey/busco/'
input:
file(in) from all_info2.collectFile()
output:
file('NoAlt_All_infos.csv') into all_info_noalt, all_info_noalt2
script:
"""
grep -v "alt_assembly" $in > NoAlt_All_infos.csv
"""
}
process createUniqSpeciesFile{
input:
file(in) from all_info_noalt
output:
file('uniq_species.txt') into uniq_species
script:
"""
cut -d, -f 2 $in | sort | uniq > uniq_species.txt
"""
}
uniq_species.splitText(by:1).map{it -> it.trim()}.into{species1;species2}
process downloadGenome{
//publishDir "${resultsDir}", mode: 'copy'
label 'dl'
executor 'local'
maxForks 1
input:
val(spName) from species1
each file(noalt) from all_info_noalt2
output:
file('genome_file_info.csv') into genomeInfo
tuple val(spName), file('*.fna.gz') into fastaFile
tuple val(spName), file('*_report.txt') into reportFile
shell:
'''
selectGenome.sh "!{spName}" !{noalt} > genome_file_info.csv
'''
}
process unzipFasta{
errorStrategy 'ignore'
publishDir "${resultsDir}/Genomes/${spName}/", mode: 'copy'
input:
tuple val(spName), file(fasta) from fastaFile
output:
tuple val(spName), file(fasta), file('unzip.fasta') optional true into fastaUnzipped, fastaUnzipped2
script:
"""
gunzip -k -c ${fasta} > unzip.fasta
"""
}
process checkforAltScaffold{
publishDir "${resultsDir}/Info", pattern: '*_info_removed_genome_parts.txt' , mode: 'copy'
input:
tuple val(spName), file(report) from reportFile
output:
file('modified_genome.txt') optional true into listofModifiedGenome
file('good_scaffold_list.txt') optional true into listGoodScaffold
file("${report.baseName}_info_removed_genome_parts.txt") optional true into listRemovedGenomeParts
file("notrim.txt") optional true into notrim
script:
"""
if grep -q alt-scaffold $report
then
echo "${spName}" > modified_genome.txt
listGoodScaffold.sh ${report} > good_scaffold_list.txt
listRemovedGenomeParts.sh ${report} > ${report.baseName}_info_removed_genome_parts.txt
else
touch notrim.txt
fi
"""
}
process publishModified{
publishDir "${resultsDir}/Info", mode:'copy'
input:
file modified from listofModifiedGenome.collectFile()
output:
file "modifiedGenome.txt" into modified_genome
script:
"""
cat ${modified} > modifiedGenome.txt
"""
}
process removeAltScaffold{
publishDir "${resultsDir}/Genomes/${spName}/", mode: 'copy'
label 'samtools'
input:
tuple val(spName), file(fasta), file(infasta) from fastaUnzipped
file(goodScaffold) from listGoodScaffold
output:
tuple val(spName), file(fasta), file('genome_trimmed.fasta') into trimmedFasta
script:
"""
samtools faidx ${infasta} < ${goodScaffold} > genome_trimmed.fasta
"""
}
process busco{
//publishDir "${resultsDir}/results/${spName}/", mode:'copy'
label 'busco'
maxForks 50
//scratch '/pasteur/appa/scratch/jfumey/busco/'
input:
val buscoref from buscoRefFile
val buscoDLPath from buscoDLpath
tuple val(spName), file(fasta), file(fastaUnzipped) from ( notrim ? fastaUnzipped2 : trimmedFasta )
output:
//tuple val(spName), path("*-busco.batch_summary.txt"), emit: batch_summary
//tuple val(spName), file(val), file("${spName.replaceAll(/\s/,'_')}/short_summary.*json") into short_summary_json
tuple val(spName), file(fasta), file("${spName.replaceAll(/[^a-zA-Z0-9\-\_]/,'_')}/short_summary.*txt") into short_summary_txt
//tuple val(spName), file("${spName.replaceAll(/\s/,'_')}/full_table*.tsv") optional true into full_tables
//tuple val(spName), file("${spName.replaceAll(/\s/,'_')}/missing_busco_list.*tsv") optional true into busco_list
script:
"""
busco -i ${fastaUnzipped} -m genome -o ${spName.replaceAll(/[^a-zA-Z0-9\-\_]/,'_')} -l ${buscoref} --download_path ${buscoDLPath} -c 40 --offline -f --metaeuk_parameters='--remove-tmp-files=1' --metaeuk_rerun_parameters='--remove-tmp-files=1'
"""
}
process extractResults{
label 'extractResults'
input:
tuple val(spName), file(fasta), file(json) from short_summary_txt
output:
file('busco_results.csv') into finalResults
script:
"""
extractResult.py --input ${json} --species ${spName.replaceAll(/[^a-zA-Z0-9\-\_]/,'_')} --genomeFile ${fasta.getName()} --output "busco_results.csv"
"""
}
finalResults.collectFile(name: "busco_results.csv", keepHeader: true, skip: 1).subscribe{
f -> f.copyTo(resultsDir.resolve(f.name))
}