Skip to main content

An optimized batch logo generation library for sequence logos

Project description

Fast Logomaker

An optimized batch logo generation library for sequence logos. This is an optimized version of the original Logomaker package by Ammar Tareen and Justin Kinney.

Installation

pip install fast-logomaker

Features

  • Efficient batch processing of multiple logos
  • Path caching for improved performance
  • Minimized object creation
  • Optimized transformation operations

Performance

Implementation Speed
Original Logomaker ~2 seconds per logo (249 × 4 matrix)
Fast Logomaker ~0.013 seconds per logo (1000 logos in 13 seconds)

Quick Start

import numpy as np
from fast_logomaker import FastLogo

# Create sample data (N logos, L positions, 4 nucleotides)
values = np.random.randn(10, 50, 4)  # 10 logos, 50 positions, ACGT

# Create FastLogo processor
logo = FastLogo(values)

# Process all logos
logo.process_all()

# Draw a single logo
fig, ax = logo.draw_single(0)

# Draw multiple logos in a grid
fig, axes = logo.draw_logos(indices=[0, 1, 2], rows=1, cols=3)

API Reference

FastLogo

from fast_logomaker import FastLogo

FastLogo(
    values,                    # numpy array of shape (N, L, alphabet_size)
    alphabet=None,             # list of characters, default ['A', 'C', 'G', 'T']
    figsize=[10, 2.5],         # figure size for single logos
    batch_size=50,             # batch size for processing
    font_name='sans',          # font family (e.g., 'Arial Rounded MT Bold')
    color_scheme='classic',    # color scheme name or dict
    y_min_max=None,            # fixed y-axis limits (min, max)
    show_progress=True,        # show progress bar during processing
    center_values=False,       # center values at each position
    fade_below=0.5,            # alpha fade for negative values
    shade_below=0.5,           # color shade for negative values
    fade_above=0,              # alpha fade for positive values
    shade_above=0,             # color shade for positive values
    width=0.9,                 # character width
    **kwargs
)

Methods

process_all()

Process all logos in batches. Must be called before drawing.

logo.process_all()

draw_single(idx, ...)

Draw a single logo with optional highlighting and view window.

fig, ax = logo.draw_single(
    idx,                           # logo index to draw
    fixed_ylim=True,               # use consistent y-limits across logos
    view_window=None,              # [start, end] positions to zoom into
    figsize=None,                  # override figure size
    border=True,                   # show axis border
    highlight_ranges=None,         # list of (start, end) tuples or position lists
    highlight_colors=None,         # colors for highlights
    highlight_alpha=0.5,           # transparency for highlights
    ax=None                        # existing axes to draw on
)

draw_logos(indices, rows, cols)

Draw multiple logos in a grid layout.

fig, axes = logo.draw_logos(
    indices=None,    # list of indices, or None for all
    rows=None,       # number of rows (auto if None)
    cols=None        # number of columns (auto if None)
)

draw_variability_logo(...)

Draw a variability logo showing all glyphs from all logos overlaid at each position.

fig, ax = logo.draw_variability_logo(
    view_window=None,    # [start, end] positions to view
    figsize=None,        # figure size
    border=True          # show axis border
)

style_glyphs_in_sequence(sequence, color)

Style glyphs that match a reference sequence in a specified color, with non-matching glyphs in dark gray.

logo.style_glyphs_in_sequence(
    sequence='ACGTACGT',      # reference sequence string
    color='darkorange'        # color for matching glyphs
)

Examples

Attribution Logo with Centered Values

from fast_logomaker import FastLogo

# Attribution values (can be positive and negative)
attributions = np.random.randn(1, 100, 4)

logo = FastLogo(
    attributions,
    alphabet=['A', 'C', 'G', 'T'],
    font_name='Arial Rounded MT Bold',
    fade_below=0.5,
    shade_below=0.5,
    width=0.9,
    figsize=[20, 2.5],
    center_values=True,
    batch_size=1
)

logo.process_all()
fig, ax = logo.draw_single(0, border=False)

View Window and Highlighting

# Zoom into positions 50-100 and highlight specific regions
fig, ax = logo.draw_single(
    0,
    view_window=[50, 100],
    highlight_ranges=[(60, 70), (80, 90)],
    highlight_colors=['lightcyan', 'honeydew'],
    highlight_alpha=0.5
)

Fixed Y-Axis Limits Across Multiple Logos

# Compute global y-limits from all logos
logo.process_all()

# Set consistent y-limits for comparison
logo.y_min_max = (-2, 2)

# Draw logos with fixed y-axis
for i in range(logo.N):
    fig, ax = logo.draw_single(i, fixed_ylim=True)
    fig.savefig(f'logo_{i}.png')

Variability Logo

# Show overlap of multiple logos at each position
fig, ax = logo.draw_variability_logo(
    figsize=(20, 2.5),
    view_window=[50, 150]
)

Color Schemes

Built-in color schemes for DNA/RNA:

  • classic - Standard DNA colors (A=green, C=blue, G=orange, T=red)
  • grays - Grayscale
  • colorblind_safe - Colorblind-friendly palette
  • base_pairing - Colors by base pairing

Built-in color schemes for proteins:

  • weblogo_protein - WebLogo protein colors
  • skylign_protein - Skylign protein colors
  • dmslogo_charge - Charge-based coloring
  • dmslogo_funcgroup - Functional group coloring
  • hydrophobicity - Hydrophobicity-based coloring
  • chemistry - Chemistry-based coloring
  • charge - Charge-based coloring
  • NajafabadiEtAl2017 - From Najafabadi et al. 2017

List Available Color Schemes

from fast_logomaker import list_color_schemes

schemes = list_color_schemes()
print(schemes)

Custom Color Scheme

custom_colors = {
    'A': '#FF0000',  # red
    'C': '#00FF00',  # green
    'G': '#0000FF',  # blue
    'T': '#FFFF00'   # yellow
}

logo = FastLogo(values, color_scheme=custom_colors)

Migration from seam.logomaker_batch

If you were using BatchLogo from seam, you can use FastLogo (recommended) or keep using BatchLogo as an alias:

# Before
from seam.logomaker_batch.batch_logo import BatchLogo

# After (recommended)
from fast_logomaker import FastLogo

# After (backwards compatible alias)
from fast_logomaker import BatchLogo

All parameters and methods remain the same.

Credits

  • Original Logomaker: Ammar Tareen and Justin Kinney, 2019-2024
  • Batch processing optimization: Evan Seitz, 2025

For the original package and documentation, visit: https://github.com/jbkinney/logomaker

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_logomaker-0.1.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_logomaker-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file fast_logomaker-0.1.0.tar.gz.

File metadata

  • Download URL: fast_logomaker-0.1.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for fast_logomaker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e4dbac2cd8f1b7fa1bce64455f9fa64a35bbdf6ea4ca60f5076570d1c340547
MD5 decce04fefb6613b771a654c3bdbdf3d
BLAKE2b-256 cb1a51776f49767b342829071d9270f3b6bb939e9dbbaae253274a016a0816da

See more details on using hashes here.

File details

Details for the file fast_logomaker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fast_logomaker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for fast_logomaker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 268d5f4a76fd32f72dd8fc133005aa07ff069464e392152f6bba6d0e85448563
MD5 948c7410862aa7b49a9d4cec4235f6b4
BLAKE2b-256 da55480d6cf63736591770d92545617114142dca75bc0a31f92213d77f80318f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page