How To Interpret The Flag Field In The Sam Specification
5
1
Entering edit mode
11.6 years ago

Hi all ,

I created a sam file and converted it to bam file using samtools.

One of the record in bam file is :

HWI-ST1162:72:D0PMMACXX:5:1104:10496:88597      16      gi|355477192|ref|NC_007299.5|   1       255     101M    *       0       0       TACCCCACTCACACTTATGGATAGATCAACTAAACAGAAAATTAACAAGGAAAAAAAAAACAAAAAAAACATGTATCTATAAAGCTCACTAAAGGAAAGCA        05DDDDCDDCDDDDDDDDDDDCDCCADDDCDDDEDDEDEEEEDDDDDDDDDDHJJJJJJIJJJJJJJJIIJJJJJIJGJJJJJJIIHGHHHHHFFFFFCCC        XA:i:1  MD:Z:60A33C6    RG:Z:D0PMMACXX:IT27.48-3        NM:i:2

What does the second field means? What may be the possible values for second field of a bam file. In one paper I read it as a flag. But I could not find the explanation for value 0 and 16 .

Thanks, Deeps

bam • 31k views
ADD COMMENT
0
Entering edit mode

Answer is fine but it is not working so sorry

ADD REPLY
0
Entering edit mode

What answer isn't working? Istvan's link to the "Explain SAM Flags" still works, as does that site.

ADD REPLY
16
Entering edit mode
11.6 years ago

In a nutshell any integer number may be entered although some of these number may have contradictory or overlapping effects.

The best way to visualize the flag fields is via Explain SAM Flags web interface.

To also answer your question each flag corresponds to a bit set in a binary representation of the number

1 -> 00001
2 -> 00010
4 -> 00100
8 -> 01000

Then if you need to set flags 1 and 4 then the bits that will be set are 00101 and the integer flag would be 5

ADD COMMENT
0
Entering edit mode

great tool the "Explain SAM Flags"!, I expended A LOT of time understanding the combinations

ADD REPLY
4
Entering edit mode
10.5 years ago

I think some of the confusion happens because we call them binary flags, but they are displayed in decimal in the .sam file, but when they are explained in the SAM specification document, they are displayed in hexadecimal.

ADD COMMENT
4
Entering edit mode
8.6 years ago
-_- ★ 1.1k

For even faster and more handy interpretation of the flag, try http://www.samformat.info/#/flag

ADD COMMENT
0
Entering edit mode

this is neat but IMO it should work both ways, selecting rows should produce numbers.

building a number out of the desired flags is just as often needed

ADD REPLY
0
Entering edit mode

Agreed, added that feature, too and improved the binary illustration.

ADD REPLY
0
Entering edit mode

nice, I'll add this to my lecture notes ;-)

ADD REPLY
3
Entering edit mode
11.6 years ago

I wrote a blog post about this a while back: http://blog.nextgenetics.net/?e=18

It might be more detail than you need to know about how bitwise flags work.

ADD COMMENT
0
Entering edit mode

excellent summary - your blog was not listed in the planet feed - problem rectified!

ADD REPLY
2
Entering edit mode
11.6 years ago
JC 13k

In short: 0 is a single-end read mapped in the forward strand, 16 is in the reverse strand. Check all the details about the bitwise flag in the samtools manual: http://samtools.sourceforge.net/samtools.shtml and SAM format description: http://samtools.sourceforge.net/SAM1.pdf

ADD COMMENT

Login before adding your answer.

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