<p>I think it is possible:</p>
<pre><code>sambamba view --regions regions.bed --with-header --format=bam reads.bam  &gt; filtered.bam
</code></pre>

CC BY-SA 4.0
2022-06-06T19:17:11.400Z
Hi @Pablo could you kindly edit your question inserting this as a suggestion?
M__
CC BY-SA 4.0
2022-06-06T15:25:31.003Z
2022-06-06T16:08:42.727Z
2022-06-06T16:08:42.727Z
Pablo
<p>You need <a href="https://bedtools.readthedocs.io/en/latest/index.html" rel="nofollow noreferrer"><code>bedtools</code></a>, specifically <a href="https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html" rel="nofollow noreferrer">bedtools intersect</a> command, not <code>sambamba</code>:</p>
<pre><code>bedtools intersect -abam A.bam -b B.bed &gt; A_in_N.bam
</code></pre>

CC BY-SA 4.0
2022-06-06T15:00:13.360Z
2022-06-06T15:00:13.360Z
Timur Shtatland
<p>I have a very large bam file and I want to filter it to keep only a handfull of positions as defined in a bed file. Can I do this with sambamba or do i need another tool?</p>
<p>Thanks</p>

CC BY-SA 4.0
2022-06-06T10:55:57.170Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
<sam><sambamba>
Filter bam with sambamba
# Filter bam with sambamba

(Asked by: username_0 on 2022-06-06)

I have a very large bam file and I want to filter it to keep only a handfull of positions as defined in a bed file. Can I do this with sambamba or do i need another tool?

Thanks

**Tags:** sam, sambamba
> **Comments:**
> **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  

---

## 2 answers

### Answer by username_0 on 2022-06-06. Score: 1

I think it is possible:
sambamba view --regions regions.bed --with-header --format=bam reads.bam  > filtered.bam

> **Comments:**
> **username_2**: Hi @Pablo could you kindly edit your question inserting this as a suggestion?  

---

### Answer by username_3 on 2022-06-06. Score: 0

You need bedtools, specifically bedtools intersect command, not sambamba:
bedtools intersect -abam A.bam -b B.bed > A_in_N.bam


---

