def _coverage_vs_quality_plot(contigs, output_dir): """ Creates a scatter plot coverage vs quality plot for each contig in the polished assembly. Each point represents one contig. :param contigs: (dict) contig id -> ContigInfo object :param output_dir: (str) path to output directory :return: (Plot) object that has already been saved as a PNG to output_dir """ import pbreports.plot.helper as PH fig, axes = PH.get_fig_axes_lpr() axes = fig.add_subplot(111) axes.set_axisbelow(True) axes.set_ylabel( get_plot_ylabel(spec, Constants.PG_COVERAGE, Constants.P_COVERAGE)) axes.set_xlabel( get_plot_xlabel(spec, Constants.PG_COVERAGE, Constants.P_COVERAGE)) PH.set_tick_label_font_size(axes, 12, 12) PH.set_axis_label_font_size(axes, 16) x_vals = [x.mean_coverage for x in contigs.values()] y_vals = [x.mean_qv for x in contigs.values()] axes.set_xlim(0, max(x_vals) * 1.2) axes.set_ylim(0, max(y_vals) * 1.2) axes.scatter(x_vals, y_vals, s=12) png_path = os.path.join(output_dir, "polished_coverage_vs_quality.png") png, thumbpng = PH.save_figure_with_thumbnail(fig, png_path) return Plot(Constants.P_COVERAGE, os.path.basename(png), thumbnail=os.path.basename(thumbpng))
def _coverage_vs_quality_plot(contigs, output_dir): """ Creates a scatter plot coverage vs quality plot for each contig in the polished assembly. Each point represents one contig. :param contigs: (dict) contig id -> ContigInfo object :param output_dir: (str) path to output directory :return: (Plot) object that has already been saved as a PNG to output_dir """ fig, axes = PH.get_fig_axes_lpr() axes = fig.add_subplot(111) axes.set_axisbelow(True) axes.set_ylabel("Mean Confidence (QV)") axes.set_xlabel("Mean Coverage Depth") PH.set_tick_label_font_size(axes, 12, 12) PH.set_axis_label_font_size(axes, 16) x_vals = [x.mean_coverage for x in contigs.values()] y_vals = [x.mean_qv for x in contigs.values()] axes.set_xlim(0, max(x_vals) * 1.2) axes.set_ylim(0, max(y_vals) * 1.2) axes.scatter(x_vals, y_vals, s=12) png_path = os.path.join(output_dir, "polished_coverage_vs_quality.png") png, thumbpng = PH.save_figure_with_thumbnail(fig, png_path) return Plot('cov_vs_qual', os.path.basename(png), thumbnail=os.path.basename(thumbpng))
def _apply_plot_data(x_data, y1_data, y2_data, labels, legend_loc=None): """Default labels assume y1_data==control, y2_data==sample""" h1_color = '#5050f0' h2_color = '#f05050' # log option isn't really working yet ... funky with polygons # these are unintuitively inverted b/c we require the sample # on the left side of the doubleY axis h2, t = np.histogram(y1_data, bins=x_data) h1, t = np.histogram(y2_data, bins=x_data) fig, ax = get_fig_axes_lpr() x_data = x_data[:-1] y0 = np.zeros(len(x_data)) # if log: # h1 = np.log10(h1) # h2 = np.log10(h2) ax.fill_between(x_data, y0, h1.T, alpha=0.6, edgecolor=h1_color, facecolor=h1_color) fake_h2 = mp.Rectangle((0.1, 0.1), 0.1, 0.1, facecolor=h2_color, edgecolor=h2_color, alpha=0.6) fake_h1 = mp.Rectangle((0.1, 0.1), 0.1, 0.1, facecolor=h1_color, edgecolor=h1_color, alpha=0.6) ax.set_xlabel(labels[0]) ax.set_ylabel('%s (Sample)' % labels[1]) ax.legend([fake_h2, fake_h1], ['Control', 'Sample'], loc=legend_loc) # gray border around legend ax.get_legend().get_frame().set_edgecolor('#a0a0a0') set_tick_label_font_size(ax, 12, 12) set_axis_label_font_size(ax, 16) ax2 = ax.twinx() ax2.fill_between(x_data, y0, h2.T, alpha=0.6, edgecolor=h2_color, facecolor=h2_color) ax2.set_ylabel('%s (Control)' % labels[1]) set_tick_label_font_size(ax2, 12, 12) set_axis_label_font_size(ax2, 16) return fig
def _create_fig_template(dims=(8, 6), facecolor='#ffffff', gridcolor='#e0e0e0'): fig, ax = PH.get_fig_axes_lpr(dims=dims) ax = fig.add_subplot(111) ax.axesPatch.set_facecolor(facecolor) ax.grid(color=gridcolor, linewidth=0.5, linestyle='-') ax.set_axisbelow(True) PH.set_tick_label_font_size(ax, 12, 12) PH.set_axis_label_font_size(ax, 16) return fig, ax