I'd like to use C++ to generate a new BAM file programmatically. This is an example how to use htslib to generate a new BCF file on the fly.
https://github.com/samtools/htslib/blob/develop/test/test-bcf-translate.c
The two key functions are:
bcf_hdr_append
bcf_hdr_add_sample
Now when I navigate to the header file for SAM/BAM functions:
https://github.com/samtools/htslib/blob/develop/htslib/sam.h
The only "append" function is bam_aux_append
. But that's for optional fields.
My questions:
- Given a
bam_hdr_t
header (potentially empty), how to add a new chromosome reference? (For example, add a new chrAB to the BAM file) - Given a non-empty
bam_hdr_t *
header, how to remove a chromosome? (For example, remove chr4 from the BAM header)
My sample code:
// Empty BAM header, nothing inside
bam_hdr_t * hdr = bam_hdr_init();
// I'd like to add a new synthetic `chrAB` into the header, how?