Filtering paired and single end reads from a BAM file
1
1
Entering edit mode
9.0 years ago
James Ashmore ★ 3.4k

I have a paired-end BAM file which has gone through numerous filtering steps (MAPQ, MarkDuplicates, Mitochondrial, Unmapped). I would like to extract all properly paired mapped reads and place them in a BEDPE file, and extract all single mapped reads and place them in a BED file. I am sure the numerous filtering steps have created lots of orphans. What would be the correct commands to use to achieve this? I was thinking the following may work:

samtools view -bf 0x2 reads.bam | bedtools bamtobed -bedpe -i stdin > reads.paired.bedpe

samtools view -bf 8 -F 260 reads.bam | bedtools bamtobed -i stdin > reads.single.bed

When I run the first command on the query name sorted BAM file, BEDtools warns me that it could not find reads next to each other with the same name. I'm assuming the filtering steps have removed one of the paired-end reads?

bedtools samtools • 3.6k views
ADD COMMENT
2
Entering edit mode
9.0 years ago

If your BAM file is coordinate-sorted, you will need to name-sort the BAM file before converting to BEDPE. Also, the read flags will be meaningless if you have created orphans post-alignment, so you may need to use samtools fixmate as well.

ADD COMMENT
0
Entering edit mode

I am confused, what exactly does the fixmate command do? What I'm trying to do is extend the reads based on where they have aligned within the genome. I thought I could extract the properly-paired and singles into a BED file and manually extend them. I actually have the unfiltered BAM file produced by Bowtie2, but I am unsure that after extension I would be able to re-apply the filters?

ADD REPLY

Login before adding your answer.

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