Example #1
0
def _plot_gene_inner(g,
                     region_series_fits,
                     change_distribution_bin_centers=None):
    fig = plt.figure()
    nRows, nCols = rect_subplot(len(region_series_fits))
    for iRegion, (r, series, fit) in enumerate(region_series_fits):
        ax = fig.add_subplot(nRows, nCols, iRegion + 1)
        if change_distribution_bin_centers is None or not hasattr(
                fit, 'change_distribution_weights'):
            change_distribution = None
        else:
            change_distribution = Bunch(
                centers=change_distribution_bin_centers,
                weights=fit.change_distribution_weights,
            )
        plot_one_series(series,
                        fit.fitter.shape,
                        fit.theta,
                        change_distribution=change_distribution,
                        minimal_annotations=True,
                        ax=ax)
        ax.set_title('Region {}'.format(r))
        if iRegion % nCols == 0:
            ax.set_ylabel('expression level')
    if cfg.exon_level:
        plt.subplots_adjust(hspace=0.8)
        gene, start, end = g.split(cfg.exon_separator)
        ttl = '{}({}-{})'.format(gene, start, end)
    else:
        fig.tight_layout(h_pad=0, w_pad=0)
        ttl = 'Gene {}'.format(g)
    fig.suptitle(ttl, fontsize=14)
    return fig
Example #2
0
def _plot_exons_inner(gene,
                      region,
                      exon_series_fits,
                      plot_ind=1,
                      total_plots=1):
    fig = plt.figure()
    nRows, nCols = rect_subplot(len(exon_series_fits))
    nRows, nCols = min(nRows, nCols), max(nRows, nCols)
    if cfg.exons_same_scale:
        expression_max = max(
            [max(exon[1].single_expression) for exon in exon_series_fits])
        expression_min = min(
            [min(exon[1].single_expression) for exon in exon_series_fits])
        expression_range = np.array([expression_min, expression_max + np.e])
    else:
        expression_range = None
    for iExon, (exon, series, fit) in enumerate(exon_series_fits):
        ax = fig.add_subplot(nRows, nCols, iExon + 1)
        plot_one_exon(series,
                      fit.fitter.shape,
                      fit.theta,
                      LOO_predictions=fit.LOO_predictions,
                      ax=ax,
                      y_range=expression_range)
        ax.set_title(exon.replace(cfg.exon_separator, '-'))
        if iExon % nCols == 0:
            ax.set_ylabel('log expression level' if cfg.plots_scaling in
                          ['log+1', 'log'] else 'expression level')
    plt.subplots_adjust(hspace=0.4)
    plot_ind = '({}\\{})'.format(plot_ind, total_plots)
    fig.suptitle('Gene: {}, Region: {} {}'.format(gene, region, plot_ind),
                 fontsize=20,
                 fontweight='bold')
    return fig
Example #3
0
def plot_series(series, shape=None, theta=None, LOO_predictions=None):
    if series.num_genes == 1:
        return plot_one_series(series, shape, theta, LOO_predictions)
    fig = plt.figure()
    nRows, nCols = rect_subplot(series.num_genes)
    for iGene,g in enumerate(series.gene_names):
        ax = fig.add_subplot(nRows,nCols,iGene+1)
        theta_i = theta[iGene] if theta is not None else None
        LOO_i = LOO_predictions[:,iGene] if LOO_predictions is not None else None
        plot_one_series(series.get_single_gene_series(iGene), shape, theta_i, LOO_i, ax=ax)
        ax.set_title('Gene {}'.format(g), fontsize=cfg.fontsize)
    fig.tight_layout(h_pad=0,w_pad=0)
    fig.suptitle('Region {}'.format(series.region_name), fontsize=cfg.fontsize)
    return fig
Example #4
0
def _plot_exons_from_series_inner(gene, region, img_files, plot_ind,
                                  total_plots):
    fig = plt.figure()  #figsize = (20,9))
    nRows, nCols = rect_subplot(len(img_files))
    nRows, nCols = min(nRows, nCols), max(nRows, nCols)
    for n, fname in enumerate(img_files):
        image = Image.open(fname)
        ax = fig.add_subplot(nRows, nCols, n + 1)
        ax.axis('off')
        ax.imshow(image)
    plot_ind = '({}\\{})'.format(plot_ind, total_plots)
    fig.suptitle('Gene: {}, Region: {} {}'.format(gene, region, plot_ind),
                 fontsize=20,
                 fontweight='bold')
    return fig
Example #5
0
def plot_series(series, shape=None, theta=None, LOO_predictions=None):
    if series.num_genes == 1:
        return plot_one_series(series, shape, theta, LOO_predictions)
    fig = plt.figure()
    nRows, nCols = rect_subplot(series.num_genes)
    for iGene, g in enumerate(series.gene_names):
        ax = fig.add_subplot(nRows, nCols, iGene + 1)
        theta_i = theta[iGene] if theta is not None else None
        LOO_i = LOO_predictions[:,
                                iGene] if LOO_predictions is not None else None
        plot_one_series(series.get_single_gene_series(iGene),
                        shape,
                        theta_i,
                        LOO_i,
                        ax=ax)
        ax.set_title('Gene {}'.format(g), fontsize=cfg.fontsize)
    fig.tight_layout(h_pad=0, w_pad=0)
    fig.suptitle('Region {}'.format(series.region_name), fontsize=cfg.fontsize)
    return fig
Example #6
0
def _plot_gene_inner(g, region_series_fits, change_distribution_bin_centers=None):
    fig = plt.figure()
    nRows, nCols = rect_subplot(len(region_series_fits))
    for iRegion,(r,series,fit) in enumerate(region_series_fits):
        ax = fig.add_subplot(nRows,nCols,iRegion+1)
        if change_distribution_bin_centers is None or not hasattr(fit, 'change_distribution_weights'):
            change_distribution = None
        else:
            change_distribution = Bunch(
                centers = change_distribution_bin_centers,
                weights = fit.change_distribution_weights,
            )
        plot_one_series(series, fit.fitter.shape, fit.theta, change_distribution=change_distribution, minimal_annotations=True, ax=ax)
        ax.set_title('Region {}'.format(r))
        if iRegion % nCols == 0:
            ax.set_ylabel('expression level')
    fig.tight_layout(h_pad=0,w_pad=0)
    fig.suptitle('Gene {}'.format(g))
    return fig