I am using the "htslib/sam.h" header in C++. I need to access the SEQ field of bam reads and store each sequence in a vector of strings. I also need to access the MAPQ field of each read to check if the read passes my threshold quality of 10 (which I have stored as an integer). Does anyone know which htslib/sam.h functions can accomplish these tasks?


1 Answer 1


The MAPQ is stored in b->core.qual, given a bam1_t *b. You can access the sequence with bam_seqi(bam_get_seq(b), some_offset)(see https://github.com/samtools/htslib/blob/develop/htslib/sam.h#L317). This will get you a base at a time, so you'd need to iterate over it (the length of the sequence being in b->core.l_qseq).

  • $\begingroup$ Thank you! This worked $\endgroup$ Jun 29, 2021 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.