Skip to content

Commit 3d6b664

Browse files
committed
added the remaining tests to plasmid components
1 parent e9f0d71 commit 3d6b664

File tree

5 files changed

+139
-3
lines changed

5 files changed

+139
-3
lines changed

flowcraft/templates/mashscreen2json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def main(mash_output, sample_id):
9999
# estimated copy number
100100
copy_number = int(float(v[1]) / median_cutoff)
101101
# assure that plasmid as at least twice the median coverage depth
102-
if float(v[1]) > median_cutoff:
102+
if float(v[1]) >= median_cutoff:
103103
filtered_dic["_".join(k.split("_")[0:3])] = [
104104
round(float(v[0]),2),
105105
copy_number

flowcraft/tests/template_tests/test_mapping2json.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import json
23
import flowcraft.templates.mapping2json as mapping2json
34

45
depth_dict_coverage = {
@@ -96,3 +97,48 @@ def test_generate_file(tmpdir):
9697
assert not assert_message, "errors occurred:\n{}".format(
9798
"\n".join(assert_message)
9899
)
100+
101+
102+
def test_generated_dict(tmpdir):
103+
"""
104+
This function tests if the files generated by this template script are
105+
created
106+
"""
107+
108+
# create a temporary file depth txt file
109+
depth_file = tmpdir.join("test_depth_file.txt")
110+
depth_file.write("ACC1\t1\t30")
111+
112+
# creates a temporary file with the json_dict
113+
json_dict = tmpdir.join("test_json_dict.json")
114+
json_dict.write('{"ACC1": 2000}')
115+
116+
expected_dict = {"ACC1": 0.0}
117+
118+
# executes the function to be tested
119+
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
120+
121+
result_dict = json.load(open("{}_mapping.json".format(str(depth_file))))
122+
123+
assert_message = []
124+
125+
# checks if result_dict is indeed a dictionary
126+
if not isinstance(result_dict, dict):
127+
assert_message.append("Contents of the generated file must be a "
128+
"dictionary.")
129+
130+
if not result_dict == expected_dict:
131+
assert_message.append("The expected dictionary must be equal to the "
132+
"one present in the generated file.\n"
133+
"Expected: {}\n"
134+
"Result: {}". format(
135+
json.dumps(expected_dict),
136+
json.dumps(result_dict)
137+
))
138+
139+
# remove the .report.json file
140+
os.remove(".report.json")
141+
142+
assert not assert_message, "Errors occurred:\n{}".format(
143+
"\n".join(assert_message)
144+
)

flowcraft/tests/template_tests/test_mashdist2json.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import json
23
import flowcraft.templates.mashdist2json as mashdist2json
34

45

@@ -10,7 +11,7 @@ def test_generate_file(tmpdir):
1011

1112
# create a temporary file mash screen txt file
1213
mash_file = tmpdir.join("test_depth_file.txt")
13-
mash_file.write("NC_ACC_1_seq\tseq1\t100\t900/1000")
14+
mash_file.write("ACC1\tseq1\t0\t900/1000")
1415

1516
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
1617

@@ -28,3 +29,45 @@ def test_generate_file(tmpdir):
2829
assert not assert_message, "errors occurred:\n{}".format(
2930
"\n".join(assert_message)
3031
)
32+
33+
34+
def test_generated_dict(tmpdir):
35+
"""
36+
This function tests if the files generated by this template script are
37+
created
38+
"""
39+
40+
# create a temporary file mash screen txt file
41+
mash_file = tmpdir.join("test_depth_file.txt")
42+
mash_file.write("ACC1\tseq1\t0\t900/1000")
43+
44+
# the expected result from loading the dictionary in the generated file
45+
expected_dict = {"ACC1": [1.0, 0.9, "seq1"]}
46+
47+
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
48+
49+
result_dict = json.load(open("{}.json".format(
50+
str(mash_file).split(".")[0])))
51+
52+
assert_message = []
53+
54+
# checks if result_dict is indeed a dictionary
55+
if not isinstance(result_dict, dict):
56+
assert_message.append("Contents of the generated file must be a "
57+
"dictionary.")
58+
59+
if not result_dict == expected_dict:
60+
assert_message.append("The expected dictionary must be equal to the "
61+
"one present in the generated file.\n"
62+
"Expected: {}\n"
63+
"Result: {}". format(
64+
json.dumps(expected_dict),
65+
json.dumps(result_dict)
66+
))
67+
68+
# remove the .report.json file
69+
os.remove(".report.json")
70+
71+
assert not assert_message, "Errors occurred:\n{}".format(
72+
"\n".join(assert_message)
73+
)

flowcraft/tests/template_tests/test_mashscreen2json.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import json
23
import flowcraft.templates.mashscreen2json as mashscreen2json
34

45

@@ -28,3 +29,46 @@ def test_generate_file(tmpdir):
2829
assert not assert_message, "errors occurred:\n{}".format(
2930
"\n".join(assert_message)
3031
)
32+
33+
34+
def test_generated_dict(tmpdir):
35+
"""
36+
This function tests if the files generated by this template script are
37+
created
38+
"""
39+
40+
# create a temporary file mash screen txt file
41+
mash_file = tmpdir.join("test_depth_file.txt")
42+
mash_file.write("100\tNA\t30\tNA\tACC1")
43+
44+
# the expected result from loading the dictionary in the generated file
45+
expected_dict = {"ACC1": [100.0, 1]}
46+
47+
mashscreen2json.main(str(mash_file), "test")
48+
49+
result_dict = json.load(open("{}.json".format(
50+
str(mash_file).split(".")[0])))
51+
52+
assert_message = []
53+
54+
# checks if result_dict is indeed a dictionary
55+
if not isinstance(result_dict, dict):
56+
assert_message.append("Contents of the generated file must be a "
57+
"dictionary.")
58+
59+
if not result_dict == expected_dict:
60+
assert_message.append("The expected dictionary must be equal to the "
61+
"one present in the generated file.\n"
62+
"Expected: {}\n"
63+
"Result: {}". format(
64+
json.dumps(expected_dict),
65+
json.dumps(result_dict)
66+
))
67+
68+
# remove the .report.json file
69+
os.remove(".report.json")
70+
71+
assert not assert_message, "Errors occurred:\n{}".format(
72+
"\n".join(assert_message)
73+
)
74+

flowcraft/tests/template_tests/test_pATLAS_consensus_json.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
import json
43
import flowcraft.templates.pATLAS_consensus_json as pATLAS_consensus_json
54

@@ -103,6 +102,10 @@ def test_generated_dict(tmpdir):
103102
[str(x + 1) for x, el in enumerate(list_of_checks) if not el]
104103
)))
105104

105+
# remove the .report.json file
106+
os.remove(".report.json")
107+
os.remove("consensus_file.json")
108+
106109
assert not assert_message, "Errors occurred:\n{}".format(
107110
"\n".join(assert_message)
108111
)

0 commit comments

Comments
 (0)