Answers.Body: <p>There's no simple way to do that with awk, since you would need to parse the CIGAR string and iterate over the operations. In python using pysam you would iterate over the reads and filter as follows:</p>
  <pre><code>keep = False
  for OP, LEN in b.cigartuples:
      if OP == 2 and LEN &gt; 20:
          keep = True
          break
  
  if keep:
      ...do stuff...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-14T10:58:11.970Z
Answers.LastActivityDate: 2021-01-14T21:20:59.850Z
Answers.LastEditDate: 2021-01-14T21:20:59.850Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I'm trying to modify this <a href="https://www.biostars.org/p/253774/" rel="nofollow noreferrer">https://www.biostars.org/p/253774/</a></p>
  <p>To get reads with deletions &gt; 20bp</p>
  <p>I think this gives reads with exactly 20bp dels:</p>
  <pre><code>samtools view -h in.bam chr1:12340-200000 \ | awk '<span class="math-container">$1 ~ "^@" || $</span>6 ! &quot;20D&quot;' \ | samtools view -b - &gt; out.bam
  </code></pre>
  <p>is it possibe to do &gt;?</p>
  <p>Thanks!</p>
  
Tags: <sam><samtools><reads><awk><indel>
Title: How to extract reads with INDELs > a given size?
ThreadText: # How to extract reads with INDELs > a given size?
  
  (Asked by: username_0 on 2021-01-14)
  
  I'm trying to modify this <https://www.biostars.org/p/253774/>
  
  To get reads with deletions > 20bp
  
  I think this gives reads with exactly 20bp dels:
  
  ```
  samtools view -h in.bam chr1:12340-200000 \ | awk '$1 ~ "^@" || $6 ! "20D"' \ | samtools view -b - > out.bam
  
  ```
  
  is it possibe to do >?
  
  Thanks!
  
  **Tags:** sam, samtools, reads, awk, indel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-14. Score: 2
  
  There's no simple way to do that with awk, since you would need to parse the CIGAR string and iterate over the operations. In python using pysam you would iterate over the reads and filter as follows:
  
  ```
  keep = False
  for OP, LEN in b.cigartuples:
      if OP == 2 and LEN > 20:
          keep = True
          break
  
  if keep:
      ...do stuff...
  
  ```
  
  
  ---
  
  