<p>This is how I do it.</p>
<pre><code>samtools view -@5 -f 0x800 -hb /path/sample.bam &gt; sup.bam
</code></pre>
<p>Then if you want it as a fasta</p>
<pre><code>samtools view -F 0x1 -hb sup.bam | samtools fasta -F 0x1 - &gt; sup.fa
</code></pre>

CC BY-SA 4.0
2021-02-18T05:52:23.110Z
Thanks !! It works great. I will use samtools source code to write a small program to extract the reads based on flag.
SBDK8219
CC BY-SA 4.0
2021-02-18T07:02:18.523Z
Pysam wraps it pretty well, just fyi
Liam McIntyre
CC BY-SA 4.0
2021-02-17T10:45:38.887Z
2021-02-17T10:45:38.887Z
Liam McIntyre
<p>I am trying to extract all chimeric and multi-map reads from either SAM/BAM file. Is there any simple command to do that? Can I use <code>htslib</code> for parsing sam/bam files and extracting based on any flags. Any help on how to start will be appreciated.</p>

<sam><htslib>
extract chimeric and multimap reads from bam file
# extract chimeric and multimap reads from bam file

(Asked by: username_0 on 2021-02-17)

I am trying to extract all chimeric and multi-map reads from either SAM/BAM file. Is there any simple command to do that? Can I use `htslib` for parsing sam/bam files and extracting based on any flags. Any help on how to start will be appreciated.

**Tags:** sam, htslib

---

## 1 answers

### Answer by username_1 on 2021-02-17. Score: 1

This is how I do it.
samtools view -@5 -f 0x800 -hb /path/sample.bam > sup.bam

Then if you want it as a fasta
samtools view -F 0x1 -hb sup.bam | samtools fasta -F 0x1 - > sup.fa

> **Comments:**
> **username_0**: Thanks !! It works great. I will use samtools source code to write a small program to extract the reads based on flag.  
> **username_1**: Pysam wraps it pretty well, just fyi  

---

