Entering edit mode
2.6 years ago
Hrishikesh
•
0
I have certain bam files which have reads of different size. I wish to create another bam file from it which has reads smaller than a certain length N. I should be able to run samtools stats and idxstats like commands on it. Is there a way to do it?
You can use
samtools view -h myfile.bam | awk 'length($10) > 30 || $1 ~ /^@/' | samtools view -bS - > out.bam
from Ashutosh Pandey answer available here Filtration Of Reads With Length Lower Than 30 From BamWhere 30 is the minimum length
Hey, can range be used in this case? Like if I want it to be 20 < 'length($10) < 30? Or must I perform these actions separately? Much thanks for your previous answer
Sure;
samtools view -h myfile.bam | awk '(length($10) > 20 && length($10) < 30) || $1 ~ /^@/' | samtools view -bS - > out.bam