This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove some reads from a BAM file

Hi,

I have a paired-end BAM file and I found that some pairs/mates have identical positions on the chromosome, i.e., the numbers in the POS and PNEXT fields are exactly the same. I want to remove these reads.

I also found that some reads present more than 2 times in my BAM file (same QNAME) (I think paired-end reads should have two records/rows in a BAM file). I want to keep the first two records/rows and remove the others.

I used samtools rmdup to remove duplicates.

Any help will be greatly appreciated. Thank you.

next-gen

1 answer

For your first task, picard's Mark Duplicates might do better job than rmdup. For your second task, maybe you have some supplementary alignments? Those would show up as multiple rows. Try removing them with samtools:

samtools view -bh -F 2048 input.bam >output.bam

Also please add which mapper you used, that will be helpful.

Thank you for your help. I used Bowtie2.

Is there any simple way, e.g., a Linux command solution, for these problem? Thanks.

Log in to answer this question.