Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 2 changed files with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. +5 1 Bio/AlignIO/MafIO.py
  2. +8 0 Tests/test_MafIO_index.py
6 Bio/AlignIO/MafIO.py
@@ -373,7 +373,11 @@ def search(self, starts, ends):
373 373 hits = {}
374 374
375 375 for exonstart, exonend in zip(starts, ends):
376   - possible_bins = ", ".join(map(str, self._region2bin(exonstart, exonend)))
  376 + try:
  377 + possible_bins = ", ".join(map(str, self._region2bin(exonstart, exonend)))
  378 + except TypeError:
  379 + raise TypeError("Exon coordinates must be integers "
  380 + "(start=%s, end=%s)" % (exonstart, exonend))
377 381
378 382 result = con.execute("SELECT * FROM offset_data WHERE bin IN (%s) "
379 383 "AND (end BETWEEN %s AND %s OR %s BETWEEN start AND end) "
8 Tests/test_MafIO_index.py
@@ -261,6 +261,14 @@ def setUp(self):
261 261 self.idx = MafIndex("MAF/ucsc_mm9_chr10.mafindex", "MAF/ucsc_mm9_chr10.maf", "mm9.chr10")
262 262 self.assertEqual(len(self.idx), 48)
263 263
  264 + def test_invalid_type_1(self):
  265 + search = self.idx.search((500, 1000), ("string", 1500))
  266 + self.assertRaises(TypeError, search.next)
  267 +
  268 + def test_invalid_type_2(self):
  269 + search = self.idx.search((500, 1000), (750, 1500.25))
  270 + self.assertRaises(TypeError, search.next)
  271 +
264 272 def test_invalid_exon_count(self):
265 273 search = self.idx.search((0, 1000, 2000), (500, 1500))
266 274 self.assertRaises(ValueError, search.next)

0 comments on commit af34c03

Please sign in to comment.
Something went wrong with that request. Please try again.