This works perfectly. Thank you so much!
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!
1 answer
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
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.
This is useful to know. Thank you!
Log in to answer this question.