Remove supplementary alignments from a bam file
2
1
Entering edit mode
4.6 years ago
jeni ▴ 90

Hi!

Do you know how can I filter out supplementary alignments from a bam file? I was reviewing http://broadinstitute.github.io/picard/explain-flags.html and I am aware that the flag for this kind of alignments is "2048". However, depending on another features (ex: paired read, second in pair, etc), the flag can vary.

So, I am not sure about how can I filter out this kind of alignments.

alignment • 8.2k views
ADD COMMENT
5
Entering edit mode
4.6 years ago

samtools view -F 2048 -bo filtered.bam original.bam

You don't have to care about what other flags are set, the -F option will filter any entry with bit 2048.

ADD COMMENT
0
Entering edit mode

Hi all, I am very new to all these tools and analysis. I have a bam file and I wanted to eliminate the supplementary alignments but when I use samtools view -b -F 2145 tow.sort.bam > new.bam

The new.bam file is empty. However, if what I do is to select them in a new file:

samtools view -b -f 2145 tow.sort.bam > filtered.bam

The filtered.bam file contains the supplementary aligments I saw in flagstat.

Anyone can tell me why the first command is not working as I expect?

Thanks!

ADD REPLY
0
Entering edit mode

-F 2145 will remove all paired-end reads. You want -F 2048.

ADD REPLY
3
Entering edit mode
4.6 years ago

the SAM flag is a bit array https://en.wikipedia.org/wiki/Bit_array . Filtering with samtools view -F or samtools view -f uses Bit Wise operations https://en.wikipedia.org/wiki/Bitwise_operation so the other bits don't have any consequence on the filtering.

ADD COMMENT
2
Entering edit mode

Beat you by 3 minutes :)

ADD REPLY

Login before adding your answer.

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