def line(parameters): parser = parsers.line_parser() args = parser.parse_args(parameters) regions = [fanc.load(file_name) for file_name in args.regions] attribute = args.attribute bin_size = args.bin_size labels = args.labels colors = args.colors fill = args.fill line_style = args.line_style ylim = args.ylim alpha = args.alpha legend_location = args.legend_location if labels is not None and len(labels) != len(regions): parser.error("Number of labels ({}) must be the same as number " "of datasets ({})".format(len(labels), len(regions))) p = kplt.LinePlot(regions, bin_size=bin_size, fill=fill, attribute=attribute, labels=labels, style=line_style, ylim=ylim, colors=colors, legend_location=legend_location, plot_kwargs={'alpha': alpha}) return p, args
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())
# 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=False, 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=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)
plt.show() # end snippet ab fancplot-correlation fig.savefig('../docsrc/api/analyse/images/ab_1mb_correlation.png') # start snippet ab ev ev = ab.eigenvector() # end snippet ab ev # start snippet ab gc-ev gc_ev = ab.eigenvector(genome='hg19_chr18_19.fa', force=True) # end snippet ab gc-ev # start snippet ab plot-ev fig, ax = plt.subplots(figsize=(5, 2)) lp = fancplot.LinePlot(ab, colors=['darkturquoise']) lp.plot('chr18') plt.show() # end snippet ab plot-ev fig.savefig('../docsrc/api/analyse/images/ab_1mb_ev.png') # start snippet ab profile profile, cutoffs = ab.enrichment_profile(hic_1mb, genome='hg19_chr18_19.fa') # end snippet ab profile # start snippet ab saddle fig, axes = fancplot.saddle_plot(profile, cutoffs) # end snippet ab saddle fig.savefig('../docsrc/api/analyse/images/ab_1mb_saddle.png')
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 compare(self, weight1, weight2): if weight1 < weight2: return -1 if weight1 > weight2: return 1 return 0 # end snippet comparisons custom # start snippet regions compare diff_ins_esc_cn_100kb = fanc.DifferenceRegions.from_regions(ins_esc_100kb, ins_cn_100kb) # end snippet regions compare # start snippet regions plot p_orig = fancplot.LinePlot([ins_esc_100kb, ins_cn_100kb], ylim=(-1, 1), colors=['darkturquoise', 'orange'], style='mid', fill=False) p_diff = fancplot.LinePlot(diff_ins_esc_cn_100kb, ylim=(-1., 1.), colors=['aquamarine'], style='mid') gf = fancplot.GenomicFigure([p_orig, p_diff], ticks_last=True) fig, axes = gf.plot("chr1:167.9mb-168.7mb") axes[0].set_ylabel("Insulation\nscore") axes[1].set_ylabel("Insulation\ndifference") # end snippet regions plot fig.savefig("../docsrc/api/analyse/images/comparisons_regions.png") plt.close(fig) # start snippet scores compare
#fanc_base = '..' fanc_base = '/Users/kkruse/dev/fanc' # start snippet fancplot load bed insulation_scores_1mb = fanc.load( "architecture/domains/fanc_example_100kb.insulation_1mb.bed") insulation_scores_2mb = fanc.load( "architecture/domains/fanc_example_100kb.insulation_2mb.bed") boundaries_1mb = fanc.load( "architecture/domains/fanc_example_100kb.insulation_boundaries_1mb.bed") boundaries_2mb = fanc.load( "architecture/domains/fanc_example_100kb.insulation_boundaries_2mb.bed") # end snippet fancplot load bed # start snippet fancplot line fill hp = fancplot.LinePlot(insulation_scores_1mb) hp.plot('chr18:6mb-10mb') hp.show() # end snippet fancplot line fill hp.save(os.path.join(fanc_base, 'docsrc/api/plot/images/plot_line.png')) # start snippet fancplot line nofill hp = fancplot.LinePlot(insulation_scores_1mb, fill=False) hp.plot('chr18:6mb-10mb') hp.show() # end snippet fancplot line nofill hp.save(os.path.join(fanc_base, 'docsrc/api/plot/images/plot_line_nofill.png')) # start snippet fancplot line mid
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)
# start snippet insulation multiplot p = fancplot.GenomicVectorArrayPlot(insulation, colormap='RdBu_r', vmin=-1, vmax=1, genomic_format=True) p.plot('chr18:18mb-28mb') # end snippet insulation multiplot fig.savefig("../docsrc/api/analyse/images/domains_multi.png") plt.close(fig) fig, ax = plt.subplots() # start snippet insulation singleplot p = fancplot.LinePlot(insulation, ylim=(-1, 1), colors=['darkturquoise'], style="mid", attribute="insulation_1000000") p.plot('chr18:18mb-28mb') # end snippet insulation singleplot fig.savefig("../docsrc/api/analyse/images/domains_single.png") plt.close(fig) # start snippet boundaries run 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
Toll10B_stg10_hic_plot = fancplot.HicPlot(Toll10B_stg10_hic, vmin=1e-03, vmax=1e-01, norm="log", draw_minor_ticks=False, title="Toll10B") 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", "modencode_white", "rnaseq_aligned", name + "_sorted_filtered_merged_canonical_chrs_rnaseq.bw") for name in ["E0-4", "E4-8"]} rnaseq_plot_E04 = fancplot.LinePlot(rnaseq_dict['E0-4'], fill=False, plot_kwargs={'color': "black"}, draw_minor_ticks=False, aspect=0.05, n_yticks=2) rnaseq_plot_E48 = fancplot.LinePlot(rnaseq_dict['E4-8'], fill=False, plot_kwargs={'color': "black"}, draw_minor_ticks=False, aspect=0.05, n_yticks=2) 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)
vmin=-1, vmax=1, draw_tick_legend=False, draw_minor_ticks=False, draw_tick_labels=False) p_ins_array.plot(triangular_plotting_region) p_ins_array.colorbar.set_label('Insulation score') ax_ins_array.set_xticks([triangular_plotting_region.start, triangular_plotting_region.center, triangular_plotting_region.end]) ax_ins_array.set_yticks([50000, 200000, 1000000]) ax_ins_array.set_yticklabels(['50kb', '200kb', '1mb']) ax_ins_array.set_ylabel('Window\nsize (bp)') # 10. Insulation score insulation_single = insulation.score_regions(100000) p_ins = fancplot.LinePlot(insulation_single, ax=ax_ins, style='mid', plot_kwargs={'color': '#79C7C5'}, draw_tick_legend=False, draw_minor_ticks=False) p_ins.plot(triangular_plotting_region) ax_ins.set_xticks([triangular_plotting_region.start, triangular_plotting_region.center, triangular_plotting_region.end]) ax_ins.set_ylabel('Insulation\nscore 100kb') # 11. Directionality flame directionality = fanc.load(directionality_file) p_dir_array = fancplot.GenomicVectorArrayPlot(directionality, y_scale='log', ax=ax_dir_array, colormap='PuOr', cax=cax_dir_array, vmin=-0.1, vmax=0.1, draw_tick_legend=False, draw_minor_ticks=False, draw_tick_labels=False)