Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-06T19:17:11.400Z
Answers.Text: Hi @Pablo could you kindly edit your question inserting this as a suggestion?
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-06T15:25:31.003Z
Answers.LastActivityDate: 2022-06-06T16:08:42.727Z
Answers.LastEditDate: 2022-06-06T16:08:42.727Z
Answers.UserDisplayName: Pablo
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-06T15:00:13.360Z
Answers.LastActivityDate: 2022-06-06T15:00:13.360Z
Answers.UserDisplayName: Timur Shtatland
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-06T10:55:57.170Z
Comments.Text: 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.
Comments.UserDisplayName: Community
Tags: <sam><sambamba>
Title: Filter bam with sambamba
ThreadText: # 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 @username_0 could you kindly edit your question inserting this as a suggestion?  
  
  ---
  
  ### Answer by username_3 on 2022-06-06. Score: 0
  
  You need [`bedtools`](https://bedtools.readthedocs.io/en/latest/index.html), specifically [bedtools intersect](https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html) command, not `sambamba`:
  
  ```
  bedtools intersect -abam A.bam -b B.bed > A_in_N.bam
  
  ```
  
  
  ---
  
  