Raise exception in get_tid() if header could not be parsed
HTSlib 1.10's header API added a new error code to bam_name2id()
indicating invalid headers. Distinguish this from no-such-reference
by raising an exception in this rare case. Fixes
@@ -522,7 +522,10 @@ cdef class AlignmentHeader(object):
returns -1 if reference is not known.
"""
reference = force_bytes(reference)
- return bam_name2id(self.ptr, reference)
+ tid = bam_name2id(self.ptr, reference)
+ if tid < -1:
+ raise ValueError('could not parse header')
+ return tid
def __str__(self):
'''string with the full contents of the :term:`sam file` header as a
