Skip to content

Commit a9bf44e

Browse files
Diamond (#161)
* added diamond components * removed quotes
1 parent 22a21aa commit a9bf44e

File tree

5 files changed

+157
-1
lines changed

5 files changed

+157
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ resolution
2525
- Added component `unicycler`.
2626
- Added component `prokka`.
2727
- Added component `bcalm`.
28+
- Added component `diamond`.
2829

2930
### Minor/Other changes
3031

docs/user/components/diamond.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
diamond
2+
=======
3+
4+
Purpose
5+
-------
6+
7+
This component performs ``blastx`` or ``blastp`` with diamond. The database
8+
used by diamond can be provided from the local disk or generated in the process.
9+
This component uses the same output type as abricate with the same blast output
10+
fields.
11+
12+
.. note::
13+
Software page: https://github.com/bbuchfink/diamond
14+
15+
16+
Input/Output type
17+
-----------------
18+
19+
- Input type: ``Fasta``
20+
- Output type: None
21+
22+
.. note::
23+
The default input parameter for fasta data is ``--fasta``.
24+
25+
Parameters
26+
----------
27+
28+
- ``pathToDb``: Provide full path for the diamond database. If none is provided
29+
then will try to fetch from the previous process. Default: None
30+
31+
- ``fastaToDb``: Provide the full path for the fasta to construct a diamond
32+
database. Default: None
33+
34+
- ``blastType``: Defines the type of blast that diamond will do. Can wither be
35+
blastx or blastp. Default: blastx
36+
37+
Published results
38+
-----------------
39+
40+
- ``results/annotation/diamond*``: Stores the results of the abricate screening
41+
for each sample and for each specified database.
42+
43+
Published reports
44+
-----------------
45+
46+
None.
47+
48+
Default directives
49+
------------------
50+
51+
- ``diamond``:
52+
- ``container``: flowcraft/diamond
53+
- ``version``: 0.9.22-1
54+
- ``memory``: { 4.GB * task.attempt }
55+
- ``cpus``: 2

flowcraft/generator/components/annotation.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CardRgi(Process):
7676
- ``input_type``: fasta
7777
- ``output_type``: txt
7878
- ``ptype``: resistance gene detection (assembly)
79-
"""
79+
"""
8080

8181
def __init__(self, **kwargs):
8282

@@ -158,3 +158,49 @@ def __init__(self, **kwargs):
158158
"version": "1.12"
159159
}
160160
}
161+
162+
163+
class Diamond(Process):
164+
"""diamond process for protein database queries
165+
166+
This process is set with:
167+
168+
- ``input_type``: fasta
169+
- ``output_type``: None
170+
- ``ptype``: post_assembly
171+
"""
172+
173+
def __init__(self, **kwargs):
174+
175+
super().__init__(**kwargs)
176+
177+
self.input_type = "fasta"
178+
self.output_type = None
179+
180+
self.params = {
181+
"pathToDb": {
182+
"default": 'null',
183+
"description": "Provide full path for the diamond database. "
184+
"If none is provided then will try to fetch from"
185+
" the previous process. Default: None"
186+
},
187+
"fastaToDb": {
188+
"default": 'null',
189+
"description": "Provide the full path for the fasta to "
190+
"construct a diamond database. Default: None"
191+
},
192+
"blastType": {
193+
"default": "'blastx'",
194+
"description": "Defines the type of blast that diamond will do."
195+
"Can wither be blastx or blastp. Default: blastx"
196+
}
197+
}
198+
199+
self.directives = {
200+
"diamond": {
201+
"container": "flowcraft/diamond",
202+
"version": "0.9.22-1",
203+
"memory": "{ 4.GB * task.attempt }",
204+
"cpus": 2
205+
}
206+
}

flowcraft/generator/engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"check_coverage": readsqc.CheckCoverage,
6666
"chewbbaca": mlst.Chewbbaca,
6767
"dengue_typing": typing.DengueTyping,
68+
"diamond": annotation.Diamond,
6869
"downsample_fastq": readsqc.DownsampleFastq,
6970
"fastqc": readsqc.FastQC,
7071
"fastqc_trimmomatic": readsqc.FastqcTrimmomatic,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// check if any of the parameters it defined before executing the process.
2+
if (!params.pathToDb{{ param_id }} && !params.fastaToDb{{ param_id }})
3+
exit 1, "'You must specify either a pathToDb or fastaToDb parameter.'"
4+
// checks if both are defined and if so raises an error.
5+
else if (params.pathToDb{{ param_id }} && params.fastaToDb{{ param_id }})
6+
exit 1, "'Both pathToDb and fastaToDb were given, choose just one.'"
7+
8+
// list of blasts allowed for diamond
9+
allowedBlasts = ["blastp", "blastx"]
10+
// checks if blast type os defined
11+
if (!allowedBlasts.contains(params.blastType{{ param_id }}))
12+
exit 1, "Provide a valid blast type: blastx or blastp"
13+
14+
process diamond_{{ pid }} {
15+
16+
// Send POST request to platform
17+
{% include "post.txt" ignore missing %}
18+
19+
tag { sample_id }
20+
publishDir "results/annotation/diamond_{{ pid }}/${sample_id}"
21+
22+
input:
23+
set sample_id, file(assembly) from {{ input_channel }}
24+
file pathToDb from params.pathToDb{{ param_id }} ?
25+
Channel.fromPath(params.pathToDb{{ param_id }}) : Channel.value("NA")
26+
file fastaToDb from params.fastaToDb{{ param_id }} ?
27+
Channel.fromPath(params.fastaToDb{{ param_id }}) : Channel.value("NA")
28+
val blast from params.blastType{{ param_id }}
29+
30+
output:
31+
file "*.txt" into diamondOutputs
32+
output:
33+
{% with task_name="diamond"%}
34+
{%- include "compiler_channels.txt" ignore missing -%}
35+
{% endwith %}
36+
37+
script:
38+
// Use database when available or otherwise use Fasta file
39+
if (params.pathToDb{{ param_id }})
40+
"""
41+
diamond ${blast} -d ${pathToDb} -q ${assembly} \
42+
-o ${pathToDb}.txt -e 1E-20 -p ${task.cpus} \
43+
-f 6 qseqid sseqid pident length mismatch gapopen qstart qend slen sstart send evalue bitscore
44+
"""
45+
else if (params.fastaToDb{{ param_id }})
46+
"""
47+
diamond makedb --in ${fastaToDb} -d ${fastaToDb}
48+
diamond ${blast} -d ${fastaToDb}.dmnd -q ${assembly} \
49+
-o ${fastaToDb}.txt -e 1E-20 -p ${task.cpus} \
50+
-f 6 qseqid sseqid pident length mismatch gapopen qstart qend slen sstart send evalue bitscore
51+
"""
52+
53+
}

0 commit comments

Comments
 (0)