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 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 gene(parameters): parser = parsers.gene_parser() args = parser.parse_args(parameters) genes_file = os.path.expanduser(args.genes) p = kplt.GenePlot(genes_file, feature_types=args.feature_types, color_neutral=args.color_neutral, color_forward=args.color_forward, color_reverse=args.color_reverse, color_score=args.color_score, box_height=args.box_height, font_size=args.font_size, arrow_size=args.arrow_size, line_width=args.line_width, group_by=args.group_by, show_labels=args.show_labels, collapse=args.collapse, squash=args.squash, label_field=args.label_field) return p, args
gd7_microc_plot = fancplot.HicPlot(gd7_microc, vmin=1e-03, vmax=1e-01, norm="log", draw_minor_ticks=False, title="gd7") control_microc = fanc.load(os.path.join("data", "micro-c", "merged", "control", "hic", "control_" + res + ".hic"), mode="r") control_microc_plot = fancplot.HicPlot(control_microc, vmin=1e-03, vmax=1e-01, norm="log", draw_minor_ticks=False, title="control") 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"]}
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()
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)
p_dir = fancplot.LinePlot(directionality_single, ax=ax_dir, style='mid', plot_kwargs={'color': '#79C7C5'}, draw_tick_legend=False, draw_minor_ticks=False) p_dir.plot(triangular_plotting_region) ax_dir.set_xticks([triangular_plotting_region.start, triangular_plotting_region.center, triangular_plotting_region.end]) ax_dir.set_ylabel('Directionality\nindex 1Mb') # 13. Genes genes = fanc.load(genes_file) p_genes = fancplot.GenePlot(genes, feature_types=('exon',), color_score=False, box_height=0.9, show_labels=True, label_field='gene_name', font_size=7, arrow_size=0, show_arrows=False, line_width=1, group_by='gene_id', draw_tick_legend=False, draw_tick_labels=True, draw_minor_ticks=False, ax=ax_genes, squash=True, min_gene_size=3000, collapse=False, include={ 'gene_type': {'processed_transcript', 'rRNA', 'protein_coding', 'IG_V_gene'} }) p_genes.plot(triangular_plotting_region) ax_genes.set_xticks([triangular_plotting_region.start, triangular_plotting_region.center, triangular_plotting_region.end]) # 14. CTCF enrichment p_ctcf = fancplot.LinePlot(ctcf, ax=ax_ctcf, style='mid', plot_kwargs={'color': 'black'}, fill=False, draw_tick_labels=False) p_ctcf.plot(triangular_plotting_region) ax_ctcf.set_xticks([triangular_plotting_region.start,