From 90d43799b013a4528dde3eff2c4ecec6d6a75122 Mon Sep 17 00:00:00 2001 From: Kevin Chau Date: Mon, 26 Feb 2024 15:21:47 -0800 Subject: [PATCH] Automatically translate VariantRecord on write --- pysam/libcbcf.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pysam/libcbcf.pyx b/pysam/libcbcf.pyx index 8ecfe5f3..82856268 100644 --- a/pysam/libcbcf.pyx +++ b/pysam/libcbcf.pyx @@ -3033,6 +3033,7 @@ cdef class VariantRecord(object): return makeVariantRecord(self.header, bcf_dup(self.ptr)) def translate(self, VariantHeader dst_header): + """Translate the record to a new header. Number of samples must match.""" if dst_header is None: raise ValueError('dst_header must not be None') @@ -4499,9 +4500,8 @@ cdef class VariantFile(HTSFile): with nogil: bcf_hdr_write(self.htsfile, self.header.ptr) - #if record.header is not self.header: - # record.translate(self.header) - # raise ValueError('Writing records from a different VariantFile is not yet supported') + if record.header is not self.header: + record.translate(self.header) if record.ptr.n_sample != bcf_hdr_nsamples(self.header.ptr): msg = 'Invalid VariantRecord. Number of samples does not match header ({} vs {})'