Creates an extraction file (keeping only markers on autosomes).

    :param bim_filename: the name of the BIM file.
    :param out_prefix: the prefix for the output file.

    :type bim_filename: str
    :type out_prefix: str

def create_extraction_file(bim_filename, out_prefix):
    """Creates an extraction file (keeping only markers on autosomes).

    :param bim_filename: the name of the BIM file.
    :param out_prefix: the prefix for the output file.

    :type bim_filename: str
    :type out_prefix: str

    """
    o_file = None
    try:
        o_file = open(out_prefix + ".to_extract", "w")
    except IOError:
        raise ProgramError("{}: cannot write file".format(
            out_prefix + ".to_extract"
        ))

    # Reading the BIM file and extracts only the markers on autosome
    autosomes = set(map(str, range(1, 23)))
    nb_markers = 0
    header = dict(zip(["chrom", "name", "cm", "pos", "a1", "a2"], range(6)))
    with open(bim_filename, "r") as i_file:
        for line in i_file:
            row = line.rstrip("\r\n").split()
            if row[header["chrom"]] in autosomes:
                print >>o_file, row[header["name"]]
                nb_markers += 1

    # Closing the file
    o_file.close()

    logger.info("  - {:,d} markers will be used for contamination "
                "estimation".format(nb_markers))