This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Possible To Convert Bam To Bam?

Is it possible to convert bam to bam? I have bam produced by default BWA; but I may also need bam filtered by tossing out those with mapping quality< 20. We can convert sam to bam with a quality cut-off as 20, but storage of sam file is painful (simply too large). So just wondering if I can convert default bam to quality-control bam, so that I only need to store bam file in my system.

thx

bwa bam samtools

3 answers

samtools view -b -q 20 in.bam > out.bam

This will filter any alignments with a mapping quality < 20 from in.bam to out.bam

You can do this with [?]samtools[?]:

Samtools view has these options:

-b        Output in the BAM format.
-q INT    Skip alignments with MAPQ smaller than INT [0]

samtools view -q 20 -b inputbam > outputq20.bam

Log in to answer this question.