コード例 #1
0
def do(html_fpath, output_dirpath, combined_output_dirpath,
       output_dirpath_per_ref, metrics, misassembly_metrics, ref_names):
    labels = get_labels(combined_output_dirpath,
                        qconfig.report_prefix + '.tsv')
    contigs_num = len(labels)
    plots_dirname = qconfig.plot_extension.upper()
    for ext in ['TXT', plots_dirname, 'TEX', 'TSV']:
        if not os.path.isdir(os.path.join(output_dirpath, ext)):
            os.mkdir(os.path.join(output_dirpath, ext))
    for metric in metrics:
        if not isinstance(metric, tuple):
            summary_txt_fpath = os.path.join(output_dirpath, 'TXT',
                                             metric.replace(' ', '_') + '.txt')
            summary_tex_fpath = os.path.join(output_dirpath, 'TEX',
                                             metric.replace(' ', '_') + '.tex')
            summary_tsv_fpath = os.path.join(output_dirpath, 'TSV',
                                             metric.replace(' ', '_') + '.tsv')
            summary_plot_fpath = os.path.join(output_dirpath, plots_dirname,
                                              metric.replace(' ', '_'))
            results, all_rows, cur_ref_names = \
                get_results_for_metric(ref_names, metric, contigs_num, labels, output_dirpath_per_ref, qconfig.transposed_report_prefix + '.tsv')
            if not results or not results[0]:
                continue
            if cur_ref_names:
                transposed_table = [{
                    'metricName':
                    'Assemblies',
                    'values': [
                        all_rows[i]['metricName']
                        for i in range(1, len(all_rows))
                    ],
                }]
                for i in range(len(all_rows[0]['values'])):
                    values = []
                    for j in range(1, len(all_rows)):
                        values.append(all_rows[j]['values'][i])
                    transposed_table.append({
                        'metricName':
                        all_rows[0]['values'][i],  # name of reference
                        'values':
                        values
                    })

                print_file(transposed_table, summary_txt_fpath)

                reporting.save_tsv(summary_tsv_fpath, transposed_table)
                reporting.save_tex(summary_tex_fpath, transposed_table)
                reverse = False
                if reporting.get_quality(
                        metric) == reporting.Fields.Quality.MORE_IS_BETTER:
                    reverse = True
                y_label = None
                if metric in [
                        reporting.Fields.TOTALLEN,
                        reporting.Fields.TOTALLENS__FOR_1000_THRESHOLD,
                        reporting.Fields.TOTALLENS__FOR_10000_THRESHOLD,
                        reporting.Fields.TOTALLENS__FOR_50000_THRESHOLD
                ]:
                    y_label = 'Total length'
                elif metric == reporting.Fields.TOTAL_ALIGNED_LEN:
                    y_label = 'Aligned length'
                elif metric in [
                        reporting.Fields.LARGCONTIG, reporting.Fields.N50,
                        reporting.Fields.NGA50,
                        reporting.Fields.MIS_EXTENSIVE_BASES
                ]:
                    y_label = 'Contig length'
                elif metric == reporting.Fields.LARGALIGN:
                    y_label = 'Alignment length'
                plotter.draw_meta_summary_plot(html_fpath,
                                               output_dirpath,
                                               labels,
                                               cur_ref_names,
                                               results,
                                               summary_plot_fpath,
                                               title=metric,
                                               reverse=reverse,
                                               yaxis_title=y_label,
                                               print_all_refs=True,
                                               logger=logger)
                if metric == reporting.Fields.MISASSEMBL:
                    mis_results = []
                    report_fname = os.path.join(
                        'contigs_reports', qconfig.transposed_report_prefix +
                        '_misassemblies' + '.tsv')
                    if ref_names[-1] == qconfig.not_aligned_name:
                        cur_ref_names = ref_names[:-1]
                    for misassembly_metric in misassembly_metrics:
                        results, all_rows, cur_ref_names = \
                            get_results_for_metric(cur_ref_names, misassembly_metric[len(reporting.Fields.TAB):],
                                                   contigs_num, labels, output_dirpath_per_ref, report_fname)
                        if results:
                            mis_results.append(results)
                    if mis_results:
                        json_points = []
                        for contig_num in range(contigs_num):
                            plot_fpath = os.path.join(
                                output_dirpath, plots_dirname,
                                qutils.slugify(labels[contig_num]) +
                                '_misassemblies')
                            json_points.append(
                                plotter.draw_meta_summary_misassemblies_plot(
                                    mis_results,
                                    cur_ref_names,
                                    contig_num,
                                    plot_fpath,
                                    title=labels[contig_num]))
                        if qconfig.html_report:
                            from quast_libs.html_saver import html_saver
                            if ref_names[-1] == qconfig.not_aligned_name:
                                cur_ref_names = ref_names[:-1]
                            if json_points:
                                html_saver.save_meta_misassemblies(
                                    html_fpath, output_dirpath, json_points,
                                    labels, cur_ref_names)
    logger.main_info('')
    logger.main_info(
        '  Text versions of reports and plots for each metric (for all references and assemblies) are saved to '
        + output_dirpath + '/')
コード例 #2
0
def do(html_fpath, output_dirpath, combined_output_dirpath, output_dirpath_per_ref, metrics, misassembl_metrics, ref_names):
    labels = get_labels(combined_output_dirpath, qconfig.report_prefix + '.tsv')
    contigs_num = len(labels)
    plots_dirname = qconfig.plot_extension.upper()
    for ext in ['TXT', plots_dirname, 'TEX', 'TSV']:
        if not os.path.isdir(os.path.join(output_dirpath, ext)):
            os.mkdir(os.path.join(output_dirpath, ext))
    for metric in metrics:
        if not isinstance(metric, tuple):
            summary_txt_fpath = os.path.join(output_dirpath, 'TXT', metric.replace(' ', '_') + '.txt')
            summary_tex_fpath = os.path.join(output_dirpath, 'TEX', metric.replace(' ', '_') + '.tex')
            summary_tsv_fpath = os.path.join(output_dirpath, 'TSV', metric.replace(' ', '_') + '.tsv')
            summary_png_fpath = os.path.join(output_dirpath, plots_dirname, metric.replace(' ', '_') + '.' + qconfig.plot_extension)
            results, all_rows, cur_ref_names = get_results_for_metric(ref_names, metric, contigs_num, labels, output_dirpath_per_ref, qconfig.transposed_report_prefix + '.tsv')
            if not results or not results[0]:
                continue
            if cur_ref_names:
                transposed_table = [{'metricName': 'Assemblies',
                                    'values': [all_rows[i]['metricName'] for i in range(1, len(all_rows))],}]
                for i in range(len(all_rows[0]['values'])):
                    values = []
                    for j in range(1, len(all_rows)):
                        values.append(all_rows[j]['values'][i])
                    transposed_table.append({'metricName': all_rows[0]['values'][i], # name of reference
                                             'values': values})

                print_file(transposed_table, summary_txt_fpath)

                reporting.save_tsv(summary_tsv_fpath, transposed_table)
                reporting.save_tex(summary_tex_fpath, transposed_table)
                reverse = False
                if reporting.get_quality(metric) == reporting.Fields.Quality.MORE_IS_BETTER:
                    reverse = True
                y_label = None
                if metric == reporting.Fields.TOTALLEN:
                    y_label = 'Total length '
                elif metric == reporting.Fields.TOTAL_ALIGNED_LEN:
                    y_label = 'Aligned length '
                elif metric in [reporting.Fields.LARGCONTIG, reporting.Fields.N50, reporting.Fields.NGA50,
                                reporting.Fields.MIS_EXTENSIVE_BASES]:
                    y_label = 'Contig length '
                elif metric == reporting.Fields.LARGALIGN:
                    y_label = 'Alignment length '
                plotter.draw_meta_summary_plot(html_fpath, output_dirpath, labels, cur_ref_names, all_rows, results,
                                               summary_png_fpath, title=metric, reverse=reverse, yaxis_title=y_label)
                if metric == reporting.Fields.MISASSEMBL:
                    mis_results = []
                    report_fname = os.path.join('contigs_reports', qconfig.transposed_report_prefix + '_misassemblies' + '.tsv')
                    if ref_names[-1] == qconfig.not_aligned_name:
                        cur_ref_names = ref_names[:-1]
                    for misassembl_metric in misassembl_metrics:
                        results, all_rows, cur_ref_names = get_results_for_metric(cur_ref_names, misassembl_metric[len(reporting.Fields.TAB):], contigs_num, labels, output_dirpath_per_ref, report_fname)
                        if results:
                            mis_results.append(results)
                    if mis_results:
                        json_points = []
                        for contig_num in range(contigs_num):
                            plot_fpath = os.path.join(output_dirpath, plots_dirname, qutils.slugify(labels[contig_num]) + '_misassemblies')
                            json_points.append(plotter.draw_meta_summary_misassembl_plot(mis_results, cur_ref_names,
                                                                                         contig_num, plot_fpath,
                                                                                         title=labels[contig_num]))
                        if qconfig.html_report:
                            from quast_libs.html_saver import html_saver
                            if ref_names[-1] == qconfig.not_aligned_name:
                                cur_ref_names = ref_names[:-1]
                            if json_points:
                                html_saver.save_meta_misassemblies(html_fpath, output_dirpath, json_points, labels, cur_ref_names)
    logger.main_info('')
    logger.main_info('  Text versions of reports and plots for each metric (for all references and assemblies) are saved to ' + output_dirpath + '/')
コード例 #3
0
def get_blast_output_fpath(blast_output_fpath, label):
    return blast_output_fpath + '_' + slugify(label)
コード例 #4
0
def get_blast_output_fpath(blast_output_fpath, label):
    return blast_output_fpath + '_' + slugify(label)