-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pyBlast.py
133 lines (107 loc) · 3.82 KB
/
test_pyBlast.py
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
#!/usr/bin/env python3
# Author: Redmar van den Berg
# Copyright: 2017-2018 NVWA
#
# NVWA: Nederlandse Voedsel- en Warenautoriteit
# Netherlands Food and Consumer Product Safety Authority
# https://english.nvwa.nl/
#
# Licence: GPLv3
import unittest
import os
import shutil
import tempfile
import pyBlast
class test_pyblast(unittest.TestCase):
def test_unsupported_ncbi_command(self):
self.verbose = False
from Bio.Blast.Applications import NcbiblastnCommandline
from Bio.Application import ApplicationError
cmd = NcbiblastnCommandline(
query = 'test/query.fasta',
db = 'test/target.fasta',
evalue = 0.001
)
cmd.program_name = 'bla_blast'
self.assertRaises(
ApplicationError,
pyBlast.pyBlast.run_blast,
self, cmd
)
class testPyBlast(unittest.TestCase):
def setUp(self):
from Bio.Blast.Applications import NcbiblastnCommandline
cmd = NcbiblastnCommandline(
query = 'test/sul2_1_AF542061.fasta',
db = 'test/102637-001-018_k64-contigs.fa',
evalue = 0.001
)
with pyBlast.pyBlast(cmd, rm_tmp=False) as pb:
self.sul2_1 = next(pb)
def test_true(self):
self.assertTrue(True)
def test_min_max_two(self):
self.assertEqual(pyBlast._minmax(3,2), (2,3))
def test_min_max_ten_list(self):
numbers = list(range(10))
self.assertEqual(pyBlast._minmax(numbers), (0,9))
def test_min_max_ten(self):
self.assertEqual(pyBlast._minmax(0,1,2,3,4,9), (0,9))
def test_hit_overlap(self):
self.assertFalse(pyBlast._hit_overlap(*self.sul2_1.alignments[0].hsps))
def test_srange_five(self):
self.assertEqual(pyBlast._srange(0,5), set([0,1,2,3,4]))
def test_srange_zero(self):
self.assertEqual(pyBlast._srange(0,0), set())
def test_srange_one(self):
self.assertEqual(pyBlast._srange(0,1), {0})
class test_file_operations(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.target = shutil.copy('test/target.fasta', self.temp_dir)
self.query = shutil.copy('test/query.fasta', self.temp_dir)
self.verbose = False
def tearDown(self):
shutil.rmtree(self.temp_dir)
def test_temp_folder(self):
self.assertTrue(os.path.isdir(self.temp_dir))
def test_files_exist(self):
self.assertTrue(os.path.isfile(self.target))
self.assertTrue(os.path.isfile(self.query))
def test_makeblastdb(self):
blastdb = os.path.join(self.temp_dir,'testdb')
pyBlast.pyBlast.makeblastdb(
self,
target = self.target,
dbtype = 'nucl',
blastdb = blastdb
)
self.assertTrue(os.path.isfile(blastdb + '.nhr'))
self.assertTrue(os.path.isfile(blastdb + '.nin'))
self.assertTrue(os.path.isfile(blastdb + '.nsq'))
def test_unsupported_makeblastdb_command(self):
self.assertRaises(
FileNotFoundError,
pyBlast.pyBlast.makeblastdb,
self, self.target, 'nucl', self.temp_dir, makeblastdb='fakecommand'
)
def test_unsupported_makeblastdb_dbtype(self):
self.assertRaises(
SyntaxError,
pyBlast.pyBlast.makeblastdb,
self, self.target, 'wrong_dbtype', self.temp_dir
)
def test_missing_file_makeblastdb(self):
self.assertRaises(
FileNotFoundError,
pyBlast.pyBlast.makeblastdb,
self,'no_file','nucl', self.temp_dir
)
def test_makeblastdb_target_is_folder(self):
self.assertRaises(
FileNotFoundError,
pyBlast.pyBlast.makeblastdb,
self, self.temp_dir, 'nucl', self.temp_dir
)
if __name__ == '__main__':
unittest.main()