In NGS (next gen sequencing) data analysis, data alignment results in files in SAM format i.e alignment is stored in sam format (.sam extension). Sam files are store alignment information in 2nd field called bitwise flag. Allowed flags are listed in: https://samtools.github.io/hts-specs/SAMv1.pdf and they are:

 
 These bit wise scores are associated with an aligned read and a read can have any combination of these bitwise flags (for eg 7(1+2+4) or 1 or 1024+2048). Most of the times, user is interested in knowing the alignment information of a read. Some times, you wants to filter reads from SAM file based on one or more flags. Then it is necessary to know what each flag means.  There are several tools online to decrypt bitwise flag information. In R, SAMseq allows such operations very easy. Following is the example code for such operation.

Load library:
> library(SamSeq)
  • Decode flag 228:
> samFlags(228)[samFlags(228)==1]
     SECOND_OF_PAIR       FIRST_OF_PAIR MATE_REVERSE_STRAND       READ_UNMAPPED
               TRUE                TRUE                TRUE                TRUE 
  • Decode flag 2056:
> samFlags(2056)[samFlags(2056)==1]
SUPPLEMENTARY_ALIGNMENT           MATE_UNMAPPED
                   TRUE                    TRUE 
  •  Decode flag 128:
> samFlags(128)[samFlags(128)==1]
SECOND_OF_PAIR
          TRUE
 
Instead of looking for integer, let us say you would like to know what is the flag code for alignment information:
  • code for read that is involved in secondary alignment (not a primary alignment)    
    > samFlags("SUPPLEMENTARY_ALIGNMENT")

    [1] 2048
  • Code for read that is not in primary alignment and unmapped mate
    > samFlags(c("SUPPLEMENTARY_ALIGNMENT","MATE_UNMAPPED"))

    [1] 2056