How to retain reads on only an certain size in a bam file?

615 views Asked by At

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?

1

There are 1 answers

0
Timur Shtatland On

Use bamutils:

 bamutils filter filename.bam output.bam -maxlen N

From the docs:

Removes reads from a BAM file based on criteria

Given a BAM file, this script will only allow reads that meet filtering
criteria to be written to output. The output is another BAM file with the
reads not matching the criteria removed.
...
Currently, the available filters are:
    -minlen val                Remove reads that are smaller than {val}
    -maxlen val                Remove reads that are larger than {val}

SEE ALSO:

Filtration Of Reads With Length Lower Than 30 From Bam: https://www.biostars.org/p/92889/