Improve sanity checking of VariantRecord.rlen
@@ -1159,13 +1159,14 @@ cdef inline bcf_sync_end(VariantRecord record):
cdef bcf_hdr_t *hdr = record.header.ptr
cdef bcf_info_t *info
cdef int end_id = bcf_header_get_info_id(record.header.ptr, b'END')
+ cdef int ref_len = len(record.ref)
# Ensure rlen can't ever become negative
if record.ptr.rlen < 0:
- record.ptr.rlen = 0
+ record.ptr.rlen = ref_len if record.ptr.n_allele else 0
# Delete INFO/END if no alleles are present or if rlen is equal to len(ref)
- if not record.ptr.n_allele or record.ptr.rlen == len(record.ref):
+ if not record.ptr.n_allele or record.ptr.rlen == ref_len:
# If INFO/END is not defined in the header, it doesn't exist in the record
if end_id >= 0:
info = bcf_get_info(hdr, record.ptr, b'END')
