-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.nf
More file actions
224 lines (183 loc) · 6.67 KB
/
Copy pathmain.nf
File metadata and controls
224 lines (183 loc) · 6.67 KB
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
nextflow.enable.dsl=2
params.help = false
if (params.help) {
log.info """
=======================================================================
GORG Classifier, Single Cell Genome Center, Bigelow Laboratory
=======================================================================
#### Homepage / Documentation
https://github.com/BigelowLab/gorg-classifier
#### Citation
https://doi.org/10.1016/j.cell.2019.11.017
#### Reference data
URL: https://osf.io/pcwj9
License: Attribution-NonCommercial 4.0 International.
#### Authors
Joe Brown <[email protected]>
-----------------------------------------------------------------------
Required arguments
--seqs
File path with wildcard(s) of your sequence files,
e.g. "/data/*.fastq.gz"
Optional parameters
--mode
One of 'ncbi', 'crest', or 'local'. Downloads references
and annotates using respective reference files
Default: 'ncbi'
--outdir
Directory, existing or not, into which the output is written
Default: './results'
--cpus
CPUs allocated to `kaiju`
Default: 8
--mismatches
The number of mismatches allowed in a kaiju alignment
Default: 3
--minlength
The minimum alignment length threshold for kaiju alignments
Default: 11
Local mode
--nodes
File path to nodes.dmp
--names
File path to names.dmp
--fmi
File path to kaiju index (ends with .fmi)
--annotations
File path to GORG functional annotations (ends with .tsv)
-----------------------------------------------------------------------
""".stripIndent()
exit 0
}
// required arguments
params.seqs = false
// local mode
params.nodes = false
params.annotations = false
params.names = false
params.fmi = false
if (!params.seqs) { exit 1, "--seqs is not defined" }
if (params.mode == "local") {
if (!params.nodes) { exit 1, "--nodes is not defined" }
if (!params.names) { exit 1, "--names is not defined" }
if (!params.fmi) { exit 1, "--fmi is not defined" }
if (!params.annotations) { exit 1, "--annotations is not defined" }
nodes = file(params.nodes)
names = file(params.names)
fmi = file(params.fmi)
annotations = file(params.annotations)
// check file existence
if( !nodes.exists() ) { exit 1, "Missing taxonomy nodes: ${nodes}" }
if( !names.exists() ) { exit 1, "Missing taxonomy names: ${names}" }
if( !fmi.exists() ) { exit 1, "Missing kaiju index: ${fmi}" }
if( !annotations.exists() ) { exit 1, "Missing GORG annotations: ${annotations}" }
}
else if(params.mode == "ncbi") {
// future file versioning will look like: ?action=download&version=1&direct
fmi = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12d0946b571000d064725")
annotations = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12a440db187000e3afd8a")
names = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12d3146b571000b0663af")
nodes = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12d3446b571000d06473b")
}
else if(params.mode == "crest") {
fmi = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12c74743c23000c9ed206")
annotations = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12a440db187000e3afd8a")
names = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12d0c743c23000a9ee2bf")
nodes = file("https://files.osf.io/v1/resources/pcwj9/providers/osfstorage/5db12d0b46b571000e06e7a8")
} else {
exit 1, "--mode must be one of 'ncbi', 'crest', or 'local'"
}
log.info """
=======================================================================
GORG Classifier, Single Cell Genome Center, Bigelow Laboratory
=======================================================================
#### Homepage / Documentation
https://github.com/BigelowLab/gorg-classifier
#### Citation
https://doi.org/10.1016/j.cell.2019.11.017
#### Reference data
URL: https://osf.io/pcwj9
License: Attribution-NonCommercial 4.0 International.
#### Authors
Joe Brown <[email protected]>
-----------------------------------------------------------------------
Sequences (*.fq/*.fna) : ${params.seqs}
Mode : ${params.mode}
Nodes (nodes.dmp) : ${nodes}
Names (names.dmp) : ${names}
Kaiju Index (.fmi) : ${fmi}
GORG Annotations (.tsv) : ${annotations}
Output directory : ${params.outdir}
Kaiju mismatches : ${params.mismatches}
Kaiju minimum alignment length : ${params.minlength}
Kaiju CPUs : ${params.cpus}
-----------------------------------------------------------------------
""".stripIndent()
process run_kaiju {
tag "$sample"
cpus params.cpus
input:
tuple val(sample), path(r1), path(r2)
path(nodes)
path(fmi)
output:
tuple val(sample), path("${sample}_hits.txt")
script:
def r2path = r2 ? "-j ${r2}" : ""
"""
kaiju -z ${task.cpus} -v -m ${params.minlength} \
-e ${params.mismatches} -t $nodes -f $fmi \
-i ${r1} ${r2path} -o ${sample}_hits.txt
"""
}
process add_taxonomy {
tag "$sample"
input:
tuple val(sample), path(hits)
path(nodes)
path(names)
output:
tuple val(sample), path("${sample}_hits_names.txt.gz")
script:
"""
kaiju-addTaxonNames -t ${nodes} -n ${names} -i ${hits} -o ${sample}_hits_names.txt \
-r superkingdom,phylum,class,order,family,genus,species
gzip ${sample}_hits_names.txt
"""
}
process add_functions {
tag "$sample"
publishDir path: "${params.outdir}/annotations"
input:
tuple val(sample), path(hits)
path(annotations)
output:
tuple val(sample), path("${sample}_annotated.txt.gz")
script:
template 'add_functions.py'
}
process summarize_annotations {
tag "$sample"
publishDir path: "${params.outdir}/summaries"
cache false
input:
tuple val(sample), path(hits)
output:
path("${sample}_summary.txt")
script:
template 'summarize_annotations.py'
}
workflow {
seqs = Channel
.fromFilePairs(params.seqs, size: -1, checkIfExists: true, flat: true)
.map { it ->
if (it.size == 2) {
it.add([])
}
return it
}
run_kaiju(seqs, nodes, fmi)
add_taxonomy(run_kaiju.out, nodes, names)
add_functions(add_taxonomy.out, annotations)
summarize_annotations(add_functions.out)
}