Esempio n. 1
0
def mirror(parameters):
    parser = parsers.mirror_parser()

    args = parser.parse_args(parameters)

    if args.colormap_lower is None:
        colormap_lower = config.colormap_hic if not args.oe_lower else 'bwr'
    else:
        colormap_lower = args.colormap_lower

    if args.colormap_upper is None:
        colormap_upper = config.colormap_hic if not args.oe_upper else 'bwr'
    else:
        colormap_upper = args.colormap_upper

    matrix_upper = fanc.load(os.path.expanduser(args.hic_upper), mode='r')
    matrix_lower = fanc.load(os.path.expanduser(args.hic_lower), mode='r')

    from fanc.tools.general import str_to_int

    norm_upper = "lin" if not args.log_upper else "log"
    upper_plot = kplt.HicPlot(matrix_upper,
                              colormap=colormap_upper,
                              max_dist=str_to_int(args.max_dist),
                              norm=norm_upper,
                              vmin=args.vmin_upper,
                              vmax=args.vmax_upper,
                              oe=args.oe_upper,
                              log=args.oe_upper,
                              colorbar_symmetry=0 if args.oe_upper
                              and args.colorbar_symmetry_upper is None else
                              args.colorbar_symmetry_upper,
                              show_colorbar=args.show_colorbar,
                              adjust_range=False)
    norm_lower = "lin" if not args.log_lower else "log"
    lower_plot = kplt.HicPlot(matrix_lower,
                              colormap=colormap_lower,
                              max_dist=str_to_int(args.max_dist),
                              norm=norm_lower,
                              vmin=args.vmin_lower,
                              vmax=args.vmax_lower,
                              oe=args.oe_lower,
                              log=args.oe_lower,
                              colorbar_symmetry=0 if args.oe_lower
                              and args.colorbar_symmetry_lower is None else
                              args.colorbar_symmetry_lower,
                              show_colorbar=args.show_colorbar,
                              adjust_range=False)
    vsp = kplt.VerticalSplitPlot(upper_plot, lower_plot)
    return vsp, args
Esempio n. 2
0
def triangular(parameters):
    parser = parsers.triangular_parser()
    args = parser.parse_args(parameters)

    if args.colormap is None:
        colormap = config.colormap_hic if not args.oe else 'bwr'
    else:
        colormap = args.colormap

    matrix = fanc.load(os.path.expanduser(args.hic), mode='r')
    from fanc.tools.general import str_to_int

    norm = "lin" if not args.log else "log"
    return kplt.HicPlot(
        matrix,
        colormap=colormap,
        max_dist=str_to_int(args.max_dist)
        if args.max_dist is not None else None,
        norm=norm,
        vmin=args.vmin,
        vmax=args.vmax,
        show_colorbar=args.show_colorbar,
        adjust_range=args.adjust_range,
        oe=args.oe,
        log=args.oe,
        colorbar_symmetry=0 if args.oe and args.colorbar_symmetry is None else
        args.colorbar_symmetry,
        ylabel=args.ylabel,
        weight_field=args.weight_field,
        default_value=args.default_value,
        matrix_norm=args.norm), args
Esempio n. 3
0
 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)
Esempio n. 4
0
#                        draw_minor_ticks=False, title="Tollrm910")

# Toll10B_nc14_hic = fanc.load(os.path.join("data", "hic", "merged",
#                                           "Toll10B-nc14", "hic",
#                                           "Toll10B-nc14_1kb.hic"), mode="r")
# Toll10B_nc14_hic_plot = fancplot.HicPlot(Toll10B_nc14_hic, vmin=1e-03,
#                                          vmax=1e-01, norm="log",
#                                          draw_minor_ticks=False,
#                                          title="Toll10B")


gd7_microc = fanc.load(os.path.join("data", "micro-c", "merged",
                                    "gd7", "hic",
                                    "gd7_" + res + ".hic"), mode="r")
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)
Esempio n. 5
0
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()
Esempio n. 6
0
import os
import pybedtools
import re
import seaborn

# import sys

matplotlib.use('agg')
logging.basicConfig(level=logging.INFO)

gd7_nc14_hic = fanc.load(os.path.join("data", "hic", "merged", "gd7-nc14",
                                      "hic", "gd7-nc14_2kb.hic"),
                         mode="r")
gd7_nc14_hic_plot = fancplot.HicPlot(gd7_nc14_hic,
                                     vmin=1e-03,
                                     vmax=1e-01,
                                     norm="log",
                                     draw_minor_ticks=False,
                                     title="gd7")

Tollrm910_nc14_hic = fanc.load(os.path.join("data", "hic", "merged",
                                            "Tollrm910-nc14", "hic",
                                            "Tollrm910-nc14_2kb.hic"),
                               mode="r")
Tollrm910_nc14_hic_plot = fancplot.HicPlot(Tollrm910_nc14_hic,
                                           vmin=1e-03,
                                           vmax=1e-01,
                                           norm="log",
                                           draw_minor_ticks=False,
                                           title="Tollrm910")

Toll10B_nc14_hic = fanc.load(os.path.join("data", "hic", "merged",
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)
import matplotlib
import os
import pybedtools
import re
import seaborn

# import sys

matplotlib.use('agg')
logging.basicConfig(level=logging.INFO)

control_stg10_hic = fanc.load(os.path.join("data", "hic", "merged",
                                      "control-stg10", "hic",
                                      "control-stg10_2kb.hic"), mode="r")
control_stg10_hic_plot = fancplot.HicPlot(control_stg10_hic, vmin=1e-03,
                                     vmax=1e-01, norm="log",
                                     draw_minor_ticks=False, title="control")

gd7_stg10_hic = fanc.load(os.path.join("data", "hic", "merged",
                                      "gd7-stg10", "hic",
                                      "gd7-stg10_2kb.hic"), mode="r")
gd7_stg10_hic_plot = fancplot.HicPlot(gd7_stg10_hic, vmin=1e-03,
                                     vmax=1e-01, norm="log",
                                     draw_minor_ticks=False, title="gd7")

Tollrm910_stg10_hic = fanc.load(os.path.join("data", "hic", "merged",
                                            "Tollrm910-stg10", "hic",
                                            "Tollrm910-stg10_2kb.hic"),
                               mode="r")
Tollrm910_stg10_hic_plot = fancplot.HicPlot(Tollrm910_stg10_hic, vmin=1e-03,
                                           vmax=1e-01, norm="log",
Esempio n. 9
0
# 7. Loop aggregate plot
loops = fanc.load(loops_file)
if not os.path.exists(loop_am_output_file):
    loop_am = fanc.AggregateMatrix.from_center_pairs(hic_10kb, loops, log=True, oe=True,
                                                     file_name=loop_am_output_file, cache=False)
else:
    loop_am = fanc.AggregateMatrix(loop_am_output_file)

fanc_stats_plot.aggregate_plot(loop_am, labels=('loop anchor',), vmin=-1, vmax=1,
                               oe=False, log=False, colormap='bwr', ax=ax_aggregate_loops,
                               relative_label_locations=(0.5,), cax=cax_aggregate_loops)
ax_aggregate_loops.set_yticklabels([])

# 8. Hi-C plot triangular
p_hic_triangular = fancplot.HicPlot(hic_10kb, norm='lin', ax=ax_hic_triangular, cax=cax_hic_triangular,
                                    max_dist=750000,
                                    vmin=0, vmax=0.03, draw_tick_legend=False, draw_minor_ticks=False)
p_hic_triangular.plot(triangular_plotting_region)

ax_hic_triangular.set_xticks([triangular_plotting_region.start,
                              triangular_plotting_region.center,
                              triangular_plotting_region.end])
p_hic_triangular.colorbar.set_ticks([0, 0.03])
p_hic_triangular.colorbar.set_label("Normalised\ncontact probability")

# 9. Insulation array
insulation = fanc.load(insulation_file)

p_ins_array = fancplot.GenomicVectorArrayPlot(insulation, y_scale='log', ax=ax_ins_array,
                                              colormap='bwr', cax=cax_ins_array,
                                              vmin=-1, vmax=1, draw_tick_legend=False,
Esempio n. 10
0
 def test_hicplot_inputs(self, norm, max_dist, colormap, colorbar,
                         blend_zero, aspect, vrange, crange,
                         unmappable_color, proportional):
     start, end = crange
     vmin, vmax = vrange
     hplot = kplot.HicPlot(hic_data=self.hic_matrix,
                           title="quark",
                           norm=norm,
                           vmin=vmin,
                           vmax=vmax,
                           max_dist=max_dist,
                           colormap=colormap,
                           show_colorbar=colorbar,
                           blend_zero=blend_zero,
                           aspect=aspect,
                           unmappable_color=unmappable_color,
                           proportional=proportional)
     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.collection.norm, norm_values[norm])
     assert axes[0].get_xlim() == (start, end)
     if vmin is not None:
         assert hplot.collection.norm.vmin == vmin
     if vmax is not None:
         assert hplot.collection.norm.vmax == vmax
     if proportional:
         if max_dist is None:
             assert abs_ax_aspect(hplot.ax) == pytest.approx(.5)
         else:
             rl = end - start
             assert abs_ax_aspect(hplot.ax) == pytest.approx(
                 .5 * min(max_dist, rl) / rl)
     else:
         assert abs_ax_aspect(hplot.ax) == 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.collection.get_facecolors()[unmap_mask.T.ravel(), :],
                 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.collection.get_facecolors()[
                         exp_zero.T.ravel(), :], zero_value))
             assert blend_zero == zero_blended
     plt.close(fig)