hic3defdr.analysis.plotting module

class hic3defdr.analysis.plotting.PlottingHiC3DeFDR[source]

Bases: object

Mixin class containing plotting functions for HiC3DeFDR.

plot_correlation_matrix(stage='scaled', idx='loop', correlation='spearman', colorscale=(0.75, 1.0), **kwargs)[source]

Plots a matrix of pairwise correlations among all replicates.

Parameters:
  • stage ({'raw', 'scaled'}) – Specify the stage of the data to compute correlations between.
  • idx ({'disp', 'loop'}) – Pass ‘disp’ to compute correlations for all points for which dispersion was estimated. Pass ‘loop’ to compute correlations for all points which are in loops (available only if loop_patterns was passed to the constructor).
  • correlation ({'spearman', 'pearson'}) – Which correlation coefficient to compute.
  • colorscale (tuple of float) – The min and max values of the correlation to use to color the matrix.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_dd_curves(chrom, log=True, **kwargs)[source]

Plots the distance dependence curve before and after size factor adjustment.

Parameters:
  • chrom (str) – The name of the chromosome to plot the curve for.
  • log (bool) – Whether or not to log the axes of the plot.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_ddr(cond, dist_max=None, scatter_size=36, **kwargs)[source]

Fast alternative to plot_dispersion_fit() that only supports plotting distance versus dispersion, with no hexbin or scatter_points support.

Parameters:
  • cond (str) – The name of the chromosome and condition, respectively, to plot the fit for.
  • dist_max (int) – If xaxis is ‘dist’, the maximum distance to include on the plot in bin units. Pass None to use self.dist_thresh_max.
  • scatter_size (int) – The marker size when plotting scatterplots.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_dispersion_fit(cond, xaxis='dist', yaxis='disp', dist_max=None, scatter_fit=-1, scatter_size=36, distance=None, hexbin=False, logx=False, logy=False, **kwargs)[source]

Plots a hexbin plot of pixel-wise distance vs either dispersion or variance, overlaying the estimated and fitted dispersions.

Parameters:
  • cond (str) – The name of the chromosome and condition, respectively, to plot the fit for.
  • xaxis ('mean' or 'dist') – What to plot on the x-axis.
  • yaxis ('disp' or 'var') – What to plot on the y-axis.
  • dist_max (int) – If xaxis is ‘dist’, the maximum distance to include on the plot in bin units. Pass None to use self.dist_thresh_max.
  • scatter_fit (int) – Pass a nonzero integer to draw the fitted dispersions passed in disp as a scatterplot of scatter_fit selected points. Pass -1 to plot the fitted dispersions passed in disp as a curve. Pass 0 to omit plotting the dispersion estimates altogether.
  • scatter_size (int) – The marker size when plotting scatterplots.
  • distance (int, optional) – Pick a specific distance in bin units to plot only interactions at that distance.
  • hexbin (bool) – Pass False to skip plotting the hexbin plot, leaving only the estimated variances or dispersions.
  • logy (logx,) – Whether or not to log the x- or y-axis, respectively.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_grid(chrom, i, j, w, vmax=100, fdr=0.05, cluster_size=3, fdr_vmid=0.05, color_cycle=('blue', 'green', 'purple', 'yellow', 'cyan', 'red'), despine=False, **kwargs)[source]

Plots a combination visualization grid focusing on a specific pixel on a specific chromosome, combining heatmaps, cluster outlines, and stripplots.

Parameters:
  • chrom (str) – The name of the chromosome to slice matrices from.
  • j (i,) – The row and column index of the pixel to focus on.
  • w (int) – The size of the heatmap will be 2*w + 1 bins in each dimension.
  • vmax (float) – The maximum of the colorscale to use when plotting normalized heatmaps.
  • fdr (float) – The FDR threshold to use when outlining clusters.
  • cluster_size (int) – The cluster size threshold to use when outlining clusters.
  • fdr_vmid (float) – The FDR value at the middle of the colorscale used for plotting the q-value heatmap.
  • color_cycle (list of matplotlib colors) – The color cycle to use over conditions.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The first pyplot axis returned is injected by @plotter. The grid of pyplot axes is the second return value from the call to plt.subplots() that is used to create the grid. The function takes two args, an FDR and a cluster size, and redraws the cluster outlines using the new parameters.

Return type:

pyplot axis, grid of pyplot axes, function

plot_heatmap(chrom, row_slice, col_slice, stage='scaled', rep=None, cond=None, cmap='Reds', vmin=0, vmax=100, **kwargs)[source]

Plots a simple heatmap of a slice of the contact matrix.

Parameters:
  • chrom (str) – The chromosome to plot.
  • col_slice (row_slice,) – The row and column slice, respectively, to plot.
  • stage (str) – The stage of the data to plot.
  • cond (rep,) – Pass the rep name or condition name if the data specified by stage has multiple columns.
  • cmap (matplotlib colormap or dict) – The colormap to use for the heatmap.
  • vmax (vmin,) – The vmin and vmax to use for the heatmap colorscale.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_ma(fdr=0.05, conds=None, include_non_loops=True, s=-1, nonloop_s=None, density_dpi=72, vmax=None, nonloop_vmax=None, ax=None, legend=True, **kwargs)[source]

Plots an MA plot for a given chromosome.

Parameters:
  • fdr (float) – The threshold to use for labeling significantly differential loop pixels.
  • conds (tuple of str, optional) – Pass a tuple of two condition names to compare those two conditions. Pass None to compare the first two conditions.
  • include_non_loops (bool) – Whether or not to include non-looping pixels in the MA plot.
  • s (float) – The marker size to use for the scatterplot, or -1 to use a scatter density plot.
  • nonloop_s (float, optional) – Pass a separate marker size to use specifically for the non-loop pixels if include_non_loops is True. Useful for drawing just the non-loop pixels as a density by passing s=1, nonloop_s=-1. Pass None to use s as the size for both loop and non-loop pixels.
  • density_dpi (int) – If s or nonloop_s are -1 this specifies the DPI to use for the density grid.
  • nonloop_vmax (vmax,) – The vmax to use for ax.scatter_density() if s or nonloop_s is -1, respectively. Pass None to choose values automatically.
  • ax (pyplot axis) – The axis to plot to. Must have been created with projection=’scatter_density’. Pass None to create a new axis.
  • legend (bool) – Pass True to add a legend. Note that passing legend=’outside’ is not supported.
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_pvalue_distribution(idx='disp', **kwargs)[source]

Plots the p-value distribution across all chromosomes.

Parameters:
  • idx ({'disp', 'loop'}) – Pass ‘disp’ to plot p-values for all points for which dispersion was estimated. Pass ‘loop’ to plot p-values for all points which are in loops (available only if loop_patterns was passed to the constructor).
  • kwargs (kwargs) – Typical plotter kwargs.
Returns:

The axis plotted on.

Return type:

pyplot axis

plot_qvalue_distribution(**kwargs)[source]

Plots the q-value distribution across all chromosomes.

Parameters:kwargs (kwargs) – Typical plotter kwargs.
Returns:The axis plotted on.
Return type:pyplot axis