Question: Fix SAM flags on quality filtered paired-end BAM file
0
gravatar for le2336
2.2 years ago by
le233660
United States
le233660 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 2.2 years ago by James Ashmore2.0k • written 2.2 years ago by le233660
5
gravatar for James Ashmore
2.2 years ago by
James Ashmore2.0k
UK/Edinburgh/MRC Centre for Regenerative Medicine
James Ashmore2.0k 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 written 2.2 years ago by James Ashmore2.0k

This works perfectly. Thank you so much!

ADD REPLYlink written 2.2 years ago by le233660
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 2.2 years ago by dariober8.0k

This is useful to know. Thank you!

ADD REPLYlink written 2.2 years ago by le233660
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: 820 users visited in the last hour