Esempio n. 1
0
    def __init__(self,
                 data,
                 window_sizes=None,
                 regions=None,
                 title='',
                 midpoint=None,
                 colormap='coolwarm_r',
                 vmax=None,
                 current_window_size=0,
                 log_y=True):
        if regions is None:
            regions = []
            for i in range(data.shape[1]):
                regions.append(GenomicRegion(chromosome='', start=i, end=i))
        self.regions = regions

        BasePlotter1D.__init__(self, title=title)
        self.da = data
        if window_sizes is None:
            window_sizes = []
            try:
                l = len(data)
            except TypeError:
                l = data.shape[0]
            for i in range(l):
                window_sizes.append(i)

        self.window_sizes = window_sizes
        self.colormap = colormap
        self.midpoint = midpoint
        self.mesh = None
        self.vmax = vmax
        self.window_size_line = None
        self.current_window_size = current_window_size
        self.log_y = log_y
Esempio n. 2
0
 def plot(self, region=None, ax=None, **kwargs):
     if isinstance(region, string_types):
         region = GenomicRegion.from_string(region)
     if ax:
         self.ax = ax
     # set genome tick formatter
     self.ax.xaxis.set_major_formatter(GenomeCoordFormatter(region))
     self.ax.xaxis.set_major_locator(GenomeCoordLocator(nbins=5))
     self.ax.xaxis.set_minor_locator(MinorGenomeCoordLocator(n=5))
     self.ax.set_title(self.title)
     self._plot(region, **kwargs)
     self.ax.set_xlim(region.start, region.end)
     return self.fig, self.ax
Esempio n. 3
0
 def plot(self, region=None, ax=None, **kwargs):
     if isinstance(region, string_types):
         region = GenomicRegion.from_string(region)
     if ax:
         self.ax = ax
     # set genome tick formatter
     self.ax.xaxis.set_major_formatter(GenomeCoordFormatter(region))
     self.ax.xaxis.set_major_locator(GenomeCoordLocator(nbins=5))
     self.ax.xaxis.set_minor_locator(MinorGenomeCoordLocator(n=5))
     self.ax.set_title(self.title)
     self._plot(region, **kwargs)
     self.ax.set_xlim(region.start, region.end)
     return self.fig, self.ax
Esempio n. 4
0
    def __init__(self,
                 data,
                 regions=None,
                 title='',
                 init_row=0,
                 is_symmetric=False):
        BasePlotter1D.__init__(self, title=title)
        if regions is None:
            regions = []
            for i in range(len(data)):
                regions.append(GenomicRegion(chromosome='', start=i, end=i))

        self.init_row = init_row
        self.data = data
        self.sr = None
        self.da_sub = None
        self.regions = regions
        self.current_region = None
        self.line = None
        self.current_ix = init_row
        self.current_cutoff = None
        self.cutoff_line = None
        self.cutoff_line_mirror = None
        self.is_symmetric = is_symmetric
Esempio n. 5
0
    def __init__(self,
                 hic_matrix,
                 regions=None,
                 colormap='RdBu',
                 norm="log",
                 vmin=None,
                 vmax=None,
                 show_colorbar=True,
                 blend_masked=False):
        if regions is None:
            for i in range(hic_matrix.shape[0]):
                regions.append(GenomicRegion(chromosome='', start=i, end=i))
        self.regions = regions
        self.hic_matrix = hic_matrix

        self.colormap = copy.copy(mpl.cm.get_cmap(colormap))
        if blend_masked:
            self.colormap.set_bad(self.colormap(0))
        self._vmin = vmin
        self._vmax = vmax
        self.norm = prepare_normalization(norm=norm, vmin=vmin, vmax=vmax)
        self.colorbar = None
        self.slider = None
        self.show_colorbar = show_colorbar
Esempio n. 6
0
    def __init__(self,
                 hic_matrix,
                 regions=None,
                 data=None,
                 window_sizes=None,
                 norm='lin',
                 max_dist=3000000,
                 max_percentile=99.99,
                 algorithm='insulation',
                 matrix_colormap=None,
                 data_colormap=None,
                 log_data=True):
        self.hic_matrix = hic_matrix
        if regions is None:
            regions = []
            for i in range(hic_matrix.shape[0]):
                regions.append(GenomicRegion(chromosome='', start=i, end=i))
        self.regions = regions
        self.norm = norm
        self.fig = None
        self.max_dist = max_dist
        self.algorithm = algorithm
        self.svmax = None
        self.min_value = np.nanmin(self.hic_matrix[np.nonzero(
            self.hic_matrix)])
        self.min_value_data = None
        self.hic_plot = None
        self.tad_plot = None
        self.data_plot = None
        self.line_plot = None
        self.sdata = None
        self.data_ax = None
        self.line_ax = None
        self.da = None
        self.ws = None
        self.current_window_size = None
        self.window_size_text = None
        self.tad_cutoff_text = None
        self.max_percentile = max_percentile
        self.tad_regions = None
        self.current_da_ix = None
        self.button_save_tads = None
        self.button_save_vector = None
        self.button_save_matrix = None

        self.log_data = log_data

        if algorithm == 'insulation':
            self.tad_algorithm = insulation_index
            self.tad_calling_algorithm = call_tads_insulation_index
            self.is_symmetric = False
            if matrix_colormap is None:
                self.matrix_colormap = LinearSegmentedColormap.from_list(
                    'myreds', ['white', 'red'])
            if data_colormap is None:
                self.data_plot_color = 'plasma'
        elif algorithm == 'ninsulation':
            self.tad_algorithm = normalised_insulation_index
            self.tad_calling_algorithm = call_tads_insulation_index
            self.is_symmetric = True
            if matrix_colormap is None:
                self.matrix_colormap = LinearSegmentedColormap.from_list(
                    'myreds', ['white', 'red'])
            if data_colormap is None:
                self.data_plot_color = LinearSegmentedColormap.from_list(
                    'myreds', ['blue', 'white', 'red'])
        elif algorithm == 'directionality':
            self.tad_algorithm = directionality_index
            self.tad_calling_algorithm = call_tads_directionality_index
            self.is_symmetric = True
            if matrix_colormap is None:
                self.matrix_colormap = LinearSegmentedColormap.from_list(
                    'myreds', ['white', 'red'])
            if data_colormap is None:
                self.data_plot_color = LinearSegmentedColormap.from_list(
                    'myreds', ['blue', 'white', 'red'])

        if data is None:
            self.da, self.ws = data_array(hic_matrix=self.hic_matrix,
                                          regions=self.regions,
                                          tad_method=self.tad_algorithm,
                                          window_sizes=window_sizes)
        else:
            self.da = data
            if window_sizes is None:
                raise ValueError(
                    "window_sizes parameter cannot be None when providing data!"
                )
            self.ws = window_sizes