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.
The two key functions are:
Now when I navigate to the header file for SAM/BAM functions:
The only "append" function is
bam_aux_append. But that's for optional fields.
- Given a
bam_hdr_theader (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?