lib5c.plotters.heatmap module

Module providing plot_heatmap(), a wrapper function for the extendable heatmap system defined in the lib5c.plotters.extendable module.

lib5c.plotters.heatmap.plot_heatmap(matrix, grange_x, grange_y=None, rulers=True, ruler_fontsize=7, genes=None, gene_colors=None, colorscale=None, colorbar=False, colormap='abs_obs', motif_tracks=None, motif_track_colors=None, motif_track_labels=None, motif_linewidth=0.5, bed_tracks=None, bed_track_colors=None, bed_track_labels=None, chipseq_tracks=None, snp_tracks=None, snp_colors=None, snp_track_labels=None, chipseq_track_scales=None, chipseq_track_colors=None, chipseq_track_labels=None, domains=None, domain_color='g', clusters=None, cluster_colors=None, dpi=800, despine=False, style=None, **kwargs)[source]

Wrapper function for creating ExtendableHeatmaps.

Parameters
  • matrix (np.ndarray) – The matrix to plot in the heatmap.

  • grange_x (dict or list of dict) –

    The genomic range represented by the x-axis of this heatmap. The dict should have the form:

    {
        'chrom': str,
        'start': int,
        'end': int
    }
    

    Pass a list of dicts of this form (assumed to be sorted) to assume that the genomic range extends from the start of the first range to the end of the last range.

  • grange_y (dict, optional) – The genomic range represented by the y-axis of this heatmap. If None, the heatmap is assumed to be symmetric.

  • rulers (bool) – Pass True to include genomic coordinate rulers on the heatmap.

  • ruler_fontsize (int) – Controls the fontsize for the ruler when rulers is True.

  • genes (str or list of dict) –

    Pass None to skip plotting gene tracks. Pass one of ‘mm9’, ‘mm10’, ‘hg18’, ‘hg19’, or ‘hg38’ to add gene tracks for the selected reference genome. To plot a custom set of genes, pass a list of dicts of the form:

    {
        'chrom' : str,
        'start' : int,
        'end'   : int,
        'name'  : str,
        'strand': '+' or '-',
        'blocks': list of dicts
    }
    

    Blocks typically represent exons and are represented as dicts with the following structure:

    {
        'start': int,
        'end'  : int
    }
    

  • gene_colors (dict, optional) – Pass a dict mapping gene names or ID’s as strings to valid matplotlib colors to plot specific genes in the specified colors.

  • colorscale (tuple of float, optional) – Specify the range of the heatmap colorbar as a tuple of the form (min, max).

  • colorbar (bool) – Pass True to include a colorbar.

  • colormap (str) – Specify the colormap to use.

  • motif_tracks (list of str, optional) – Pass file references to bed files to add to the heatmap as motif tracks.

  • motif_track_colors (dict, optional) – Map from strand value (e.g., ‘+’, ‘-‘) to color name for motifs with that strand value (i.e., orientation). If not provided for a given strand, color is ‘k’ by default.

  • motif_track_labels (list of str, optional) – Parallel to motif_tracks, the ith string will be used to label the ith motif track.

  • motif_linewidth (float) – Pass a linewidth to use when drawing motif instances.

  • bed_tracks (list of str, optional) – Pass file references to bed files to add to the heatmap as bed tracks.

  • bed_track_colors (dict, optional) – Map from strand value (e.g., ‘+’, ‘-‘) to color name for bed features with that strand value (i.e., orientation). If not provided for a given strand, color is ‘k’ by default.

  • bed_track_labels (Parallel to bed_tracks, the ith string will be used) – to label the ith bed track.

  • snp_tracks (list of str, optional) – Pass file references to bed files to add to the heatmap as SNP tracks.

  • snp_colors (dict, optional) – Map from SNP id’s or names to colors. If not provided for a given SNP, color is ‘k’ by default.

  • snp_track_labels (list of str, optional) – Parallel to snp_tracks, the ith string will be used to label the ith SNP track.

  • chipseq_tracks (list of str or list of lists of dicts, optional) –

    Pass file references to bed, bedgraph, or bigwig files to add to the heatmap as chipseq/feature tracks. Alternatively, pass a list of feature lists where each feature is a dict with the form:

    {
        'chrom': str,
        'start': int,
        'end': int,
        'value': float
    }
    

    where the ‘value’ key is optional.

  • chipseq_track_scales (list of tuples of float, optional) – Parallel to chipseq_tracks, the ith tuple should have the form (min, max) and should specify the axis limits of the ith track. Pass None to scale chipseq tracks automatically.

  • chipseq_track_colors (list of str, optional) – Parallel to chipseq_tracks, the ith string should indicate the color of the ith chipseq track. Pass None to color all chipseq tracks black.

  • chipseq_track_labels (list of str, optional) – Parallel to chipseq_tracks, the ith string will be used to label the ith chipseq track.

  • domains (list of dict, optional) –

    Each dict should represent one domain and should have the form:

    {
        'chrom': str,
        'start': int,
        'end': int
    }
    

  • domain_color (str) – The color to use to outline the domains.

  • clusters (list of lists of dicts, optional) –

    Each inner list should describe one cluster to be outlined. Each cluster is a list of dicts of the form:

    {
        'x': int,
        'y': int
    }
    

    where these integers represent indices of matrix.

  • cluster_colors (list of str, optional) – Parallel to clusters, the ith string should indicate the color to use to outline the ith cluster. Pass None to outline all clusters in green.

  • kwargs (kwargs) – Typical plotter kwargs.

Returns

The resulting ExtendableHeatmap.

Return type

lib5c.plotters.extendable.ExtendableHeatmap