logo¶
Core logo-drawing functions of dmslogo.
Some of this code is borrowed and modified from pyseqlogo.
- class dmslogo.logo.Memoize(f)[source]¶
Bases:
object
Memoize function from https://stackoverflow.com/a/1988826
- class dmslogo.logo.Scale(sx, sy=None)[source]¶
Bases:
RendererBase
Scale letters using affine transformation.
From here: https://www.python-forum.de/viewtopic.php?t=30856
- dmslogo.logo.draw_logo(data, *, x_col, letter_col, letter_height_col, xtick_col=None, color_col=None, shade_color_col=None, shade_alpha_col=None, heatmap_overlays=None, xlabel=None, ylabel=None, title=None, colorscheme={'A': '#f76ab4', 'C': '#ff7f00', 'D': '#e41a1c', 'E': '#e41a1c', 'F': '#84380b', 'G': '#f76ab4', 'H': '#3c58e5', 'I': '#12ab0d', 'K': '#3c58e5', 'L': '#12ab0d', 'M': '#12ab0d', 'N': '#972aa8', 'P': '#12ab0d', 'Q': '#972aa8', 'R': '#3c58e5', 'S': '#ff7f00', 'T': '#ff7f00', 'V': '#12ab0d', 'W': '#84380b', 'Y': '#84380b'}, missing_color='gray', addbreaks=True, widthscale=1, heightscale=1, heatmap_overlay_height=0.15, axisfontscale=1, hide_axis=False, fontfamily='DejaVuSansMonoBold_SeqLogo', fontaspect=0.58, letterpad=0.0105, letterheightscale=0.96, ax=None, ylim_setter=None, fixed_ymin=None, fixed_ymax=None, clip_negative_heights=False, drop_na_letter_heights=True, draw_line_at_zero='if_negative')[source]¶
Draw sequence logo from specified letter heights.
- Args:
- data (pandas DataFrame)
Holds data to plot.
- letter_height_col (str)
Column in data with letter heights.
- letter_col (str)
Column in data with letter identities.
- x_col (str)
Column in data with integer site numbers.
- xtick_col (None or str)
Column in data used to label sites if not using x_col.
- color_col (None or str)
Column in data with colors for each letter; set to None to define colors via colorscheme and missing_color.
- shade_color_col (None or str)
Column in data indicating color to shade each site. Must be same color for all letters at site. If a site should not be shaded, set to something that evaluates to False or NaN.
- shade_alpha_col (None or str)
Column in data giving transparency of shading at each site.
- heatmap_overlays (None or list)
List of columns in data giving colors for each overlay.
- xlabel (None or str)
Label for x-axis if not using xtick_col or x_col.
- ylabel (None or str)
Label for y-axis if not using letter_height_col.
- title (None or str)
Title to place above plot.
- colorscheme (dict)
Color for each letter. Ignored if color_col is not None. See
dmslogo.colorschemes
for some color schemes.- missing_color (None or str)
Color for letters not assigned in colorscheme, or None to raise an error for unassigned letters.
- addbreaks (bool)
Anywhere there is a gap in sequential numbering of x_col, add break consisting of space and dashed line.
- widthscale (float)
Scale width by this much.
- heightscale (float)
Scale height by this much.
- heatmap_overlay_height (float)
Height of heatmap overlays relative to logo.
- axisfontscale (float)
Scale size of font for axis ticks and labels by this much.
- hide_axis (bool)
Do we hide the axis and tick labels?
- fontfamily (str)
Font to use (for logo letters).
- fontaspect (float)
Aspect ratio of logo letter font (height to width). If letters are too crowded, increase this.
- letterpad (float)
Add this much fixed vertical padding between letters as fraction of total stack height.
- letterheightscale (float)
Scale height of all letters by this much.
- ax (None or matplotlib axes.Axes object or list of Axes)
Use to plot on an existing axis. If using heatmap_overlays then must be list of axes of correct length.
- ylim_setter (None or
dmslogo.utils.AxLimSetter
) Object used to set y-limits. If None, a
dmslogo.utils.AxLimSetter
is created using default parameters). If fixed_ymin and/or fixed_ymax are set, they override the limits from this setter.- fixed_ymin (None or float)
If not None, then fixed y-axis minimum.
- fixed_ymax (None or float)
If not None, then fixed y-axis maximum.
- clip_negative_heights (bool)
Set to 0 any value in letter_height_col that is < 0.
- drop_na_letter_heights (bool)
Drop any rows in data where letter_height_col is NaN.
- draw_line_at_zero (str)
Draw a horizontal line at the value of zero? Can have following values: ‘if_negative’ to only draw line if there are negative letter heights, ‘always’ to always draw line, and ‘never’ to never draw line.
- Returns:
The 2-tuple (fig, ax) giving the figure and axis with the logo plots. If using heatmap_overlays, then ax will be an array of all axes (overlays and logo axes).