From feb11255e3609ee143dfad4aca31adea9eaf228e Mon Sep 17 00:00:00 2001 From: rickymagner <81349869+rickymagner@users.noreply.github.com> Date: Thu, 29 Jun 2023 10:43:45 -0400 Subject: [PATCH 1/2] Updated handling of INFO/END when writing records in VCF --- pysam/libcbcf.pyx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pysam/libcbcf.pyx b/pysam/libcbcf.pyx index 8ecfe5f3..7e31305b 100644 --- a/pysam/libcbcf.pyx +++ b/pysam/libcbcf.pyx @@ -1188,9 +1188,9 @@ cdef inline bcf_sync_end(VariantRecord record): else: ref_len = 0 - # Delete INFO/END if no alleles are present or if rlen is equal to len(ref) + # Delete INFO/END if no alleles are present or if not present in header # Always keep END for symbolic alleles - if not has_symbolic_allele(record) and (not record.ptr.n_allele or record.ptr.rlen == ref_len): + if not has_symbolic_allele(record) and (not record.ptr.n_allele) or end_id < 0: # 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') @@ -1198,12 +1198,8 @@ cdef inline bcf_sync_end(VariantRecord record): if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: raise ValueError('Unable to delete END') else: - # Create END header, if not present - if end_id < 0: - record.header.info.add('END', number=1, type='Integer', description='Stop position of the interval') - # Update to reflect stop position - bcf_info_set_value(record, b'END', record.ptr.pos + record.ptr.rlen) + bcf_info_set_value(record, b'END', record.stop) cdef inline int has_symbolic_allele(VariantRecord record): From c034a392d02561200207751d91ac730159583a39 Mon Sep 17 00:00:00 2001 From: rickymagner <81349869+rickymagner@users.noreply.github.com> Date: Thu, 29 Jun 2023 11:01:20 -0400 Subject: [PATCH 2/2] Revert computing END value to previous for consistency with setters --- pysam/libcbcf.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysam/libcbcf.pyx b/pysam/libcbcf.pyx index 7e31305b..2cd28fcd 100644 --- a/pysam/libcbcf.pyx +++ b/pysam/libcbcf.pyx @@ -1199,7 +1199,7 @@ cdef inline bcf_sync_end(VariantRecord record): raise ValueError('Unable to delete END') else: # Update to reflect stop position - bcf_info_set_value(record, b'END', record.stop) + bcf_info_set_value(record, b'END', record.ptr.pos + record.ptr.rlen) cdef inline int has_symbolic_allele(VariantRecord record):