Question: Filtering paired and single end reads from a BAM file
1
gravatar for James Ashmore
4.5 years ago by
James Ashmore2.7k
UK/Edinburgh/MRC Centre for Regenerative Medicine
James Ashmore2.7k 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.2k views
ADD COMMENTlink modified 4.5 years ago by Sean Davis25k • written 4.5 years ago by James Ashmore2.7k
1
gravatar for Sean Davis
4.5 years ago by
Sean Davis25k
National Institutes of Health, Bethesda, MD
Sean Davis25k 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 4.5 years ago by Sean Davis25k

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 4.5 years ago by James Ashmore2.7k
Please log in to add an answer.

Help
Access

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