Skip to content

Commit 94c4dc1

Browse files
cimendescimendes
authored andcommitted
added params to decide if dengue_typing retrieves the sequence of the closest reference
1 parent fe46ddf commit 94c4dc1

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

flowcraft/bin/parse_fasta.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
from itertools import groupby
66
import os
77

8+
9+
def replace_char(text):
10+
for ch in ['/', '`', '*', '{', '}', '[', ']', '(', ')', '#', '+', '-', '.', '!', '$', ':']:
11+
text = text.replace(ch, "_")
12+
return text
13+
814
def getSequence(ref, fasta):
915

1016
entry = (x[1] for x in groupby(fasta, lambda line: line[0] == ">"))
@@ -15,8 +21,9 @@ def getSequence(ref, fasta):
1521

1622
if ref == headerStr.replace('>',''):
1723
filename = os.path.join(os.getcwd(), ref.replace('/','_').split('|')[0])
18-
output_file = open(filename + '.fa', "w+")
19-
output_file.write(">" + headerStr + "\\n" + seq + "\\n")
24+
fasta_header = replace_char(headerStr)
25+
output_file = open(filename + '.fa', "w")
26+
output_file.write(">" + fasta_header + "\n" + seq.upper() + "\n")
2027
output_file.close()
2128

2229
def main():

flowcraft/generator/components/typing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def __init__(self, **kwargs):
130130

131131
self.link_start = None
132132

133+
self.params = {
134+
"reference": {
135+
"default": "false",
136+
"description":
137+
"Retrieves the sequence of the closest reference."
138+
}
139+
}
140+
133141
self.directives = {"dengue_typing": {
134142
"cpus": 4,
135143
"memory": "'4GB'",

flowcraft/generator/templates/dengue_typing.nf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
getRef = params.reference ? "true" : "false"
3+
getRef_{{ pid }} = Channel.value(getRef)
4+
15
process dengue_typing_{{ pid }} {
26

37
// Send POST request to platform
@@ -9,10 +13,11 @@ process dengue_typing_{{ pid }} {
913

1014
input:
1115
set sample_id, file(assembly) from {{ input_channel }}
16+
val ref from getRef_{{ pid }}
1217

1318
output:
1419
file "seq_typing*"
15-
file "*.fa"
20+
file "*.fa" into _ref_seqTyping, optional True
1621
{% with task_name="dengue_typing" %}
1722
{%- include "compiler_channels.txt" ignore missing -%}
1823
{% endwith %}
@@ -27,8 +32,12 @@ process dengue_typing_{{ pid }} {
2732
2833
seq_typing.py assembly --org Dengue Virus -f ${assembly} -o ./ -j $task.cpus -t nucl
2934
30-
awk 'NR == 2 { print \$4 }' seq_typing.report_types.tab > reference
31-
parse_fasta.py -t \$(cat reference) -f /NGStools/seq_typing/reference_sequences/dengue_virus/1_GenotypesDENV_14-05-18.fasta
35+
36+
if [ $ref = "cool" ]
37+
then
38+
awk 'NR == 2 { print \$4 }' seq_typing.report_types.tab > reference
39+
parse_fasta.py -t \$(cat reference) -f /NGStools/seq_typing/reference_sequences/dengue_virus/1_GenotypesDENV_14-05-18.fasta
40+
fi
3241
3342
# Add information to dotfiles
3443
json_str="{'tableRow':[{'sample':'${sample_id}','data':[{'header':'seqtyping','value':'\$(cat seq_typing.report.txt)','table':'typing'}]}],'metadata':[{'sample':'${sample_id}','treeData':'\$(cat seq_typing.report.txt)','column':'typing'}]}"

flowcraft/generator/templates/mafft.nf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ process mafft_{{ pid }} {
88

99
input:
1010
file(assembly) from {{ input_channel }}.map{ it[1] }.collect()
11+
file(refs) from _ref_seqTyping.collect().unique()
1112

1213
output:
1314
file ("*.align") into {{ output_channel }}
@@ -18,7 +19,9 @@ process mafft_{{ pid }} {
1819
script:
1920
"""
2021
21-
cat ${assembly} > all_assemblies.fasta
22+
23+
24+
cat ${assembly} ${refs} > all_assemblies.fasta
2225
2326
mafft --adjustdirection --thread $task.cpus --auto all_assemblies.fasta > ${workflow.scriptName}.align
2427
"""

0 commit comments

Comments
 (0)