Fix SAM flags on quality filtered paired-end BAM file
1
0
Entering edit mode
7.0 years ago
le2336 ▴ 70

Hello,

I have a BAM file of paired-end reads that have been quality filtered. I would like to salvage those reads whose mates have been filtered out and continue using them in my analysis (I would also appreciate any input on whether this is acceptable practice). Since some of my downstream tools give me errors if they see only one mate of a paired end read, is there a way to fix the SAM flags (to 0 or 16, for example) so that these reads are treated as single-end reads?

 

Thank you!

SAM flag BAM file paired-end read • 4.3k views
ADD COMMENT
6
Entering edit mode
7.0 years ago
James Ashmore ★ 3.2k

I believe you can use the samtools fixmate command to update the flags, but you need to sort your BAM file by read name first:

samtools -n sort sample.bam sampled.sorted
samtools fixmate sample.sorted.bam sample.fixed.bam
ADD COMMENT
0
Entering edit mode

This works perfectly. Thank you so much!

ADD REPLY
1
Entering edit mode

Just for information, you should be able to use pipes to avoid intermediate files and have a final bam file coordinate sorted and mate fixed:

samtools sort -o -n aln.bam - \
| samtools fixmate -O bam - - \
| samtools sort - aln.sorted.fixed

I would like to salvage those reads whose mates have been filtered out and continue using them in my analysis (I would also appreciate any input on whether this is acceptable practice)

That's what I also do. When I filter for, say, mapping quality I don't mind if one mate fails and the other passes.

ADD REPLY
0
Entering edit mode

This is useful to know. Thank you!

ADD REPLY

Login before adding your answer.

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