Converting bam to sam using htslib C++ api
1
1
Entering edit mode
7 weeks ago
Uveyik ▴ 40

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.

bam htslib sam • 281 views
ADD COMMENT
1
Entering edit mode

Don't forget to follow up on your threads. If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they all work. If an answer was not really helpful or did not work, provide detailed feedback so others know not to use that answer.

Upvote|Bookmark|Accept

Extract bam file to sam inside code?

GAM file columns?

ADD REPLY
2
Entering edit mode
7 weeks ago

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
ADD COMMENT

Login before adding your answer.

Traffic: 2477 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6