Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
genome-spy-python
Logo
genome-spy-python
  • Getting started
  • User guide
    • Data and chart inputs
    • Charts and marks
    • Encodings and channels
    • Scales, axes, and legends
    • Transforms
    • Composition
    • Import remote view specifications
    • Configuration
    • Chromosomes and locus scales
    • Large and indexed genomic data
    • Build linked genome tracks
    • Label points and genomic intervals
    • Parameters and interaction
    • Create and update charts in notebooks
    • Display controls and embed options
    • Save and inspect charts
  • Gallery
    • Manhattan plot
    • Brush-linked genome tracks
    • Volcano plot
    • MA plot
    • Volcano plot
    • Genome tracks with gene annotations
    • Stacked genome browser tracks
    • Sashimi plot
    • BAM read alignments
    • Dynseq binding-QTL tracks
    • Composing a genome browser
    • Chromosome ideogram
    • GFF3 gene annotations
    • RefSeq genes with scored labels
    • BigBed cCRE track
    • Indexed FASTA six-frame translation
    • Indexed FASTA sequence track
    • Multiple sequence alignment
    • P53 multiple-sequence alignment with an overview brush
    • Lollipop plot
    • PIK3CA mutation lollipop plot
    • Rainfall plot
    • ClinVar variants track
    • Oncoplot
    • LAML oncoplot with clinical and pathway annotations
    • LUAD oncoprint
    • Set intersections with an UpSet plot
    • Copy-number profile
    • ASCAT copy-number segmentation
    • Interactive ASCAT purity/ploidy fitting
    • HCC1954 structural variants and copy number
    • TCGA ovarian cancer GISTIC landscape
    • Point mark
    • Rect heatmap
    • Ranged rule mark
    • Link mark
    • Sequence logo
    • Vertical concatenation
    • Scrollable viewport
  • Example datasets
  • API reference
    • genome_spy.Chart
    • genome_spy.ConcatChart
    • genome_spy.HConcatChart
    • genome_spy.ImportedView
    • genome_spy.LayerChart
    • genome_spy.MultiscaleChart
    • genome_spy.TopLevelSpec
    • genome_spy.VConcatChart
    • genome_spy.Angle
    • genome_spy.Color
    • genome_spy.Direction
    • genome_spy.Dx
    • genome_spy.Dy
    • genome_spy.FacetIndex
    • genome_spy.Fill
    • genome_spy.FillOpacity
    • genome_spy.Key
    • genome_spy.Locus
    • genome_spy.Opacity
    • genome_spy.Sample
    • genome_spy.Search
    • genome_spy.SemanticScore
    • genome_spy.Shape
    • genome_spy.Size
    • genome_spy.Stroke
    • genome_spy.StrokeOpacity
    • genome_spy.StrokeWidth
    • genome_spy.Text
    • genome_spy.Tooltip
    • genome_spy.UniqueId
    • genome_spy.X
    • genome_spy.X2
    • genome_spy.XOffset
    • genome_spy.Y
    • genome_spy.Y2
    • genome_spy.YOffset
    • genome_spy.axes
    • genome_spy.binding
    • genome_spy.binding_checkbox
    • genome_spy.binding_radio
    • genome_spy.binding_range
    • genome_spy.binding_select
    • genome_spy.compare
    • genome_spy.concat
    • genome_spy.condition
    • genome_spy.config
    • genome_spy.data_format
    • genome_spy.datum
    • genome_spy.dynamic_opacity
    • genome_spy.expr
    • genome_spy.hconcat
    • genome_spy.import_view
    • genome_spy.layer
    • genome_spy.locus
    • genome_spy.multiscale
    • genome_spy.param
    • genome_spy.parse
    • genome_spy.ruler
    • genome_spy.scales
    • genome_spy.selection_interval
    • genome_spy.selection_point
    • genome_spy.step
    • genome_spy.title
    • genome_spy.to_arrow_ipc
    • genome_spy.value
    • genome_spy.vconcat
    • genome_spy.view
    • genome_spy.view_config
    • genome_spy.when
    • genome_spy.AxisGenomeData
    • genome_spy.BrushConfig
    • genome_spy.Data
    • genome_spy.DataFormat
    • genome_spy.DynamicOpacity
    • genome_spy.ExprRef
    • genome_spy.Expression
    • genome_spy.GenomeAxis
    • genome_spy.HandledTooltip
    • genome_spy.Legend
    • genome_spy.Paddings
    • genome_spy.Parameter
    • genome_spy.Parse
    • genome_spy.RulerMarkConfig
    • genome_spy.Scale
    • genome_spy.SelectionDomainRef
    • genome_spy.SizeDef
    • genome_spy.Step
    • genome_spy.Title
    • genome_spy.data.LazyNamespace
    • genome_spy.data_transformers.DataTransformerSettings
    • genome_spy.datasets.available_datasets
    • genome_spy.datasets.load_dataset
    • genome_spy.datasets.DatasetNotFoundError
    • genome_spy.JupyterChart
  • About
Back to top

Sequence logo¶

Letter marks are stacked by information content to show a compact sequence motif summary.

Code¶

"""Sequence logo.

Letter marks are stacked by information content to show a compact sequence
motif summary.
"""

import genome_spy as gs
from genome_spy.datasets._grammar import sequence_logo_data
from genome_spy.schema import Scale


# Load example base counts at each position.
data = sequence_logo_data()

base_colors = Scale(
    domain=["A", "C", "T", "G"],
    range=["#7bd56c", "#ff9b9b", "#86bbf1", "#ffc56c"],
)

# Stack the base letters: taller stacks indicate more consistent positions.
chart = (
    gs.Chart(data)
    .transform_stack(
        field="count",
        groupby=["pos"],
        offset="information",
        as_=["_y0", "_y1"],
        baseField="base",
        sort=gs.compare("count", order="ascending"),
    )
    # Stretch each letter to fill its share of the stack.
    .mark_text(
        font="Source Sans Pro",
        fontWeight=700,
        size=90,
        squeeze=True,
        fitToBand=True,
        paddingX=0,
        paddingY=0,
        logoLetters=True,
    )
    .encode(
        x=gs.X("pos:O").title("Position"),
        y=gs.Y("_y0:Q").scale(domain=[0, 2], zoom=True).title("Information"),
        y2=gs.Y2("_y1"),
        text=gs.Text("base:N"),
        color=gs.Color("base:N").scale(base_colors).legend(None),
    )
    .properties(title="Sequence logo")
)
Next
Vertical concatenation
Previous
Link mark
Copyright © genome-spy-python contributors
Made with Sphinx and @pradyunsg's Furo
On this page
  • Sequence logo
    • Code