How to generate a bam file with reads of only a certain length?
1
0
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?

samtools • 921 views
ADD COMMENT
1
Entering edit mode

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 Bam

Where 30 is the minimum length

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

Sure;
samtools view -h myfile.bam | awk '(length($10) > 20 && length($10) < 30) || $1 ~ /^@/' | samtools view -bS - > out.bam

ADD REPLY
1
Entering edit mode
2.6 years ago
samtools view -e 'length(seq)<100'  -O BAM -o out.bam in.bam
ADD COMMENT

Login before adding your answer.

Traffic: 1792 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