annotate resfinder/tests/unit_tests.py @ 0:55051a9bc58d draft default tip

Uploaded
author dcouvin
date Mon, 10 Jan 2022 20:06:07 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
1 #!/usr/bin/env python3
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
2 import unittest
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
3 import os
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
4 import subprocess
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
5
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
6
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
7 test_names = ["test1", "test3"]
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
8 test_data = {
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
9 test_names[0]: "data/test_isolate_01.fa", # Test published resistance
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
10 test_names[1]: "data/test_isolate_03.fa", # Test no resistance
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
11 }
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
12 run_test_dir = "unit_tests"
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
13 blast_out_dir = "blast_out"
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
14
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
15 configs = {}
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
16
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
17
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
18 class ResFinderTest(unittest.TestCase):
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
19
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
20 def setUp(self):
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
21 # Change working dir to test dir
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
22 os.chdir(os.path.dirname(os.path.realpath(__file__)))
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
23 # Does not allow running two tests in parallel
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
24 os.makedirs(run_test_dir, exist_ok=False)
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
25 with open("test_config.txt", "r") as fh:
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
26 for line in fh:
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
27 line = line.rstrip()
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
28
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
29 if not(line):
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
30 continue
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
31
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
32 if(line.startswith("#")):
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
33 continue
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
34
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
35 key, path = line.split()
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
36 configs[key] = path
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
37
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
38 def test_run_resfinder(self):
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
39
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
40 test1_dir = run_test_dir + "/" + test_names[0]
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
41 test1_blast_dir = test1_dir + "/" + blast_out_dir
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
42 os.makedirs(test1_dir)
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
43 os.makedirs(test1_blast_dir)
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
44
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
45 cmd = ("python3 ../ResFinder.py"
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
46 + " -i " + test_data[test_names[0]]
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
47 + " -o " + test1_blast_dir
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
48 + " -p " + configs["resfinder_dbs"]
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
49 + " -l 0.6"
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
50 + " -t 0.9")
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
51
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
52 print("Run cmd: " + cmd)
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
53
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
54 process = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE,
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
55 stderr=subprocess.PIPE)
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
56
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
57 outs = process.stdout.decode()
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
58 errs = process.stderr.decode()
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
59
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
60 self.assertNotIn("Error", errs)
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
61
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
62
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
63 if __name__ == "__main__":
55051a9bc58d Uploaded
dcouvin
parents:
diff changeset
64 unittest.main()