Question: Fix SAM flags on quality filtered paired-end BAM file
0
gravatar for le2336
4.5 years ago by
le233670
United States
le233670 wrote:

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!

ADD COMMENTlink modified 4.5 years ago by James Ashmore2.7k • written 4.5 years ago by le233670
6
gravatar for James Ashmore
4.5 years ago by
James Ashmore2.7k
UK/Edinburgh/MRC Centre for Regenerative Medicine
James Ashmore2.7k wrote:

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 COMMENTlink modified 5 weeks ago by RamRS25k • written 4.5 years ago by James Ashmore2.7k

This works perfectly. Thank you so much!

ADD REPLYlink written 4.5 years ago by le233670
1

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 REPLYlink written 4.5 years ago by dariober10k

This is useful to know. Thank you!

ADD REPLYlink written 4.5 years ago by le233670
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: 1060 users visited in the last hour