Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
4cbd3037
Commit
4cbd3037
authored
12 years ago
by
Gabriel Studer
Browse files
Options
Downloads
Patches
Plain Diff
massively expanded blast unit tests
parent
5f7d6530
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/bindings/tests/test_blast.py
+39
-6
39 additions, 6 deletions
modules/bindings/tests/test_blast.py
with
39 additions
and
6 deletions
modules/bindings/tests/test_blast.py
+
39
−
6
View file @
4cbd3037
...
@@ -2,6 +2,10 @@ import unittest
...
@@ -2,6 +2,10 @@ import unittest
from
ost
import
*
from
ost
import
*
from
ost
import
settings
from
ost
import
settings
from
ost.bindings
import
blast
from
ost.bindings
import
blast
import
re
import
tempfile
import
os
import
shutil
class
TestBlastBindings
(
unittest
.
TestCase
):
class
TestBlastBindings
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -9,8 +13,6 @@ class TestBlastBindings(unittest.TestCase):
...
@@ -9,8 +13,6 @@ class TestBlastBindings(unittest.TestCase):
'
DFSLSVKFGNDVQHFKVLRDGAGKYFLWVVKFNSLNELV
'
+
'
DFSLSVKFGNDVQHFKVLRDGAGKYFLWVVKFNSLNELV
'
+
'
DYHRSTSVSRNQQIFLRDIEQVP
'
)
'
DYHRSTSVSRNQQIFLRDIEQVP
'
)
def
testAllowedMatricesAndPenalties
(
self
):
def
testAllowedMatricesAndPenalties
(
self
):
self
.
assertRaises
(
blast
.
BlastError
,
blast
.
Blast
,
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM45
'
)
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM45
'
,
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM45
'
,
gap_open
=
13
,
gap_ext
=
3
)
gap_open
=
13
,
gap_ext
=
3
)
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM80
'
)
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM80
'
)
...
@@ -20,12 +22,17 @@ class TestBlastBindings(unittest.TestCase):
...
@@ -20,12 +22,17 @@ class TestBlastBindings(unittest.TestCase):
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM62
'
)
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
BLOSUM62
'
)
self
.
assertRaises
(
ValueError
,
blast
.
Blast
,
self
.
query
,
'
testfiles/seqdb
'
,
self
.
assertRaises
(
ValueError
,
blast
.
Blast
,
self
.
query
,
'
testfiles/seqdb
'
,
matrix
=
'
MUAHA
'
)
matrix
=
'
MUAHA
'
)
self
.
assertRaises
(
RuntimeError
,
blast
.
Blast
,
self
.
query
,
'
testfiles/seqdb
'
,
blast_location
=
'
/I/do/not/exist
'
)
def
testMissingDB
(
self
):
def
testMissingDB
(
self
):
self
.
assertRaises
(
IOError
,
blast
.
Blast
,
self
.
query
,
self
.
assertRaises
(
IOError
,
blast
.
Blast
,
self
.
query
,
'
testfiles/nonexistentdb
'
)
'
testfiles/nonexistentdb
'
)
def
testBlastOutput
(
self
):
def
testBlastExec
(
self
):
hits
=
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
)
hits
=
blast
.
Blast
(
self
.
query
,
'
testfiles/seqdb
'
)
expected_hits
=
[
'
1griA
'
,
'
1fhsA
'
,
'
3n84E
'
,
'
1mw9X
'
]
expected_hits
=
[
'
1griA
'
,
'
1fhsA
'
,
'
3n84E
'
,
'
1mw9X
'
]
self
.
assertEqual
(
len
(
hits
),
4
)
self
.
assertEqual
(
len
(
hits
),
4
)
...
@@ -41,13 +48,15 @@ class TestBlastBindings(unittest.TestCase):
...
@@ -41,13 +48,15 @@ class TestBlastBindings(unittest.TestCase):
self
.
assertEqual
(
found
,
4
)
self
.
assertEqual
(
found
,
4
)
def
testBlastParseOutput
(
self
):
def
testBlastParseOutput
(
self
):
raw_out
=
open
(
'
testfiles/raw_blastout.txt
'
,
'
r
'
).
readlines
()
raw_out
=
open
(
'
testfiles/raw_blastout.txt
'
,
'
r
'
).
read
()
parsed_out
=
blast
.
ParseBlastOutput
(
raw_out
)
parsed_out
=
blast
.
ParseBlastOutput
(
raw_out
)
expected_ids
=
[
'
1griA
'
,
'
1fhsA
'
,
'
3n84E
'
,
'
1mw9X
'
]
expected_ids
=
[
'
1griA
'
,
'
1fhsA
'
,
'
3n84E
'
,
'
1mw9X
'
]
expected_evalues
=
[
4.80893e-59
,
4.80893e-59
,
9.06925e-58
,
2.96523
]
expected_evalues
=
[
4.80893e-59
,
4.80893e-59
,
9.06925e-58
,
2.96523
]
expected_scores
=
[
534
,
534
,
523
,
27
]
expected_scores
=
[
534
,
534
,
523
,
27
]
expected_bitscores
[
210.305
,
210.305
,
206.068
,
15.0086
]
expected_bitscores
=
[
210.305
,
210.305
,
206.068
,
15.0086
]
expected_seqid
=
[
1.0
,
1.0
,
1.0
,
0.30769
]
expected_seqid
=
[
1.0
,
1.0
,
1.0
,
0.30769
]
for
i
in
range
(
4
):
for
i
in
range
(
4
):
...
@@ -58,8 +67,32 @@ class TestBlastBindings(unittest.TestCase):
...
@@ -58,8 +67,32 @@ class TestBlastBindings(unittest.TestCase):
self
.
assertAlmostEqual
(
patch
.
bit_score
,
expected_bitscores
[
i
])
self
.
assertAlmostEqual
(
patch
.
bit_score
,
expected_bitscores
[
i
])
self
.
assertAlmostEqual
(
patch
.
seqid
,
expected_seqid
[
i
],
places
=
5
)
self
.
assertAlmostEqual
(
patch
.
seqid
,
expected_seqid
[
i
],
places
=
5
)
def
testBlastVersion
(
self
):
self
.
assertRaises
(
RuntimeError
,
blast
.
Blast
,
self
.
query
,
'
testfiles/seqdb
'
,
blast_location
=
'
/I/do/not/exist
'
)
version
=
blast
.
BlastVersion
()
self
.
assertIsInstance
(
version
,
str
)
re_v
=
re
.
compile
(
'
\d+\.\d+\.\d+
'
)
match
=
False
if
re_v
.
match
(
version
):
match
=
True
self
.
assertEqual
(
match
,
True
)
def
testBuildDatabase
(
self
):
tmp_dir_name
=
tempfile
.
mkdtemp
()
db_name
=
os
.
path
.
join
(
tmp_dir_name
,
'
testdb
'
)
blast
.
CreateDB
(
'
testfiles/multiple.fasta
'
,
db_name
)
self
.
assertRaises
(
IOError
,
blast
.
CreateDB
,
'
testfiles/multiple.fasta
'
,
db_name
,
mkdb_cmd
=
'
I/am/not/a/damn/executable
'
)
test_seq
=
seq
.
CreateSequence
(
'
B
'
,
'
ALRLVKDGFAVAIADYNDATATAVAAEINQAGGRAVAIKVDV
'
+
'
SRRDQVFAAVEQARKALGGFNVIVNNAGIAPSTPIESIT
'
)
blastout
=
blast
.
Blast
(
test_seq
,
db_name
)
self
.
assertEqual
(
len
(
blastout
),
28
)
shutil
.
rmtree
(
tmp_dir_name
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# test if blast package is available on system, otherwise ignore tests
# test if blast package is available on system, otherwise ignore tests
try
:
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment