Question: Filtering paired and single end reads from a BAM file
gravatar for James Ashmore
5.7 years ago by
James Ashmore3.0k
UK/Edinburgh/MRC Centre for Regenerative Medicine
James Ashmore3.0k wrote:

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?

samtools bedtools • 2.7k views
ADD COMMENTlink modified 5.7 years ago by Sean Davis26k • written 5.7 years ago by James Ashmore3.0k
gravatar for Sean Davis
5.7 years ago by
Sean Davis26k
National Institutes of Health, Bethesda, MD
Sean Davis26k wrote:

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 COMMENTlink written 5.7 years ago by Sean Davis26k

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 REPLYlink written 5.7 years ago by James Ashmore3.0k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 997 users visited in the last hour