Runs step11 (flag MAF zero).

    :param in_prefix: the prefix of the input files.
    :param in_type: the type of the input files.
    :param out_prefix: the output prefix.
    :param base_dir: the output directory.
    :param options: the options needed.

    :type in_prefix: str
    :type in_type: str
    :type out_prefix: str
    :type base_dir: str
    :type options: list

    :returns: a tuple containing the prefix of the output files (the input
              prefix for the next script) and the type of the output files
              (``bfile``).

    This function calls the :py:mod:`pyGenClean.FlagMAF.flag_maf_zero` module.
    The required file type for this module is ``bfile``, hence the need to use
    the :py:func:`check_input_files` to check if the file input file type is
    the good one, or to create it if needed.

    .. note::
        The :py:mod:`pyGenClean.FlagMAF.flag_maf_zero` module doesn't return
        usable output files. Hence, this function returns the input file prefix
        and its type.

def run_flag_maf_zero(in_prefix, in_type, out_prefix, base_dir, options):
    """Runs step11 (flag MAF zero).

    :param in_prefix: the prefix of the input files.
    :param in_type: the type of the input files.
    :param out_prefix: the output prefix.
    :param base_dir: the output directory.
    :param options: the options needed.

    :type in_prefix: str
    :type in_type: str
    :type out_prefix: str
    :type base_dir: str
    :type options: list

    :returns: a tuple containing the prefix of the output files (the input
              prefix for the next script) and the type of the output files
              (``bfile``).

    This function calls the :py:mod:`pyGenClean.FlagMAF.flag_maf_zero` module.
    The required file type for this module is ``bfile``, hence the need to use
    the :py:func:`check_input_files` to check if the file input file type is
    the good one, or to create it if needed.

    .. note::
        The :py:mod:`pyGenClean.FlagMAF.flag_maf_zero` module doesn't return
        usable output files. Hence, this function returns the input file prefix
        and its type.

    """
    # Creating the output directory
    os.mkdir(out_prefix)

    # We know we need bfile
    required_type = "bfile"
    check_input_files(in_prefix, in_type, required_type)

    # We need to inject the name of the input file and the name of the output
    # prefix
    script_prefix = os.path.join(out_prefix, "flag_maf_0")
    options += ["--{}".format(required_type), in_prefix,
                "--out", script_prefix]

    # We run the script
    try:
        flag_maf_zero.main(options)
    except flag_maf_zero.ProgramError as e:
        msg = "flag_maf_zero: {}".format(e)
        raise ProgramError(msg)

    # Reading the file to compute the number of flagged markers
    nb_flagged = None
    flagged_fn = script_prefix + ".list"
    with open(flagged_fn, "r") as i_file:
        nb_flagged = len(i_file.read().splitlines())

    # We write a LaTeX summary
    latex_file = os.path.join(script_prefix + ".summary.tex")
    try:
        with open(latex_file, "w") as o_file:
            print >>o_file, latex_template.subsection(
                flag_maf_zero.pretty_name
            )
            safe_fn = latex_template.sanitize_tex(os.path.basename(flagged_fn))
            text = (
                "After computing minor allele frequencies (MAF) of all "
                "markers using Plink, a total of {:,d} marker{} had a MAF "
                "of zero and were flagged ({}).".format(
                    nb_flagged,
                    "s" if nb_flagged - 1 > 1 else "",
                    "see file " + latex_template.texttt(safe_fn) +
                    " for more information"
                )
            )
            print >>o_file, latex_template.wrap_lines(text)

    except IOError:
        msg = "{}: cannot write LaTeX summary".format(latex_file)
        raise ProgramError(msg)

    # Writing the summary results
    with open(os.path.join(base_dir, "results_summary.txt"), "a") as o_file:
        print >>o_file, "# {}".format(script_prefix)
        print >>o_file, ("Number of markers flagged for MAF of 0\t"
                         "{:,d}".format(nb_flagged))
        print >>o_file, "---"

    # We know this step doesn't produce an new data set, so we return the old
    # prefix and the old in_type
    return _StepResult(
        next_file=in_prefix,
        next_file_type=required_type,
        latex_summary=latex_file,
        description=flag_maf_zero.desc,
        long_description=flag_maf_zero.long_desc,
        graph_path=None,
    )