Converting bam to sam using htslib C++ api
Hi everyone, is it possible to convert between sam and bam file inside C++ code. I knowhtslib library offers implementation of file formats including sam and bam. However, I could not find a documentation describing this conversion.
I know samtools view command can be used for this purpose but I need to deal with this inside C++ code.
• 1,018 views
•
link
1 answer
read https://github.com/samtools/samtools/blob/develop/sam_view.c
- allocate a new bam1_t* b = bam_init1
- open the input file: sam_open_format
- read the header sam_hdr_read
- open the output file: sam_open_format
- write the header: sam_hdr_str
- while you can read a bam1_t : sam_read1
- write the read sam_format1
- dispose header sam_hdr_destroy
- dispose read bam_destroy1
- dispose files: sam_close
• 0 views
•
link
Log in to answer this question.
Extract bam file to sam inside code?
GAM file columns?