def draw_meta_summary_plot(html_fpath, output_dirpath, labels, ref_names, all_rows, results, plot_fpath, title='', reverse=False, yaxis_title=''): import math if can_draw_plots: meta_logger.info(' Drawing ' + title + ' metaQUAST summary plot...') import matplotlib.pyplot import matplotlib.ticker fig = matplotlib.pyplot.figure() ax = fig.add_subplot(111) matplotlib.pyplot.title(title) box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height * 1.0]) ax.yaxis.grid(with_grid) ref_num = len(ref_names) contigs_num = len(labels) arr_x = [] arr_y = [] values = [] arr_y_by_refs = [] for j in range(contigs_num): to_plot_x = [] to_plot_y = [] arr = range(1, ref_num + 1) for i in range(ref_num): arr[i] += 0.07 * (j - (contigs_num - 1) * 0.5) to_plot_x.append(arr[i]) if results[i][j] and results[i][j] != '-': to_plot_y.append(parseStrToNum(results[i][j])) else: to_plot_y.append(None) arr_x.append(to_plot_x) arr_y.append(to_plot_y) refs = [] for i in range(ref_num): points_y = [arr_y[j][i] for j in range(contigs_num) if i < len(arr_y[j])] significant_points_y = [points_y[k] for k in range(len(points_y)) if points_y[k] is not None] if significant_points_y: arr_y_by_refs.append(points_y) values.append(sum(filter(None, points_y))/len(points_y)) refs.append(ref_names[i]) sorted_values = sorted(itertools.izip(values, refs, arr_y_by_refs), reverse=reverse, key=lambda x: x[0]) values, refs, arr_y_by_refs = [[x[i] for x in sorted_values] for i in range(3)] if can_draw_plots: matplotlib.pyplot.xticks(range(1, len(refs) + 1), refs, size='small', rotation='vertical') json_points_x = [] json_points_y = [] for j in range(contigs_num): points_x = [arr_x[j][i] for i in range(len(arr_y_by_refs))] points_y = [arr_y_by_refs[i][j] for i in range(len(arr_y_by_refs))] if can_draw_plots: color, ls = get_color_and_ls(None, labels[j]) ax.plot(points_x, points_y, 'o:', color=color, ls=ls) json_points_x.append(points_x) json_points_y.append(points_y) if qconfig.html_report: from quast_libs.html_saver import html_saver html_saver.save_meta_summary(html_fpath, output_dirpath, json_points_x, json_points_y, title.replace(' ', '_'), labels, refs) if can_draw_plots: matplotlib.pyplot.xlim([0, ref_num + 1]) ymax = 0 for i in range(ref_num): for j in range(contigs_num): if all_rows[j + 1]['values'][i] is not None and all_rows[j + 1]['values'][i] != '-': ymax = max(ymax, parseStrToNum(all_rows[j + 1]['values'][i])) if ymax < 5: matplotlib.pyplot.ylim([0, 5]) else: matplotlib.pyplot.ylim([0, math.ceil(ymax * 1.05)]) if yaxis_title: ylabel = yaxis_title ylabel, mkfunc = y_formatter(ylabel, ymax) matplotlib.pyplot.ylabel(ylabel, fontsize=axes_fontsize) mkformatter = matplotlib.ticker.FuncFormatter(mkfunc) ax.yaxis.set_major_formatter(mkformatter) if ymax == 0: matplotlib.pyplot.ylim([0, 5]) legend = [] for j in range(contigs_num): legend.append(labels[j]) try: ax.legend(legend, loc='center left', bbox_to_anchor=(1.0, 0.5), numpoints=1) except Exception: pass matplotlib.pyplot.tight_layout() matplotlib.pyplot.savefig(plot_fpath, bbox_inches='tight') meta_logger.info(' saved to ' + plot_fpath) matplotlib.pyplot.close()
def draw_meta_summary_plot(html_fpath, output_dirpath, labels, ref_names, results, plot_fpath, title='', reverse=False, yaxis_title='', print_all_refs=False, logger=logger): if can_draw_plots: logger.info(' Drawing ' + title + ' metaQUAST summary plot...') plots = [] ref_num = len(ref_names) contigs_num = len(labels) max_y = 0 arr_x = [] arr_y = [] mean_values = [] arr_y_by_refs = [] for j in range(contigs_num): to_plot_x = [] to_plot_y = [] arr = list(range(1, ref_num + 1)) for i in range(ref_num): arr[i] += 0.07 * (j - (contigs_num - 1) * 0.5) to_plot_x.append(arr[i]) if results[i][j] and results[i][j] != '-': to_plot_y.append(parse_str_to_num(results[i][j])) elif print_all_refs: to_plot_y.append(0) else: to_plot_y.append(None) arr_x.append(to_plot_x) arr_y.append(to_plot_y) selected_refs = [] for i in range(ref_num): points_y = [ arr_y[j][i] for j in range(contigs_num) if i < len(arr_y[j]) ] significant_points_y = [ points_y[k] for k in range(len(points_y)) if points_y[k] is not None ] if significant_points_y or print_all_refs: arr_y_by_refs.append(points_y) mean_values.append( sum(list(filter(None, points_y))) * 1.0 / len(points_y)) selected_refs.append(ref_names[i]) json_points_x = [] json_points_y = [] if not qconfig.use_input_ref_order: sorted_values = sorted(zip(mean_values, selected_refs, arr_y_by_refs), reverse=reverse, key=lambda x: x[0]) mean_values, selected_refs, arr_y_by_refs = [ [x[i] for x in sorted_values] for i in range(3) ] for j in range(contigs_num): points_x = [arr_x[j][i] for i in range(len(arr_y_by_refs))] points_y = [arr_y_by_refs[i][j] for i in range(len(arr_y_by_refs))] max_y = max(max_y, max(points_y)) color, ls = get_color_and_ls(None, labels[j]) plots.append( Plot(points_x, points_y, color=color, ls='dotted', marker='o', markersize=7)) if not qconfig.use_input_ref_order: json_points_x.append(points_x) json_points_y.append(points_y) refs_for_html = [ r for r in selected_refs ] # for summary html, we need to sort values by average value anyway if qconfig.use_input_ref_order: sorted_values = sorted(zip(mean_values, selected_refs, arr_y_by_refs), reverse=reverse, key=lambda x: x[0]) mean_values, refs_for_html, arr_y_by_refs = [ [x[i] for x in sorted_values] for i in range(3) ] for j in range(contigs_num): points_x = [arr_x[j][i] for i in range(len(arr_y_by_refs))] points_y = [arr_y_by_refs[i][j] for i in range(len(arr_y_by_refs))] json_points_x.append(points_x) json_points_y.append(points_y) if qconfig.html_report and html_fpath: from quast_libs.html_saver import html_saver html_saver.save_meta_summary(html_fpath, output_dirpath, json_points_x, json_points_y, title.replace(' ', '_'), labels, refs_for_html) if can_draw_plots: legend_list = labels create_plot(plot_fpath, title, plots, legend_list, y_label=yaxis_title, vertical_legend=True, x_ticks=[''] + selected_refs, vertical_ticks=True, x_limit=[0, len(selected_refs) + 1], add_to_report=False, logger=logger)
def draw_meta_summary_plot(html_fpath, output_dirpath, labels, ref_names, all_rows, results, plot_fpath, title='', reverse=False, yaxis_title='', print_all_refs=False): import math if can_draw_plots: meta_logger.info(' Drawing ' + title + ' metaQUAST summary plot...') import matplotlib.pyplot import matplotlib.ticker figure = matplotlib.pyplot.figure() ax = figure.add_subplot(111) matplotlib.pyplot.title(title) box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height * 1.0]) ax.yaxis.grid(with_grid) ref_num = len(ref_names) contigs_num = len(labels) arr_x = [] arr_y = [] values = [] arr_y_by_refs = [] for j in range(contigs_num): to_plot_x = [] to_plot_y = [] arr = list(range(1, ref_num + 1)) for i in range(ref_num): arr[i] += 0.07 * (j - (contigs_num - 1) * 0.5) to_plot_x.append(arr[i]) if results[i][j] and results[i][j] != '-': to_plot_y.append(parseStrToNum(results[i][j])) elif print_all_refs and results[i][j] != '-': to_plot_y.append(0) else: to_plot_y.append(None) arr_x.append(to_plot_x) arr_y.append(to_plot_y) refs = [] for i in range(ref_num): points_y = [arr_y[j][i] for j in range(contigs_num) if i < len(arr_y[j])] significant_points_y = [points_y[k] for k in range(len(points_y)) if points_y[k] is not None] if significant_points_y or print_all_refs: arr_y_by_refs.append(points_y) values.append(sum(list(filter(None, points_y))) / len(points_y)) refs.append(ref_names[i]) sorted_values = sorted(zip(values, refs, arr_y_by_refs), reverse=reverse, key=lambda x: x[0]) values, refs, arr_y_by_refs = [[x[i] for x in sorted_values] for i in range(3)] if can_draw_plots: matplotlib.pyplot.xticks(range(1, len(refs) + 1), refs, size='small', rotation='vertical') json_points_x = [] json_points_y = [] for j in range(contigs_num): points_x = [arr_x[j][i] for i in range(len(arr_y_by_refs))] points_y = [arr_y_by_refs[i][j] for i in range(len(arr_y_by_refs))] if can_draw_plots: color, ls = get_color_and_ls(None, labels[j]) ax.plot(points_x, points_y, 'o:', color=color, ls=ls) json_points_x.append(points_x) json_points_y.append(points_y) if qconfig.html_report and html_fpath: from quast_libs.html_saver import html_saver html_saver.save_meta_summary(html_fpath, output_dirpath, json_points_x, json_points_y, title.replace(' ', '_'), labels, refs) if can_draw_plots: matplotlib.pyplot.xlim([0, ref_num + 1]) ymax = 0 for i in range(ref_num): for j in range(contigs_num): if all_rows[j + 1]['values'][i] is not None and all_rows[j + 1]['values'][i] != '-': ymax = max(ymax, parseStrToNum(all_rows[j + 1]['values'][i])) if ymax < 5: matplotlib.pyplot.ylim([0, 5]) else: matplotlib.pyplot.ylim([0, math.ceil(ymax * 1.05)]) if yaxis_title: ylabel = yaxis_title ylabel, mkfunc = y_formatter(ylabel, ymax) matplotlib.pyplot.ylabel(ylabel, fontsize=axes_fontsize) mkformatter = matplotlib.ticker.FuncFormatter(mkfunc) ax.yaxis.set_major_formatter(mkformatter) if ymax == 0: matplotlib.pyplot.ylim([0, 5]) legend = [] for j in range(contigs_num): legend.append(labels[j]) try: ax.legend(legend, loc='center left', bbox_to_anchor=(1.0, 0.5), numpoints=1) except Exception: pass matplotlib.pyplot.tight_layout() matplotlib.pyplot.savefig(plot_fpath, bbox_inches='tight') meta_logger.info(' saved to ' + plot_fpath) pdf_plots_figures.append(figure) matplotlib.pyplot.close()