Plots the gender.

    :param data: the data to plot.
    :param options: the options.

    :type data: numpy.recarray
    :type options: argparse.Namespace

    Plots the summarized intensities of the markers on the Y chromosomes in
    function of the markers on the X chromosomes, with problematic samples with
    different colors.

    Also uses :py:func:`print_data_to_file` to save the data, so that it is
    faster to rerun the analysis.

def plot_gender(data, options):
    """Plots the gender.

    :param data: the data to plot.
    :param options: the options.

    :type data: numpy.recarray
    :type options: argparse.Namespace

    Plots the summarized intensities of the markers on the Y chromosomes in
    function of the markers on the X chromosomes, with problematic samples with
    different colors.

    Also uses :py:func:`print_data_to_file` to save the data, so that it is
    faster to rerun the analysis.

    """
    if data is None:
        # there is a problem...
        msg = ("no data: specify either '--bfile' and '--intensities', or "
               "'--summarized-intensities'")
        raise ProgramError(msg)

    import matplotlib as mpl
    if options.format != "X11" and mpl.get_backend() != "agg":
        mpl.use("Agg")
    import matplotlib.pyplot as plt
    if options.format != "X11":
        plt.ioff()

    # The figure and axes
    fig = plt.figure()
    fig.subplots_adjust(top=0.84)
    ax = fig.add_subplot(111)

    # Changing the spines
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)

    # Setting the title
    ax.set_xlabel(options.xlabel)
    ax.set_ylabel(options.ylabel)

    # For the legend
    plot_object = []
    labels = []

    # Plotting the OK males
    males = np.logical_and(data["gender"] == "Male", data["status"] == "OK")
    tmp, = ax.plot(data["chr23"][males], data["chr24"][males], "o", ms=5,
                   mec="#0099CC", mfc="#0099CC")
    plot_object.append(tmp)
    labels.append("OK Males (n={})".format(sum(males)))
    if options.summarized_intensities is None:
        print_data_to_file(data[males], "{}.ok_males.txt".format(options.out))

    # Plotting the OK females
    females = np.logical_and(data["gender"] == "Female",
                             data["status"] == "OK")
    tmp, = ax.plot(data["chr23"][females], data["chr24"][females], "o", ms=5,
                   mec="#CC0000", mfc="#CC0000")
    plot_object.append(tmp)
    labels.append("OK Females (n={})".format(sum(females)))
    if options.summarized_intensities is None:
        print_data_to_file(data[females],
                           "{}.ok_females.txt".format(options.out))

    # Plotting the OK unknowns
    unknowns = np.logical_and(data["gender"] == "Unknown",
                              data["status"] == "OK")
    tmp, = ax.plot(data["chr23"][unknowns], data["chr24"][unknowns], "o", ms=5,
                   mec="#555555", mfc="#555555")
    plot_object.append(tmp)
    labels.append("OK Unknowns (n={})".format(sum(unknowns)))
    if options.summarized_intensities is None:
        print_data_to_file(data[unknowns],
                           "{}.ok_unknowns.txt".format(options.out))

    # Plotting the Problem males
    males = np.logical_and(data["gender"] == "Male",
                           data["status"] == "Problem")
    tmp, = ax.plot(data["chr23"][males], data["chr24"][males], "^", ms=6,
                   mec="#000000", mfc="#669900")
    plot_object.append(tmp)
    labels.append("Problematic Males (n={})".format(sum(males)))
    if options.summarized_intensities is None:
        print_data_to_file(data[males],
                           "{}.problematic_males.txt".format(options.out))

    # Plotting the Problem females
    females = np.logical_and(data["gender"] == "Female",
                             data["status"] == "Problem")
    tmp, = ax.plot(data["chr23"][females], data["chr24"][females], "v", ms=6,
                   mec="#000000", mfc="#9933CC")
    plot_object.append(tmp)
    labels.append("Problematic Females (n={})".format(sum(females)))
    if options.summarized_intensities is None:
        print_data_to_file(data[females],
                           "{}.problematic_females.txt".format(options.out))

    # Plotting the Problem unknowns
    unknowns = np.logical_and(data["gender"] == "Unknown",
                              data["status"] == "Problem")
    tmp, = ax.plot(data["chr23"][unknowns], data["chr24"][unknowns], ">", ms=6,
                   mec="#000000", mfc="#555555")
    plot_object.append(tmp)
    labels.append("Problematic Unknown (n={})".format(sum(unknowns)))
    if options.summarized_intensities is None:
        print_data_to_file(data[unknowns],
                           "{}.problematic_unknowns.txt".format(options.out))

    # the legend
    prop = mpl.font_manager.FontProperties(size=10)
    leg = ax.legend(plot_object, labels, loc=8, numpoints=1, fancybox=True,
                    prop=prop, ncol=2, bbox_to_anchor=(0., 1.02, 1., .102),
                    borderaxespad=0.)

    # Setting the limit
    xlim = ax.get_xlim()
    ax.set_xlim((xlim[0]-0.01, xlim[1]+0.01))
    ylim = ax.get_ylim()
    ax.set_ylim((ylim[0]-0.01, ylim[1]+0.01))

    if options.format == "X11":
        plt.show()
    else:
        file_name = "{}.{}".format(options.out, options.format)
        try:
            plt.savefig(file_name)
        except IOError:
            msg = "{}: can't write file".format(file_name)
            raise ProgramError(msg)