How to extract reads with no INDEL?
2
1
Entering edit mode
7.5 years ago
Jeason Rad ▴ 30

Hi, all. I am using samtools view .bam [region] to extract all reads overlapping the region. I find some reads with INDEL and I want to filter them, only getting the reads with no INDEL. Which samtools options I should use?

samtools INDEL SAM • 4.9k views
ADD COMMENT
6
Entering edit mode
7.5 years ago

Isn't it enough to keep reads without I or D operator in the cigar? For this you can use awk like:

samtools view -h in.bam chr1:12340-200000 \
| awk '$1 ~ "^@" || $6 !~ "I|D"' \
| samtools view -b - > out.bam
ADD COMMENT
0
Entering edit mode

Thanks, dariober, it working properly!

ADD REPLY
0
Entering edit mode

please check the green marks on the left to validate+close the question

ADD REPLY
0
Entering edit mode

Hi all. Any way to modify this so it finds read with deletions > 20bp?

samtools view -h in.bam chr1:12340-200000 \
| awk '$1 ~ "^@" || $6 ! "20D"' \
| samtools view -b - > out.bam

Would give reads with exactly 20 bp, right? Is it possible to do > 20bp?

ADD REPLY
0
Entering edit mode

@shimbalama - If you really wanted to you could write an awk script that parses the cigar string and checks for a D operator > 20. But I think it would be easier to write a python script using the pysam package to parse the cigar string or see if Pierre's tools can do it (probably they can). If you get stuck, maybe open a new question for it.

ADD REPLY
0
Entering edit mode

ask as a new question please

ADD REPLY
3
Entering edit mode
7.5 years ago

using samjs http://lindenb.github.io/jvarkit/SamJavascript.html

samtools -bu view your.bam chr1:12340-200000 |\
java -jar dist/samjs.jar -e 'function accept(r) { if(r.getReadUnmappedFlag()) return false; var cigar=r.getCigar();if(cigar==null) return false; for(var i=0;i< cigar.numCigarElements();++i) {if(cigar.getCigarElement(i).getOperator().isIndelOrSkippedRegion()) return false; } return true;} accept(record);'
ADD COMMENT
0
Entering edit mode

Thx for your help, pierre!

ADD REPLY

Login before adding your answer.

Traffic: 2560 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6