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

CC BY-SA 4.0
2021-06-29T20:52:04.487Z
Thank you! This worked
annabelperry
CC BY-SA 4.0
2021-06-29T19:58:18.587Z
2021-06-29T19:58:18.587Z
Devon Ryan
<p>I am using the &quot;htslib/sam.h&quot; 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?</p>

<sam><c++><htslib>
How do I access sequence and MAPQ from bam using HTSlib in C++?
# How do I access sequence and MAPQ from bam using HTSlib in C++?

(Asked by: username_0 on 2021-06-29)

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?

**Tags:** sam, c++, htslib

---

## 1 answers

### Answer by username_1 on 2021-06-29. Score: 4 | Accepted answer

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`).

> **Comments:**
> **username_0**: Thank you! This worked  

---

