Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle invalid types passed to search()

Without handling, the error raised is pretty obscure. Added a unit test for this case.
  • Loading branch information...
commit af34c033d78c4c72dffbb500e513e568a2ba5e29 1 parent 140bd6b
polyatail authored
Showing with 13 additions and 1 deletion.
  1. +5 −1 Bio/AlignIO/MafIO.py
  2. +8 −0 Tests/test_MafIO_index.py
View
6 Bio/AlignIO/MafIO.py
@@ -373,7 +373,11 @@ def search(self, starts, ends):
hits = {}
for exonstart, exonend in zip(starts, ends):
- possible_bins = ", ".join(map(str, self._region2bin(exonstart, exonend)))
+ try:
+ possible_bins = ", ".join(map(str, self._region2bin(exonstart, exonend)))
+ except TypeError:
+ raise TypeError("Exon coordinates must be integers "
+ "(start=%s, end=%s)" % (exonstart, exonend))
result = con.execute("SELECT * FROM offset_data WHERE bin IN (%s) "
"AND (end BETWEEN %s AND %s OR %s BETWEEN start AND end) "
View
8 Tests/test_MafIO_index.py
@@ -261,6 +261,14 @@ def setUp(self):
self.idx = MafIndex("MAF/ucsc_mm9_chr10.mafindex", "MAF/ucsc_mm9_chr10.maf", "mm9.chr10")
self.assertEqual(len(self.idx), 48)
+ def test_invalid_type_1(self):
+ search = self.idx.search((500, 1000), ("string", 1500))
+ self.assertRaises(TypeError, search.next)
+
+ def test_invalid_type_2(self):
+ search = self.idx.search((500, 1000), (750, 1500.25))
+ self.assertRaises(TypeError, search.next)
+
def test_invalid_exon_count(self):
search = self.idx.search((0, 1000, 2000), (500, 1500))
self.assertRaises(ValueError, search.next)
Please sign in to comment.
Something went wrong with that request. Please try again.