-
Notifications
You must be signed in to change notification settings - Fork 0
/
viabusco.nf
179 lines (141 loc) · 4.77 KB
/
viabusco.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
#!/usr/bin/env nextflow
if(!workflow.profile.contains('BUSCOs')) {
println("This workflow requires -profile BUSCOs")
exit 1
}
//INPUT PARAMS
trialLines = params.trialLines
import static groovy.json.JsonOutput.*
/*
Generic method for extracting a string tag or a file basename from a metadata map
*/
def getTagFromMeta(meta, delim = '_') {
return (meta.species+delim+meta.version+(trialLines == null ? "" : delim+trialLines+delim+"trialLines"))
}
/*
Generic method for extracting a string tag or a file basename from a metadata map
*/
def getAnnotationTagFromMeta(meta, delim = '_') {
return meta.species+delim+meta.version+(meta.containsKey("annotation") ? delim+meta.annotation : "")+(trialLines == null ? "" : delim+trialLines+delim+"trialLines")
}
def helpMessage() {
log.info"""
Usage:
nextflow run plantinformatics/pretzel-input-generator
Default params:
""".stripIndent()
println(prettyPrint(toJson(params)))
}
// Show help message
params.help = false
if (params.help){
helpMessage()
exit 0
}
//ARRANGE INPUTS FOR PROCESSES
referencesLocal = Channel.create()
referencesRemote = Channel.create()
params.assemblies.each { assembly ->
//sanitise any trailing spaces in strings
// assembly.each {k,v -> assembly[k] = v.trim()}
//Abbreviate Genus_species name to G_species
assembly.species = (assembly.species =~ /^./)[0]+(assembly.species =~ /_.*$/)[0]
if(assembly.containsKey("fasta")) {
if((assembly.fasta).matches("^(https?|ftp)://.*\$")) {
referencesRemote << assembly
} else {
referencesLocal << [assembly,file(assembly.fasta)]
}
}
}
referencesRemote.close()
referencesLocal.close()
process fetchRemoteReference {
// storeDir {executor == 'awsbatch' ? "${params.outdir}/downloaded" : "downloaded"}
// scratch false
tag{meta.subMap(['species','version'])}
label 'download'
input:
val(meta) from referencesRemote
output:
set val(meta), file("${basename}.fasta") into referencesRemoteFasta
script:
basename=getTagFromMeta(meta)
//DECOMPRESS?
cmd = (meta.fasta).matches("^.*\\.gz\$") ? "| gunzip --stdout " : " "
//TRIAL RUN? ONLY TAKE FIRST n LINES
cmd += trialLines != null ? "| head -n ${trialLines}" : ""
"""
curl -L ${meta.fasta} ${cmd} > ${basename}.fasta
"""
}
//Mix local and remote references then connect o multiple channels
// referencesRemoteFasta.mix(referencesLocal).into{ references }
process indexReference() {
tag{meta.subMap(['species','version'])}
label 'samtools'
input:
set val(meta), file(fasta) from referencesRemoteFasta.mix(referencesLocal)
output:
set val(meta), file(fasta), file("${fasta}.fai") into indexedReferences1, indexedReferences2
"""
samtools faidx ${fasta}
"""
}
lineage = params.busco.lineage
process fetchAndPrepBuscoData {
scratch false
tag{ "${fname}" }
input:
val params.busco.lineage
output:
file (lineage.substring(lineage.lastIndexOf('/') + 1).replaceAll('.tar.gz','')) into lineageChannel
script:
fname = lineage.substring(lineage.lastIndexOf('/') + 1);
//DOWNLOAD?
fetch = lineage.matches("^(https?|ftp)://.*\$") ? "wget --no-check-certificate" : "ln -s"
//DECOMPRESS?
unzip = lineage.matches("^.*\\.tar\\.gz\$") ? "tar xzvf ${fname}" : " "
"""
${fetch} ${lineage}
${unzip}
"""
}
process runBUSCO {
label 'BUSCO'
label 'summary'
tag{outmeta.subMap(['species','version','lineage'])}
input:
set val(meta), file(fasta), file("${fasta}.fai"), file(lineage) from indexedReferences2.combine(lineageChannel)
output:
set val(outmeta), file("run_${basename}/full_table_${basename}.tsv"), file("${fasta}.fai") into computedBUSCOs
file ("run_${basename}/short_summary_${basename}.txt")
script:
outmeta = meta.clone()
outmeta.lineage = lineage.name
basename=getTagFromMeta(meta)
//BUSCO wants to write to ${AUGUSTUS_CONFIG_PATH} which may be in a read-only container!
"""
cp -r \${AUGUSTUS_CONFIG_PATH} augustus_config
export AUGUSTUS_CONFIG_PATH=augustus_config
run_BUSCO.py -i ${fasta} -o ${basename} --lineage_path ${lineage} --mode genome --cpu ${task.cpus} --species ${params.busco.augustusSpecies} --tarzip
rm -r augustus_config
"""
}
process generateStandaloneJSONfromBUSCOs {
tag{tag}
label 'json'
label 'groovy'
errorStrategy 'ignore'
input:
set val(meta), file(tsv), file(fai) from computedBUSCOs
output:
file "*.json.gz" into featuresJSON
// file "*.json.gz" into featuresJSON
script:
tag=getAnnotationTagFromMeta(meta)
genome=getTagFromMeta(meta)
shortName = (meta.containsKey("shortName") ? meta.shortName : "")
shortName +=(meta.containsKey("annotation") ? "_"+meta.annotation : "") //only for cases where multiple annotations per genome
template 'BUSCO_2_standaloneJSON.groovy'
}