How To Interpret The Flag Field In The Sam Specification
5
1
Entering edit mode
11.5 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
0
Entering edit mode

Answer is fine but it is not working so sorry

0
Entering edit mode

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

16
Entering edit mode
11.5 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

0
Entering edit mode

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

4
Entering edit mode
10.3 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.

4
Entering edit mode
8.5 years ago
-_- ★ 1.1k

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

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

0
Entering edit mode

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

0
Entering edit mode

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

3
Entering edit mode
11.5 years ago

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

0
Entering edit mode

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

2
Entering edit mode
11.5 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