Originally posted by aurelielaugraud
View Post
If you think of a standard integer as being composed of 32 bits (0 or 1) then it would look like:
00000000000000000000000000000000
However SAM uses this single number as a series of boolean (true false) flags where each position in the array of bits represents a different sequence attribute
Bit 0 = The read was part of a pair during sequencing
Bit 1 = The read is mapped in a pair
Bit 2 = The query sequence is unmapped
Bit 3 = The mate is unmapped
Bit 4 = Strand of query (0=forward 1=reverse)
etc.
Constructing the value from the individual flags is fairly easy. If the flag is false don't add anything to the total. If its true then add 2 raised to the power of the bit position.
For example:
Bit 0 - false - add nothing
Bit 1 - true - add 2**1 = 2
Bit 2 - false - add nothing
Bit 3 - true - add 2**3 = 8
Bit 4 - true - add 2**4 = 16
Bit pattern = 11010 = 16+8+2 = 26
So the flag value would be 26.
To extract the individual flags from the compound value you can use a logical AND operation. This will tell you if a specific bit in the compound value is true or not. The exact syntax will depend on the language you're using, but in Perl for instance you could do:
if ($compound & 16) {
print "Reverse";
}
else {
print "Forward";
}
To extract the information from the 4th (therefore 2**4 = 16) bit field.
I hope that makes it a bit clearer.
Leave a comment: