def test_lineplot_dict_input(self, data_source, bin_size): data = {k: getattr(self, d) for k, d in data_source.items()} lplot = kplot.LinePlot(data, bin_size=bin_size) gfig = kplot.GenomicFigure([lplot]) fig, axes = gfig.plot("chr11:77497000-77500000") assert all(len(l.get_ydata()) > 5 for a in axes for l in a.get_lines()) assert all(l.get_label() == n_p for l, n_p in zip(axes[0].get_lines(), data.keys()))
def test_lineplot(self, data_source, bin_size): data = [getattr(self, d) for d in data_source] if len(data) == 1: data = data[0] lplot = kplot.LinePlot(data, bin_size=bin_size) gfig = kplot.GenomicFigure([lplot]) fig, axes = gfig.plot("chr11:77497000-77500000") assert all(len(l.get_ydata()) > 5 for l in axes[0].get_lines())
def test_highlight_plot(self, crange): bplot = kplot.BigWigPlot(self.bigwig_path) gplot = kplot.GenePlot(self.gtf_path) high = kplot.HighlightAnnotation(self.peak_path) gfig = kplot.GenomicFigure([bplot, gplot, high]) fig, axes = gfig.plot("chr11:{}-{}".format(*crange)) p1 = high.patches[0] assert gplot.ax.transAxes.transform( (0, 0))[1] == pytest.approx(p1._transform.transform(p1.get_xy())[1])
def test_geneplot(self, collapse, squash_group): squash, group_by = squash_group gplot = kplot.GenePlot(self.gtf_path, collapse=collapse, squash=squash, group_by=group_by) gfig = kplot.GenomicFigure([gplot]) selector = "chr11:77490000-77500000" fig, axes = gfig.plot(selector) assert len(axes[0].patches) == (19 if squash else 49) plt.close(fig)
def plot_region(name, region, promoter, rnaseq_ylim): output_file = os.path.join("figures", "figure_stg10_panels", name + ".pdf") logging.info("Working on %s", name) logging.info("Will write output to %s", output_file) control_v4c = fancplot.Virtual4CPlot(control_stg10_hic, viewpoint=promoter, aspect=0.05, color="black", draw_minor_ticks=False) gd7_v4c = fancplot.Virtual4CPlot(gd7_stg10_hic, viewpoint=promoter, aspect=0.05, color="#648fff", draw_minor_ticks=False) Tollrm910_v4c = fancplot.Virtual4CPlot(Tollrm910_stg10_hic, viewpoint=promoter, aspect=0.05, color="#dc267f", draw_minor_ticks=False) Toll10B_v4c = fancplot.Virtual4CPlot(Toll10B_stg10_hic, viewpoint=promoter, aspect=0.05, color="#ffb000", draw_minor_ticks=False) ha_plot = fancplot.HighlightAnnotation(bed=pybedtools.BedTool(re.sub(":|-", " ", promoter), from_string=True), plot1=control_v4c, plot2=Toll10B_v4c, plot_kwargs={"color": "gray"}) plots = [control_stg10_hic_plot, gd7_stg10_hic_plot, Tollrm910_stg10_hic_plot, Toll10B_stg10_hic_plot, control_v4c, gd7_v4c, Tollrm910_v4c, Toll10B_v4c, ha_plot, rnaseq_plot_E04, rnaseq_plot_E48, genes_plot ] with fancplot.GenomicFigure(plots, ticks_last=True) as gfig: fig, axes = gfig.plot(region) seaborn.despine(ax=axes[4], top=True, right=True) seaborn.despine(ax=axes[5], top=True, right=True) seaborn.despine(ax=axes[6], top=True, right=True) seaborn.despine(ax=axes[7], top=True, right=True) axes[4].set_ylim([0, 0.025]) axes[5].set_ylim([0, 0.025]) axes[6].set_ylim([0, 0.025]) axes[7].set_ylim([0, 0.025]) # RNA-seq axes axes[8].set_ylim([0, rnaseq_ylim]) axes[9].set_ylim([0, rnaseq_ylim]) # seaborn.despine(ax=axes[4], bottom=True) # seaborn.despine(ax=axes[5], bottom=True) fig.savefig(output_file, bbox_inches='tight')
def test_invert_x_independent_x(self, crange): offset = 150000 bplot = kplot.BigWigPlot(self.bigwig_path) gplot = kplot.GenePlot(self.gtf_path) gfig = kplot.GenomicFigure([bplot, gplot], invert_x=True) fig, axes = gfig.plot("chr11:{}-{}".format(*crange)) ax_lim = axes[0].get_xlim() assert (ax_lim[0] > ax_lim[1] for ax_lim in (a.get_xlim() for a in axes)) bplot = kplot.BigWigPlot(self.bigwig_path, invert_x=True) gplot = kplot.GenePlot(self.gtf_path) gfig = kplot.GenomicFigure([bplot, gplot], independent_x=True) fig, axes = gfig.plot([ "chr11:{}-{}".format(*crange), "chr11:{}-{}".format(crange[0] + offset, crange[1] + offset) ]) ax_lim = [ax.get_xlim() for ax in axes] abs_tol = 10000 assert ax_lim[0][0] == pytest.approx(crange[1], abs=abs_tol) assert ax_lim[0][1] == pytest.approx(crange[0], abs=abs_tol) assert ax_lim[1][0] == pytest.approx(crange[1] + offset, abs=abs_tol) assert ax_lim[1][1] == pytest.approx(crange[0] + offset, abs=abs_tol)
def plot_region(name, region, promoter, rnaseq_ylim): output_file = os.path.join("figures", "figure_4_panels", name + ".pdf") logging.info("Working on %s", name) logging.info("Will write output to %s", output_file) gd7_v4c = fancplot.Virtual4CPlot(gd7_nc14_hic, viewpoint=promoter, aspect=0.05, color="#648fff", draw_minor_ticks=False) Tollrm910_v4c = fancplot.Virtual4CPlot(Tollrm910_nc14_hic, viewpoint=promoter, aspect=0.05, color="#dc267f", draw_minor_ticks=False) Toll10B_v4c = fancplot.Virtual4CPlot(Toll10B_nc14_hic, viewpoint=promoter, aspect=0.05, color="#ffb000", draw_minor_ticks=False) ha_plot = fancplot.HighlightAnnotation(bed=pybedtools.BedTool( re.sub(":|-", " ", promoter), from_string=True), plot1=gd7_v4c, plot2=Toll10B_v4c, plot_kwargs={"color": "gray"}) plots = [ gd7_nc14_hic_plot, rnaseq_plot_gd7, h3k27ac_plot_gd7, gd7_enh_plot, h3k27me3_plot_gd7, Tollrm910_nc14_hic_plot, rnaseq_plot_Tollrm910, h3k27ac_plot_Tollrm910, Tollrm910_enh_plot, h3k27me3_plot_Tollrm910, Toll10B_nc14_hic_plot, rnaseq_plot_toll10b, h3k27ac_plot_toll10b, toll10b_enh_plot, h3k27me3_plot_toll10b, gd7_v4c, Tollrm910_v4c, Toll10B_v4c, ha_plot, genes_plot ] with fancplot.GenomicFigure(plots, ticks_last=True) as gfig: fig, axes = gfig.plot(region) seaborn.despine(ax=axes[15], top=True, right=True) seaborn.despine(ax=axes[16], top=True, right=True) seaborn.despine(ax=axes[17], top=True, right=True) # axes[15].set_ylim([0, 0.02]) # axes[16].set_ylim([0, 0.02]) # axes[17].set_ylim([0, 0.02]) # RNA-seq axes axes[1].set_ylim([0, rnaseq_ylim]) axes[6].set_ylim([0, rnaseq_ylim]) axes[11].set_ylim([0, rnaseq_ylim]) # seaborn.despine(ax=axes[4], bottom=True) # seaborn.despine(ax=axes[5], bottom=True) fig.savefig(output_file)
def test_hicplot2d_inputs(self, norm, colormap, colorbar, blend_zero, aspect, vrange, crange, unmappable_color, adjust_range): start, end = crange vmin, vmax = vrange hplot = kplot.HicPlot2D(hic_data=self.hic_matrix, title="quark", norm=norm, vmin=vmin, vmax=vmax, colormap=colormap, show_colorbar=colorbar, adjust_range=adjust_range, blend_zero=blend_zero, aspect=aspect, unmappable_color=unmappable_color) gfig = kplot.GenomicFigure([hplot]) selector = "chr11:{}-{}".format(start, end) fig, axes = gfig.plot(selector) assert axes[0].get_title() == "quark" norm_values = {"lin": mpl.colors.Normalize, "log": mpl.colors.LogNorm} assert isinstance(hplot.norm, norm_values[norm]) assert axes[0].get_xlim() == (start, end) assert axes[0].get_ylim() == (start, end) if vmin is not None: assert hplot.im.norm.vmin == vmin if vmax is not None: assert hplot.im.norm.vmax == vmax assert hplot.aspect == aspect assert abs_ax_aspect(axes[0]) == pytest.approx(aspect) colorbar_values = {True: mpl.colorbar.Colorbar, False: type(None)} assert isinstance(hplot.colorbar, colorbar_values[colorbar]) hic_matrix = self.hic_matrix[selector, selector] zero_mask = np.isclose(hic_matrix, 0.) unmap_mask = np.all(zero_mask, axis=0) unmap_mask = np.logical_or(unmap_mask, unmap_mask[:, np.newaxis]) if unmappable_color is not None: unmap_color = mpl.colors.colorConverter.to_rgba(unmappable_color) assert np.all( np.isclose(hplot.im.get_array()[unmap_mask, :], unmap_color)) # blend zero only really makes sense with log normalization, with # linear normalization 0 values map to the first colormap value anyway if norm == "log": exp_zero = np.logical_and(zero_mask, np.logical_not(unmap_mask)) if np.sum(exp_zero) > 0: zero_value = hplot.colormap(0) zero_blended = np.all( np.isclose(hplot.im.get_array()[exp_zero, :], zero_value)) assert blend_zero == zero_blended plt.close(fig)
def test_hicsliceplot(self, n_hic, yscale, ylim, slice_region, names): hic_data = self.hic_matrix if n_hic == 1 else [self.hic_matrix] * n_hic names_passed = None if names is None else [ "hic{}".format(i) for i in range(n_hic) ] splot = kplot.HicSlicePlot(hic_data, slice_region, names=names_passed, ylim=ylim, yscale=yscale) gfig = kplot.GenomicFigure([splot]) selector = "chr11:{}-{}".format(77400000, 78600000) fig, axes = gfig.plot(selector) assert axes[0].get_yscale() == yscale for a, b in zip(ylim, axes[0].get_ylim()): assert a is None or a == pytest.approx(b) if names is not None: assert all(l.get_label() == n_p for l, n_p in zip(axes[0].get_lines(), names_passed)) plt.close(fig)
def test_tick_removal(self, width, cax_width, ticks_last, draw_labels, draw_ticks, draw_x_axis): splot = kplot.HicSlicePlot(self.hic_matrix, "chr11:77800000-77850000") hplot = kplot.HicPlot2D(hic_data=self.hic_matrix, draw_ticks=draw_ticks, draw_tick_labels=draw_labels, draw_x_axis=draw_x_axis) hplot2 = kplot.HicPlot(hic_data=self.hic_matrix) gfig = kplot.GenomicFigure([splot, hplot, hplot2], width=width, ticks_last=ticks_last, cax_width=cax_width) selector = "chr11:{}-{}".format(77400000, 78600000) fig, axes = gfig.plot(selector) # hplot2 should always have labels and lines assert all(l.get_visible() for l in axes[2].get_xticklabels()) and all( l.get_visible() for l in axes[2].xaxis.get_majorticklines()) # hplot labels are affected by the three draw parameters should_have_labels = draw_x_axis and draw_labels and (not ticks_last) assert should_have_labels == all(l.get_visible() for l in axes[1].get_xticklabels()) # But it should have tick lines even when ticks_last=True should_have_ticks = draw_x_axis and draw_ticks assert should_have_ticks == all( l.get_visible() for l in axes[1].xaxis.get_majorticklines()) assert should_have_ticks == all( l.get_visible() for l in axes[1].xaxis.get_minorticklines()) # splot should always have ticks and lines assert all(l.get_visible() for l in axes[0].xaxis.get_majorticklines()) assert all(l.get_visible() for l in axes[0].xaxis.get_minorticklines()) # splot only labels if ticks_last=False assert ticks_last != all(l.get_visible() for l in axes[0].get_xticklabels()) bbox = axes[0].get_position() figsize = fig.get_size_inches() assert bbox.width * figsize[0] == pytest.approx(width) bbox = hplot.cax.get_position() assert bbox.width * figsize[0] == pytest.approx(cax_width) plt.close(fig)
def test_bigwig_plot(self, file, crange, n_bw, ylim, yscale, names, bin_size): path = getattr(self, "{}_path".format(file)) bw_data = path if n_bw == 1 else [path] * n_bw names_passed = None if names is None else [ "bw{}".format(i) for i in range(n_bw) ] bplot = kplot.BigWigPlot(bw_data, names=names_passed, bin_size=bin_size, ylim=ylim, yscale=yscale) gfig = kplot.GenomicFigure([bplot]) fig, axes = gfig.plot("chr11:{}-{}".format(*crange)) assert axes[0].get_yscale() == yscale for a, b in zip(ylim, axes[0].get_ylim()): assert a is None or a == pytest.approx(b) if names is not None: assert all(l.get_label() == n_p for l, n_p in zip(axes[0].get_lines(), names_passed)) # Should figure out exactly how many data points I expect instead... assert all(len(l.get_ydata()) > 5 for l in axes[0].get_lines()) plt.close(fig)
def plot_region(name, region): output_file = os.path.join("figures", "figure_4_panels", name + ".pdf") logging.info("Working on %s", name) logging.info("Will write output to %s", output_file) gd7_nc14_hic = fanc.load(os.path.join("data", "hic", "merged", "gd7-nc14", "hic", "gd7-nc14_5kb.hic"), mode="r") gd7_nc14_hic_plot = fancplot.HicPlot(gd7_nc14_hic, norm="log", vmin=1e-03, vmax=1e-01, draw_minor_ticks=False, title="gd7", max_dist='250kb') gd7_nc14_diff = fanc.load(os.path.join( "data", "hic", "merged", "gd7-nc14", "hic", "diff_control-nc14_gd7-nc14_5kb.hic"), mode="r") gd7_nc14_diff_plot = fancplot.HicPlot(gd7_nc14_diff, norm="lin", colormap='bwr_r', vmin=-0.01, vmax=0.01, draw_minor_ticks=False, max_dist='250kb') Tollrm910_nc14_hic = fanc.load(os.path.join("data", "hic", "merged", "Tollrm910-nc14", "hic", "Tollrm910-nc14_5kb.hic"), mode="r") Tollrm910_nc14_hic_plot = fancplot.HicPlot(Tollrm910_nc14_hic, norm="log", vmin=1e-03, vmax=1e-01, draw_minor_ticks=False, title="Tollrm910", max_dist='250kb') Tollrm910_nc14_diff = fanc.load(os.path.join( "data", "hic", "merged", "Tollrm910-nc14", "hic", "diff_control-nc14_Tollrm910-nc14_5kb.hic"), mode="r") Tollrm910_nc14_diff_plot = fancplot.HicPlot(Tollrm910_nc14_diff, norm="lin", colormap='bwr_r', vmin=-0.01, vmax=0.01, draw_minor_ticks=False, max_dist='250kb') Toll10B_nc14_hic = fanc.load(os.path.join("data", "hic", "merged", "Toll10B-nc14", "hic", "Toll10B-nc14_5kb.hic"), mode="r") Toll10B_nc14_hic_plot = fancplot.HicPlot(Toll10B_nc14_hic, norm="log", vmin=1e-03, vmax=1e-01, draw_minor_ticks=False, title="Toll10B", max_dist='250kb') Toll10B_nc14_diff = fanc.load(os.path.join( "data", "hic", "merged", "Toll10B-nc14", "hic", "diff_control-nc14_Toll10B-nc14_5kb.hic"), mode="r") Toll10B_nc14_diff_plot = fancplot.HicPlot(Toll10B_nc14_diff, norm="lin", colormap='bwr_r', vmin=-0.01, vmax=0.01, draw_minor_ticks=False, max_dist='250kb') genes = "external_data/flybase/dmel-all-r6.30.gtf.gz" genes_plot = fancplot.GenePlot(genes, squash=True, group_by="gene_symbol", aspect=0.15, label_field="gene_symbol", show_labels=False, draw_minor_ticks=False) rnaseq_dict = { name: os.path.join("external_data", "koenecke_2016_2017", "rnaseq_aligned", name + "_sorted_filtered_merged_canonical_chrs_rnaseq.bw") for name in ["gd7", "tlrm910", "tl10b"] } h3k27ac_dict = { name: os.path.join( "external_data", "koenecke_2016_2017", "chipseq_aligned", "H3K27ac_" + name + "_sorted_filtered_merged_canonical_chrs.bw") for name in ["gd7", "tl10b"] } h3k27ac_dict["Tollrm910"] = os.path.join( "external_data", "extra_chip-seq", "chipseq_aligned", "H3K27ac_Tollrm910_sorted_filtered_merged_canonical_chrs.bw") h3k27me3_dict = { name: os.path.join( "external_data", "koenecke_2016_2017", "chipseq_aligned", "H3K27me3_" + name + "_sorted_filtered_merged_canonical_chrs.bw") for name in ["gd7", "tl10b"] } h3k27me3_dict["Tollrm910"] = os.path.join( "external_data", "extra_chip-seq", "chipseq_aligned", "H3K27me3_Tollrm910_sorted_filtered_merged_canonical_chrs.bw") # ins_dict = {name: os.path.join("data", "boundaries", name + "_2kb_8.bw") # for name in ["gd7-nc14", "Tollrm910-nc14", "Toll10B-nc14", "3-4h"]} rnaseq_ylim = fancplot.helpers.LimitGroup() rnaseq_ylim = [0, 10] h3k27ac_ylim = fancplot.helpers.LimitGroup() h3k27me3_ylim = fancplot.helpers.LimitGroup() rnaseq_plot_gd7 = fancplot.LinePlot(rnaseq_dict['gd7'], fill=False, plot_kwargs={'color': "#648fff"}, draw_minor_ticks=False, aspect=0.05, ylim=rnaseq_ylim, n_yticks=2) h3k27ac_plot_gd7 = fancplot.LinePlot(h3k27ac_dict['gd7'], fill=False, plot_kwargs={'color': "#648fff"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27ac_ylim, n_yticks=2) h3k27me3_plot_gd7 = fancplot.LinePlot(h3k27me3_dict['gd7'], fill=False, plot_kwargs={'color': "#648fff"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27me3_ylim, n_yticks=2) rnaseq_plot_Tollrm910 = fancplot.LinePlot(rnaseq_dict['tlrm910'], fill=False, plot_kwargs={'color': "#dc267f"}, draw_minor_ticks=False, aspect=0.05, ylim=rnaseq_ylim, n_yticks=2) h3k27ac_plot_Tollrm910 = fancplot.LinePlot( h3k27ac_dict['Tollrm910'], fill=False, plot_kwargs={'color': "#dc267f"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27ac_ylim, n_yticks=2) h3k27me3_plot_Tollrm910 = fancplot.LinePlot( h3k27me3_dict['Tollrm910'], fill=False, plot_kwargs={'color': "#dc267f"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27me3_ylim, n_yticks=2) rnaseq_plot_toll10b = fancplot.LinePlot(rnaseq_dict['tl10b'], fill=False, plot_kwargs={'color': "#ffb000"}, draw_minor_ticks=False, aspect=0.05, ylim=rnaseq_ylim, n_yticks=2) h3k27ac_plot_toll10b = fancplot.LinePlot(h3k27ac_dict['tl10b'], fill=False, plot_kwargs={'color': "#ffb000"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27ac_ylim, n_yticks=2) h3k27me3_plot_toll10b = fancplot.LinePlot(h3k27me3_dict['tl10b'], fill=False, plot_kwargs={'color': "#ffb000"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27me3_ylim, n_yticks=2) gd7_enh = "data/supplementary_tables/gd7_candidate_enhancers.bed" gd7_enh_plot = fancplot.GenomicFeaturePlot(gd7_enh, aspect=0.02, color="#648fff", draw_minor_ticks=False) Tollrm910_enh = "data/supplementary_tables/Tollrm910_candidate_enhancers.bed" Tollrm910_enh_plot = fancplot.GenomicFeaturePlot(Tollrm910_enh, aspect=0.02, color="#dc267f", draw_minor_ticks=False) toll10b_enh = "data/supplementary_tables/Toll10B_candidate_enhancers.bed" toll10b_enh_plot = fancplot.GenomicFeaturePlot(toll10b_enh, aspect=0.02, color="#ffb000", draw_minor_ticks=False) plots = [ gd7_nc14_hic_plot, gd7_nc14_diff_plot, rnaseq_plot_gd7, h3k27ac_plot_gd7, gd7_enh_plot, h3k27me3_plot_gd7, Tollrm910_nc14_hic_plot, Tollrm910_nc14_diff_plot, rnaseq_plot_Tollrm910, h3k27ac_plot_Tollrm910, Tollrm910_enh_plot, h3k27me3_plot_Tollrm910, Toll10B_nc14_hic_plot, Toll10B_nc14_diff_plot, rnaseq_plot_toll10b, h3k27ac_plot_toll10b, toll10b_enh_plot, h3k27me3_plot_toll10b, genes_plot ] with fancplot.GenomicFigure(plots, ticks_last=True) as gfig: fig, axes = gfig.plot(region) fig.savefig(output_file)
boundaries = fanc.Boundaries.from_insulation_score(insulation, window_size=1000000) # end snippet boundaries run # start snippet boundaries regions for boundary in boundaries.regions: score = boundary.score # end snippet boundaries regions # start snippet boundaries plot ph = fancplot.TriangularMatrixPlot(hic_100kb, max_dist=5000000, vmin=0, vmax=0.05) pb = fancplot.BarPlot(boundaries) f = fancplot.GenomicFigure([ph, pb]) fig, axes = f.plot('chr18:18mb-28mb') # end snippet boundaries plot fig.savefig("../docsrc/api/analyse/images/boundaries.png") plt.close(fig) # start snippet boundaries fp min_score = 1.0 robust_boundaries = [] for boundary in boundaries.regions: score = boundary.score if score >= min_score: robust_boundaries.append(boundary) # end snippet boundaries fp # start snippet boundaries minscore
def test_genomic_feature_score_plot(self, attribute): gfsplot = kplot.GenomicFeatureScorePlot(self.peak_path, attribute=attribute) gfig = kplot.GenomicFigure([gfsplot]) fig, axes = gfig.plot("chr11:77497000-77500000") assert len(axes[0].patches) == 2
def test_genomic_feature_plot(self): gfplot = kplot.GenomicFeaturePlot(self.peak_path, label_field=8) gfig = kplot.GenomicFigure([gfplot]) fig, axes = gfig.plot("chr11:77497000-77500000") assert len(axes[0].patches) == 2
file_name="architecture/comparisons/esc_vs_cn.diff") fc_esc_cn = fanc.FoldChangeMatrix.from_matrices(hic_esc, hic_cn, log_cmp=True, file_name="architecture/comparisons/esc_vs_cn.fc") # end snippet comparisons compare # start snippet comparisons plot p_esc = fancplot.TriangularMatrixPlot(hic_esc, vmin=0, vmax=0.05, max_dist=400000) p_cn = fancplot.TriangularMatrixPlot(hic_cn, vmin=0, vmax=0.05, max_dist=400000) p_diff = fancplot.TriangularMatrixPlot(diff_esc_cn, vmin=-0.02, vmax=0.02, colormap='bwr', max_dist=400000) p_fc = fancplot.TriangularMatrixPlot(fc_esc_cn, vmin=-1.5, vmax=1.5, colormap='PiYG', max_dist=400000) gf = fancplot.GenomicFigure([p_esc, p_cn, p_diff, p_fc], ticks_last=True) fig, axes = gf.plot("chr1:167.9mb-168.7mb") # end snippet comparisons plot fig.savefig("../docsrc/api/analyse/images/comparisons_matrices.png") plt.close(fig) # start snippet comparisons custom from fanc.architecture.comparisons import ComparisonMatrix class CustomComparisonMatrix(ComparisonMatrix): _classid = 'CUSTOMCOMPARISONMATRIX' def __init__(self, *args, **kwargs): ComparisonMatrix.__init__(self, *args, **kwargs)
def plot_regions(regions): h = fanc.load(os.path.join("data", "hic", "merged", "3-4h", "hic", "3-4h_2kb.hic"), mode="r") h_plot = fancplot.HicPlot(h, vmin=1e-03, vmax=1e-01, norm="log", draw_minor_ticks=False) genes = "external_data/flybase/dmel-all-r6.30.gtf.gz" genes_plot = fancplot.GenePlot(genes, squash=True, group_by="gene_symbol", aspect=0.15, label_field="gene_symbol", show_labels=False, draw_minor_ticks=False) rnaseq_dict = { name: os.path.join("external_data", "koenecke_2016_2017", "rnaseq_aligned", name + "_sorted_filtered_merged_canonical_chrs_rnaseq.bw") for name in ["gd7", "tlrm910", "tl10b"] } h3k27ac_dict = { name: os.path.join( "external_data", "koenecke_2016_2017", "chipseq_aligned", "H3K27ac_" + name + "_sorted_filtered_merged_canonical_chrs.bw") for name in ["gd7", "tl10b"] } h3k27ac_dict["Tollrm910"] = os.path.join( "external_data", "extra_chip-seq", "chipseq_aligned", "H3K27ac_Tollrm910_sorted_filtered_merged_canonical_chrs.bw") rnaseq_ylim = fancplot.helpers.LimitGroup() h3k27ac_ylim = fancplot.helpers.LimitGroup() polii_ylim = fancplot.helpers.LimitGroup() # polii_chip_early = os.path.join("external_data", "blythe_2015", "aligned", # "PolII-pSer5_NC14-early_sorted_filtered_merged_canonical_chrs.bw") # polii_chip_mid = os.path.join("external_data", "blythe_2015", "aligned", # "PolII-pSer5_NC14-middle_sorted_filtered_merged_canonical_chrs.bw") polii_chip_late = os.path.join( "external_data", "blythe_2015", "aligned", "PolII-pSer5_NC14-late_sorted_filtered_merged_canonical_chrs.bw") # polii_early_plot = fancplot.LinePlot(polii_chip_early, fill=True, plot_kwargs={'color': "black"}, # draw_minor_ticks=False, aspect=0.05, # ylim=polii_ylim, n_yticks=2) # polii_mid_plot = fancplot.LinePlot(polii_chip_mid, fill=True, plot_kwargs={'color': "black"}, # draw_minor_ticks=False, aspect=0.05, # ylim=polii_ylim, n_yticks=2) polii_late_plot = fancplot.LinePlot(polii_chip_late, fill=True, plot_kwargs={'color': "black"}, draw_minor_ticks=False, aspect=0.05, ylim=polii_ylim, n_yticks=2) rnaseq_plot_gd7 = fancplot.LinePlot(rnaseq_dict['gd7'], fill=True, plot_kwargs={'color': "#648fff"}, draw_minor_ticks=False, aspect=0.05, n_yticks=2) h3k27ac_plot_gd7 = fancplot.LinePlot(h3k27ac_dict['gd7'], fill=True, plot_kwargs={'color': "#648fff"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27ac_ylim, n_yticks=2) rnaseq_plot_Tollrm910 = fancplot.LinePlot(rnaseq_dict['tlrm910'], fill=True, plot_kwargs={'color': "#dc267f"}, draw_minor_ticks=False, aspect=0.05, n_yticks=2) h3k27ac_plot_Tollrm910 = fancplot.LinePlot( h3k27ac_dict['Tollrm910'], fill=True, plot_kwargs={'color': "#dc267f"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27ac_ylim, n_yticks=2) rnaseq_plot_toll10b = fancplot.LinePlot(rnaseq_dict['tl10b'], fill=True, plot_kwargs={'color': "#ffb000"}, draw_minor_ticks=False, aspect=0.05, n_yticks=2) h3k27ac_plot_toll10b = fancplot.LinePlot(h3k27ac_dict['tl10b'], fill=True, plot_kwargs={'color': "#ffb000"}, draw_minor_ticks=False, aspect=0.05, ylim=h3k27ac_ylim, n_yticks=2) gd7_enh = "data/supplementary_tables/gd7_candidate_enhancers.bed" gd7_enh_plot = fancplot.GenomicFeaturePlot(gd7_enh, aspect=0.02, color="#648fff", draw_minor_ticks=False) Tollrm910_enh = "data/supplementary_tables/Tollrm910_candidate_enhancers.bed" Tollrm910_enh_plot = fancplot.GenomicFeaturePlot(Tollrm910_enh, aspect=0.02, color="#dc267f", draw_minor_ticks=False) toll10b_enh = "data/supplementary_tables/Toll10B_candidate_enhancers.bed" toll10b_enh_plot = fancplot.GenomicFeaturePlot(toll10b_enh, aspect=0.02, color="#ffb000", draw_minor_ticks=False) plots = [ h_plot, # ins_plot, # boundaries_plot, genes_plot, # hk_plot, # polii_early_plot, polii_mid_plot, polii_late_plot, rnaseq_plot_gd7, rnaseq_plot_Tollrm910, rnaseq_plot_toll10b, h3k27ac_plot_gd7, h3k27ac_plot_Tollrm910, h3k27ac_plot_toll10b, gd7_enh_plot, Tollrm910_enh_plot, toll10b_enh_plot ] with PdfPages(output_file) as pdf: with fancplot.GenomicFigure(plots, ticks_last=True) as gfig: for name, region, rnaseq_ylim in regions: logging.info(region) fig, axes = gfig.plot(region) axes[3].set_ylim([0, rnaseq_ylim]) axes[4].set_ylim([0, rnaseq_ylim]) axes[5].set_ylim([0, rnaseq_ylim]) pdf.savefig()
# Donut O/E values p_oe_d = fancplot.TriangularMatrixPlot(loop_info, vmin=0, vmax=4, weight_field='oe_d', colormap='Reds', max_dist=600000) # Donut FDR values p_fdr_d = fancplot.TriangularMatrixPlot(loop_info, vmin=0, vmax=0.1, weight_field='fdr_d', colormap='binary_r', max_dist=600000) gf = fancplot.GenomicFigure([p_hic, p_oe_d, p_fdr_d], ticks_last=True) fig, axes = gf.plot('chr11:77.4mb-78.6mb') # end snippet loops matrix fig.savefig("../docsrc/api/analyse/images/loops_annotate.png") plt.close(fig) # start snippet loops filters # filter on O/E enrichment_filter = fanc.peaks.EnrichmentPeakFilter(enrichment_ll_cutoff=1.75, enrichment_d_cutoff=3, enrichment_h_cutoff=2, enrichment_v_cutoff=2) loop_info.filter(enrichment_filter, queue=True) # filter on FDR fdr_filter = fanc.peaks.FdrPeakFilter(fdr_ll_cutoff=0.05,