Filter Bam : Only Sens Alignment
2
0
Entering edit mode
12.2 years ago

Hi,

How can I filter a bam file to only have reads that are aligning on the sens strand of my reference. I've singe-end reads and I have aligned my reads with bowtie 0.12.7.

Thanks a lot,

EDIT > I found it myself :

sens reads : awk '$2=="0" {print $0}' input.sam > output.sam

anti-sens reads : awk '$2=="16" {print $0}' input.sam > output.sam

N.

bam filter • 3.6k views
ADD COMMENT
5
Entering edit mode
12.2 years ago

Your solution won't work if , for example, the flag " read fails platform/vendor quality checks" is set (see http://picard.sourceforge.net/explain-flags.html )

You'd better use samtools view with (filtering)

samtools view -F 16 your.bam

or (required)

samtools view -f 16 your.bam
ADD COMMENT
0
Entering edit mode

great that's better ! thanks

ADD REPLY
3
Entering edit mode
12.2 years ago

While it's correct that a bitwise flag of 16 (second column in the samfile) would mean reverse strand mapped, it is not the only possible bitwise flag that would indicate reverse strand mapped (5th bit set). For example if your read is mapped on the anti-sense strand and it is also mate paired, then you could have a flag of 17 or 49 depending on what strand your mate is mapped.

To properly check if your mapping is reverse strand, you need to check whether the 5th bit of the flag is set. You can do this by using the bitwise AND operator.

In python:

if flag & 16:
   return 'negative strand'
else:
   return 'positive strand'

The '&' bitwise AND operator also works in perl.

Or you can just use the samtools -f or -F options.

I wrote an explanation of the bitwise flags in a blog post a while back: http://blog.nextgenetics.net/?e=18

ADD COMMENT

Login before adding your answer.

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