Exemplo n.º 1
0
def main_cli():
    bin_dir = os.path.abspath(os.path.dirname(__file__))
    project_dir = os.path.abspath(os.path.dirname(bin_dir))
    result_dir = os.path.abspath(os.path.join(project_dir, 'results'))
    info_path = os.path.join(result_dir, 'sort', 'pymsbayes-results',
            'pymsbayes-info.txt')
    plot_dir = os.path.join(result_dir, 'sort', 'pymsbayes-results',
            'plots')
    plotting.plot_validation_results(info_path,
            omega_symbol = r'D_T',
            psi_symbol = r'|\mathbf{\tau}|',
            mean_time_symbol = r'\bar{T}',
            math_font = None)
    vr = plotting.plot_validation_results(info_path,
            omega_symbol = r'D_T',
            psi_symbol = r'|\mathbf{\tau}|',
            mean_time_symbol = r'\bar{T}',
            label_schema = None,
            prob_plot_height = 3.4,
            prob_plot_margin_left = 0.005,
            prob_plot_margin_bottom = 0.005,
            prob_plot_margin_right = 1,
            prob_plot_margin_top = 1,
            plot_accuracy = False,
            prob_plot_glm = False,
            write_plots = False,
            math_font = None)
    vr['prior']['prior'].prob_plot.subplots[0].set_xlabel(
            xlabel = 'Estimated probability of one divergence')
    vr['prior']['prior'].save_prob_plot(os.path.join(plot_dir,
            'mc-unadjusted.pdf'))
def main_cli():
    info_path = os.path.join(project_util.RESULT_DIR, 'old',
                'pymsbayes-results', 'pymsbayes-info.txt')
    plotting.plot_validation_results(info_path,
            omega_symbol = r'D_T',
            psi_symbol = r'|\mathbf{\tau}|',
            mean_time_symbol = r'\bar{T}',
            math_font = None)
def main_cli():
    bin_dir = os.path.abspath(os.path.dirname(__file__))
    project_dir = os.path.abspath(os.path.dirname(bin_dir))
    result_dir = os.path.abspath(os.path.join(project_dir, 'results'))
    info_path = os.path.join(result_dir, 'multi-locus-no-sort', 'pymsbayes-results',
            'pymsbayes-info.txt')
    plotting.plot_validation_results(info_path,
            omega_symbol = r'D_T',
            psi_symbol = r'|\mathbf{\tau}|',
            mean_time_symbol = r'\bar{T}',
            math_font = None)
def main_cli():
    if not os.path.exists(project_util.IMAGE_DIR):
        os.mkdir(project_util.IMAGE_DIR)
    results = {}
    for d in ['dpp', 'old', 'uniform', 'u-shaped']:
        info_path = os.path.join(project_util.RESULT_DIR, d,
                    'pymsbayes-results', 'pymsbayes-info.txt')
        r = plotting.plot_validation_results(info_path,
                plot_dir = project_util.IMAGE_DIR,
                omega_symbol = r'D_T',
                psi_symbol = r'|\mathbf{\tau}|',
                mean_time_symbol = r'\bar{T}',
                plot_accuracy = True,
                prob_plot_glm = True,
                prob_plot_height = 3.5,
                prob_plot_margin_left = 0,
                prob_plot_margin_bottom = 0,
                prob_plot_margin_right = 1,
                prob_plot_margin_top = 0.975,
                prob_plot_padding_between_horizontal = 0.5,
                prob_plot_padding_between_vertical = 1.0,
                math_font = None,
                write_plots = False)
        for obs_name, p_dict in r.iteritems():
            for prior_name, validation_result in p_dict.iteritems():
                if not results.has_key(obs_name):
                    results[obs_name] = {}
                if not results[obs_name].has_key(prior_name):
                    results[obs_name][prior_name] = validation_result
                else:
                    raise Exception('Unexpected duplicate validation result')

    sub_plot_map = {
            0: ('psi',
                r'True number of divergence events, $|\mathbf{\tau}|$',
                r'Estimated number of divergence events, $\hat{|\mathbf{\tau}|}$ (mode)'),
            1: ('omega',
                r'True variance of divergence times, $D_T$',
                r'Estimated variance of divergence times, $\hat{D_T}$ (median)'),
            2: ('time',
                r'True mean of divergence times, $\bar{T}$',
                r'Estimated mean of divergence times, $\hat{\bar{T}}$ (median)'),
            3: ('psi-glm',
                r'True number of divergence events, $|\mathbf{\tau}|$',
                r'GLM-adjusted number of divergence events, $\hat{|\mathbf{\tau}|}$ (mode)'),
            4: ('omega-glm',
                r'True variance of divergence times, $D_T$',
                r'GLM-adjusted variance of divergence times, $\hat{D_T}$ (median)'),
            5: ('time-glm',
                r'True mean of divergence times, $\bar{T}$',
                r'GLM-adjusted mean of divergence times, $\hat{\bar{T}}$ (median)'),
                }
    for idx, (variable, x_label, y_label) in sub_plot_map.iteritems():
        sub_plots = {}
        for i in ['old', 'dpp', 'uniform', 'u-shaped']:
            if not sub_plots.has_key(i):
                sub_plots[i] = {}
            for j in ['old', 'dpp', 'uniform', 'u-shaped']:
                sub_plots[i][j] = results['prior-' + i]['prior-' + j].accuracy_plot.subplots[idx]
                sub_plots[i][j].set_xlabel('')
                sub_plots[i][j].set_ylabel('')

        sub_plot_list = [
                sub_plots['old']['old'],
                sub_plots['u-shaped']['old'],
                sub_plots['uniform']['old'],
                sub_plots['dpp']['old'],
                sub_plots['old']['u-shaped'],
                sub_plots['u-shaped']['u-shaped'],
                sub_plots['uniform']['u-shaped'],
                sub_plots['dpp']['u-shaped'],
                sub_plots['old']['uniform'],
                sub_plots['u-shaped']['uniform'],
                sub_plots['uniform']['uniform'],
                sub_plots['dpp']['uniform'],
                sub_plots['old']['dpp'],
                sub_plots['u-shaped']['dpp'],
                sub_plots['uniform']['dpp'],
                sub_plots['dpp']['dpp'],
                ]
        for p in sub_plot_list:
            p.set_extra_y_label('')
            for scatter_data in p.scatter_data_list:
                scatter_data.markersize = 5.0

        pg = plotting.PlotGrid(subplots = sub_plot_list,
                num_columns = 4,
                share_x = True,
                share_y = True,
                title = x_label,
                title_size = 14.0,
                title_top = False,
                y_title = y_label,
                y_title_position = 0.015,
                y_title_size = 14.0,
                height = 9.0,
                width = 11.0,
                auto_height = False,
                row_labels = [r'$M_{msBayes}$', r'$M_{Ushaped}$', r'$M_{Uniform}$', r'$M_{DPP}$'],
                column_labels = [r'$M_{msBayes}$', r'$M_{Ushaped}$', r'$M_{Uniform}$', r'$M_{DPP}$'],
                column_label_size = 20.0,
                row_label_size = 20.0,
                column_label_offset = 0.1,
                row_label_offset = 0.05,
                super_title = r'\textbf{Data model}',
                super_y_title = r'\textbf{Inference model}',
                super_title_size = 20.0,
                super_y_title_size = 20.0,
                super_y_title_right = True)
        # pg.label_schema = None
        pg.auto_adjust_margins = False
        pg.margin_bottom = 0.04
        pg.margin_left = 0.04
        pg.margin_top = 0.92
        pg.margin_right = 0.94
        pg.plot_label_size = 12.0
        pg.padding_between_vertical = 1.2
        pg.reset_figure()

        pg.set_shared_x_limits()
        pg.set_shared_y_limits()
        pg.reset_figure()

        pg.savefig(os.path.join(project_util.IMAGE_DIR,
                'validation-accuracy-' + variable + '.pdf'))
def main_cli():
    results = {}
    for d in ['dpp', 'old', 'uniform', 'u-shaped']:
        info_path = os.path.join(project_util.VALIDATION_RESULT_DIR, d,
                    'pymsbayes-results', 'pymsbayes-info.txt')
        r = plotting.plot_validation_results(info_path,
                plot_dir = project_util.IMAGE_DIR,
                omega_symbol = r'D_T',
                psi_symbol = r'|\mathbf{\tau}|',
                mean_time_symbol = r'\bar{T}',
                plot_accuracy = False,
                prob_plot_glm = False,
                prob_plot_height = 3.5,
                prob_plot_margin_left = 0,
                prob_plot_margin_bottom = 0,
                prob_plot_margin_right = 1,
                prob_plot_margin_top = 0.975,
                prob_plot_padding_between_horizontal = 0.5,
                prob_plot_padding_between_vertical = 1.0,
                math_font = None,
                write_plots = False)
        for obs_name, p_dict in r.iteritems():
            for prior_name, validation_result in p_dict.iteritems():
                if not results.has_key(obs_name):
                    results[obs_name] = {}
                if not results[obs_name].has_key(prior_name):
                    results[obs_name][prior_name] = validation_result
                else:
                    raise Exception('Unexpected duplicate validation result')

    sub_plots = {}
    for i in ['old', 'dpp', 'uniform', 'u-shaped']:
        if not sub_plots.has_key(i):
            sub_plots[i] = {}
        for j in ['old', 'dpp', 'uniform', 'u-shaped']:
            sub_plots[i][j] = results['prior-' + i]['prior-' + j].prob_plot.subplots[0]
            sub_plots[i][j].set_xlabel('')
            sub_plots[i][j].set_ylabel('')

    sub_plot_list = [
            sub_plots['old']['old'],
            sub_plots['dpp']['old'],
            sub_plots['old']['dpp'],
            sub_plots['dpp']['dpp'],
            ]
    
    pg = plotting.PlotGrid(subplots = sub_plot_list[:1],
            num_columns = 1,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 14.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.001,
            y_title_size = 14.0,
            column_labels = [r'msBayes'],
            column_label_size = 22.0,
            column_label_offset = 0.04,
            width = 4.6,
            height = 3.7,
            auto_height = False)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.06
    pg.margin_left = 0.05
    pg.margin_top = 0.91
    pg.margin_right = 0.94
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-old.pdf')

    pg = plotting.PlotGrid(subplots = sub_plot_list[-1:],
            num_columns = 1,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 14.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.001,
            y_title_size = 14.0,
            column_labels = [r'dpp-msbayes'],
            column_label_size = 22.0,
            column_label_offset = 0.04,
            width = 4.6,
            height = 3.7,
            auto_height = False)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.06
    pg.margin_left = 0.05
    pg.margin_top = 0.91
    pg.margin_right = 0.94
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-dpp.pdf')

    pg = plotting.PlotGrid(subplots = sub_plot_list,
            num_columns = 2,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 16.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.03,
            y_title_size = 16.0,
            height = 6.0,
            auto_height = False,
            column_labels = [r'$M_{msBayes}$', r'$M_{DPP}$'],
            row_labels = [r'$M_{msBayes}$', r'$M_{DPP}$'],
            column_label_size = 22.0,
            row_label_size = 22.0,
            column_label_offset = 0.05,
            row_label_offset = 0.05,
            super_title = r'\textbf{Data model}',
            super_y_title = r'\textbf{Analysis model}',
            super_title_size = 20.0,
            super_y_title_size = 20.0,
            super_y_title_right = True)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.05
    pg.margin_left = 0.07
    pg.margin_top = 0.90
    pg.margin_right = 0.92
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-old-dpp.pdf')

    for p in sub_plot_list:
        p.set_extra_y_label('')
        p.set_title_text('')

    pg = plotting.PlotGrid(subplots = sub_plot_list[-1:],
            num_columns = 1,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 14.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.001,
            y_title_size = 14.0,
            # column_labels = [r'dpp-msbayes'],
            column_label_size = 22.0,
            column_label_offset = 0.04,
            width = 4.8,
            height = 3.6,
            auto_height = False)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.06
    pg.margin_left = 0.06
    pg.margin_top = 0.99
    pg.margin_right = 0.94
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-dpp-no-label.pdf')

    sub_plot_list = [
            sub_plots['old']['old'],
            sub_plots['dpp']['old'],
            sub_plots['uniform']['old'],
            sub_plots['u-shaped']['old'],
            sub_plots['old']['dpp'],
            sub_plots['dpp']['dpp'],
            sub_plots['uniform']['dpp'],
            sub_plots['u-shaped']['dpp'],
            ]
    for p in sub_plot_list:
        p.set_extra_y_label('')

    pg = plotting.PlotGrid(subplots = sub_plot_list,
            num_columns = 4,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 16.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.015,
            y_title_size = 16.0,
            height = 4.8,
            width = 11.0,
            auto_height = False,
            row_labels = [r'$M_{msBayes}$', r'$M_{DPP}$'],
            column_labels = [r'$M_{msBayes}$', r'$M_{DPP}$', r'$M_{Uniform}$', r'$M_{Ushaped}$'],
            column_label_size = 22.0,
            row_label_size = 22.0,
            column_label_offset = 0.05,
            row_label_offset = 0.05,
            super_title = r'\textbf{Data model}',
            super_y_title = r'\textbf{Analysis model}',
            super_title_size = 20.0,
            super_y_title_size = 20.0,
            super_y_title_right = True)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.06
    pg.margin_left = 0.045
    pg.margin_top = 0.88
    pg.margin_right = 0.94
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-old-dpp-full.pdf')

    for p in sub_plot_list:
        p.set_extra_y_label('')
        p.set_title_text('')

    old_violations = sub_plot_list[1:3]
    dpp_violations = sub_plot_list[4:5] + sub_plot_list[6:7]

    pg = plotting.PlotGrid(subplots = old_violations,
            num_columns = 1,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 16.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.015,
            y_title_size = 16.0,
            height = 6.5,
            width = 4.5,
            auto_height = False,
            column_labels = [r'msBayes'],
            column_label_size = 22.0,
            column_label_offset = 0.05,
            # super_title = r'\textbf{Data model}',
            # super_y_title = r'\textbf{Analysis model}',
            super_title_size = 20.0,
            super_y_title_size = 20.0,
            super_y_title_right = True)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.05
    pg.margin_left = 0.07
    pg.margin_top = 0.94
    pg.margin_right = 0.95
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-old-violations.pdf')

    pg = plotting.PlotGrid(subplots = dpp_violations,
            num_columns = 1,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 16.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.015,
            y_title_size = 16.0,
            height = 6.5,
            width = 4.5,
            auto_height = False,
            column_labels = [r'dpp-msbayes'],
            column_label_size = 22.0,
            column_label_offset = 0.05,
            # super_title = r'\textbf{Data model}',
            # super_y_title = r'\textbf{Analysis model}',
            super_title_size = 20.0,
            super_y_title_size = 20.0,
            super_y_title_right = True)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.05
    pg.margin_left = 0.07
    pg.margin_top = 0.94
    pg.margin_right = 0.95
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-dpp-violations.pdf')
    
    for p in sub_plot_list:
        p.set_extra_y_label('')
        p.set_title_text('')

    pg = plotting.PlotGrid(subplots = dpp_violations,
            num_columns = 2,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 16.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.015,
            y_title_size = 16.0,
            height = 4,
            width = 10,
            auto_height = False,
            # column_labels = ['',''],
            column_label_size = 22.0,
            column_label_offset = 0.05,
            # super_title = r'\textbf{Data model}',
            # super_y_title = r'\textbf{Analysis model}',
            super_title_size = 20.0,
            super_y_title_size = 20.0,
            super_y_title_right = True)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.06
    pg.margin_left = 0.06
    pg.margin_top = 0.99
    pg.margin_right = 0.95
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-dpp-violations-horizontal.pdf')

    pg = plotting.PlotGrid(subplots = dpp_violations[-1:],
            num_columns = 1,
            share_x = True,
            share_y = True,
            title = 'Posterior probability of one divergence',
            title_size = 14.0,
            title_top = False,
            y_title = 'True probability of one divergence',
            y_title_position = 0.001,
            y_title_size = 14.0,
            # column_labels = [r'dpp-msbayes'],
            column_label_size = 22.0,
            column_label_offset = 0.04,
            width = 4.8,
            height = 3.6,
            auto_height = False)
    pg.label_schema = None
    pg.auto_adjust_margins = False
    pg.margin_bottom = 0.06
    pg.margin_left = 0.06
    pg.margin_top = 0.99
    pg.margin_right = 0.94
    pg.reset_figure()

    pg.savefig('../images/validation-model-choice-dpp-uniform-no-label.pdf')