This repository has been archived by the owner on Oct 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
270 lines (199 loc) · 6.13 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
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
#!/usr/bin/env nextflow
nextflow.preview.dsl = 2
// Set some globals
DBCAN_VERSIONS = ["v4", "v5", "v6", "v7", "v8"]
DBCAN_URLS = [
"v4": "http://bcb.unl.edu/dbCAN2/download/Databases/dbCAN-old@UGA/dbCAN-fam-HMMs.txt.v4",
"v5": "http://bcb.unl.edu/dbCAN2/download/Databases/dbCAN-old@UGA/dbCAN-fam-HMMs.txt.v5",
"v6": "http://bcb.unl.edu/dbCAN2/download/Databases/dbCAN-HMMdb-V6.txt",
"v7": "http://bcb.unl.edu/dbCAN2/download/Databases/dbCAN-HMMdb-V7.txt",
"v8": "http://bcb.unl.edu/dbCAN2/download/Databases/dbCAN-HMMdb-V8.txt",
]
def helpMessage() {
log.info "# CATAStrophy-pipeline"
log.info"""
Usage:
The typical command for running the pipeline is as follows:
nextflow run nf-core/catastroflow --reads '*_R{1,2}.fastq.gz' -profile docker
Mandatory arguments:
--proteomes Path to input proteomes as fasta files (Glob patterns must be surrounded with quotes).
--dbcan An HMMER3 formatted database from dbcan.
--dbcan_version The version of dbcan used.
--dbcan_url The URL to an HMMER3 formatted database to download.
-profile Configuration profile to use. Can use multiple (comma separated)
Available: conda, docker, singularity, awsbatch, test and more.
Options:
Other options:
--outdir The output directory where the results will be saved
-name Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.
""".stripIndent()
}
def handle_dbcan_params(params) {
if ( (params.dbcan || params.dbcan_url) && !params.dbcan_version ) {
exit 1, "Please provide the dbcan version that you are providing " +
"using '--dbcan_version'."
}
if ( params.dbcan_version && !(params.dbcan_version in DBCAN_VERSIONS) ) {
exit 1, "The dbcan version you provided is not supported. " +
"Valid options are ${DBCAN_VERSIONS}."
}
// Set default version
dbcan_version = params.dbcan_version ?: DBCAN_VERSIONS[-1]
if ( params.dbcan ) {
dbcan_file = file(params.dbcan, checkIfExists: true)
} else {
url = params.dbcan_url ?: DBCAN_URLS[dbcan_version]
dbcan_file = download_dbcan(url)
}
return [dbcan_version, dbcan_file]
}
def handle_proteomes_params(params) {
if (params.proteomes) {
// Can't use the .set {} syntax inside functions.
ch_proteomes = Channel
.fromPath(params.proteomes, checkIfExists: true, type: 'file')
.map { f -> [f.simpleName, f] }
} else {
exit 1, "Please provide one or more fasta files to the --proteome parameter."
}
return ch_proteomes
}
process download_dbcan {
label "download"
label "small_task"
input:
val url
output:
path 'dbcan.txt', emit: downloaded_db
script:
"""
wget -O dbcan.txt "${url}"
"""
}
process hmmpress {
label "hmmer"
label "small_task"
input:
path "database.txt"
output:
tuple path("database.txt"),
path("database.txt.h3f"),
path("database.txt.h3i"),
path("database.txt.h3m"),
path("database.txt.h3p"), emit: pressed_hmms
script:
"""
hmmpress database.txt
"""
}
process hmmscan {
label "hmmer"
label "small_task"
tag "${name}"
input:
tuple path("database.txt"),
path("database.txt.h3f"),
path("database.txt.h3i"),
path("database.txt.h3m"),
path("database.txt.h3p")
tuple val(name), path(proteome)
output:
tuple val(name), path("${name}.csv"), emit: domtab
tuple val(name), path("${name}.txt"), emit: txt
script:
"""
hmmscan \
--domtblout "${name}.csv" \
database.txt \
"${proteome}" \
> "${name}.txt"
"""
}
process catastrophy {
label "catastrophy"
label "small_task"
input:
val version
val names
path domtabs
output:
path "catastrophy.tsv"
path "catastrophy_pca.tsv"
path "catastrophy_counts.tsv"
script:
"""
catastrophy \
--format "hmmer_domtab" \
--model "${version}" \
--outfile "catastrophy.tsv" \
--pca "catastrophy_pca.tsv" \
--counts "catastrophy_counts.tsv" \
--label ${names.join(" ")} \
-- \
${domtabs}
"""
}
workflow search_proteomes {
take:
database_file
proteomes_ch
main:
pressed_hmms = hmmpress(database_file)
(hmmscan_domtabs, hmmscan_txts) = hmmscan(pressed_hmms, proteomes_ch)
emit:
hmmscan_domtabs
hmmscan_txts
}
workflow classify_proteomes {
take:
dbcan_version
domtabs
main:
domtabs_forked = domtabs
.multiMap {
name: it[0]
file: it[1]
}
(classified, pca, counts) = catastrophy(
dbcan_version,
domtabs_forked.name.collect(),
domtabs_forked.file.collect()
)
emit:
classified
pca
counts
}
// Until we get some clarity on what will replace the publish
// workflow section, this is the workaround.
// I don't love it.
process publish_it {
label "process_low"
label "posix"
publishDir "${params.outdir}", saveAs: { name }
input:
tuple val(name), path("infile")
output:
path "infile", includeInputs: true
script:
"""
"""
}
workflow {
main:
// Show help message
if (params.help) {
helpMessage()
exit 0
}
proteomes_ch = handle_proteomes_params(params)
(dbcan_version, dbcan_file) = handle_dbcan_params(params)
(hmmscan_domtabs, hmmscan_txts) = search_proteomes(dbcan_file, proteomes_ch)
(classifications_file, pca_file, counts_file) = classify_proteomes(dbcan_version, hmmscan_domtabs)
hmmscan_domtabs.map { n, f -> ["matches/${f.name}", f] }.mix(
hmmscan_txts.map { n, f -> ["matches/${f.name}", f] },
classifications_file.map { ["${it.name}", it] },
pca_file.map { ["${it.name}", it] },
counts_file.map { ["${it.name}", it] }
) | publish_it
}