#!/opt/conda/conda-bld/bamm_1757987134492/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/bin/python
###############################################################################
#
# bamFlags - quick and dirty command line bam file flag interpreter
#
###############################################################################
#                                                                             #
#    This library is free software; you can redistribute it and/or            #
#    modify it under the terms of the GNU Lesser General Public               #
#    License as published by the Free Software Foundation; either             #
#    version 3.0 of the License, or (at your option) any later version.       #
#                                                                             #
#    This library is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        #
#    Lesser General Public License for more details.                          #
#                                                                             #
#    You should have received a copy of the GNU Lesser General Public         #
#    License along with this library.                                         #
#                                                                             #
###############################################################################

__author__ = "Michael Imelfort"
__copyright__ = "Copyright 2014"
__credits__ = ["Michael Imelfort"]
__license__ = "LGPLv3"
__version__ = "1.0.0"
__maintainer__ = "Michael Imelfort"
__email__ = "mike@mikeimelfort.com"
__status__ = "Release"

###############################################################################

import argparse

###############################################################################
###############################################################################
###############################################################################
###############################################################################

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('flags',
                        nargs='+',
                        type=int,
                        help="BAM flags to interpret")

    # parse the arguments
    args = parser.parse_args()

    # do what we came here to do
    properties = ["paired",
                  "proper_pair",
                  "unmapped",
                  "mate_unmapped",
                  "reverse",
                  "mate_reversed",
                  "read1",
                  "read2",
                  "secondary",
                  "qc_fail",
                  "duplicate",
                  "supplementary"]

    for flag in args.flags:
        q_str = ("Query: %d\n" % flag)
        print_str = ""
        for exp in range(12)[::-1]:
            if flag >= 2 ** exp:
                flag -= 2 ** exp
                print_str = "  %s\n" % properties[exp] + print_str

        print q_str + print_str,

###############################################################################
###############################################################################
###############################################################################
###############################################################################
