Charts/Diagram charts
Sequence Logo
<SequenceLogo /> · 10 examples
Stacks of letters whose height says how conserved each position of a set of aligned sequences is.
Overview
Imagine two hundred strings of DNA, each twenty letters long, all of which a protein happily binds to. You line them up and stare. Position 7 is almost always a G. Position 12 is a coin toss between A and T. Position 3 is whatever. A consensus sequence would say GATTACA-something and throw away everything you just noticed about the confidence at each spot.
A sequence logo keeps that confidence. At each position it draws a stack of the letters that occur there, each letter as tall as its frequency times the information the column carries, with the most common letter on top. The whole stack's height is a number in bits: how much the position tells you beyond random chance. Tall stacks are the places where evolution refused to compromise. Short, messy ones are the places it did not care. Thomas Schneider and Mike Stephens introduced the format in 1990 and it has appeared on the front of a remarkable number of papers since.
The logo is a bar chart that has swallowed its own labels. The letters are the bars, and the only thing you need to know to read it is that tall means "this position matters".
Props
API
<SequenceLogo data={alignment} sequence={|r: &Read| r.sequence.as_str()} />| Prop | Type | Default |
|---|---|---|
data | one row per aligned sequence | required |
sequence | Fn(&T) -> &str | required |
alphabet | LogoAlphabet::Auto, Dna, Rna or Protein | Auto |
units | LogoUnits::Bits or Probability | Bits |
start | i64: the first position's number | 1 |
correction | bool: small-sample correction | true |
Each column stacks its letters, largest on top. In bits, a column's height is its information content, log₂(alphabet size) − entropy − correction, and letters split it by frequency. DNA and RNA letters are vector glyphs stretched to their height. Amino acids are coloured by chemistry. Gaps and unknown letters are skipped.
Run them
10 examples
Press Run to load an example into the live render at the top of the page. Open one to read its code.
How to read it
- 01Read the vertical axis: it is in bits and its top is the most any position can carry (2 bits for DNA, about 4.3 for protein).
- 02Look at stack height. A tall stack is a conserved position. A flat one means anything goes.
- 03Look inside a stack. The letter on top is the most common one, and a stack of two letters of roughly equal height is a position that can be either.
- 04Use the position numbers along the bottom, which start at
start(default 1) and can be set to match a gene or a motif numbering. - 05Hover a letter to see its frequency and its height in bits.
When to use it, and when not to
Reach for it when
- You have a set of aligned sequences (binding sites, motifs, a protein family) and want to show which positions are conserved and what the variants are.
- A consensus string would hide the confidence. The logo shows it, and a position that is 60/40 does not get flattened to one letter.
- You want to see at a glance which positions matter: tall stacks are constrained, short ones are free.
- You are comparing motifs from different experiments. Put logos in the same units and the same scale and read the shapes.
Skip it when
- The sequences are not aligned. A logo assumes that column means the same thing in every row. Unaligned sequences produce confident nonsense.
- You have only a handful of sequences. The small-sample correction will flatten the logo, and any single mutation looks like a trend. Show the raw alignment instead.
- You need to show statistical significance. A logo is a summary, not a test.
- The sequences are very long (hundreds of positions). Letters shrink to nothing. Break the sequence into windows.
The math behind it
Counting
Take aligned sequences, uppercased, over an alphabet of size : for DNA and RNA, for protein. By default the alphabet is detected: DNA if every letter is in ACGT, RNA if every letter is in ACGU, protein otherwise. At each position the chart counts how often each letter occurs. Characters outside the alphabet, such as gap dashes, are ignored at that position, so is the number of valid letters there, not necessarily . A position with no valid letters is left empty.
The width of the chart is the length of the longest sequence. Shorter sequences simply contribute nothing at the positions they lack.
Information content
The uncertainty of a column is its Shannon entropy) in bits. A column where all letters are equally likely has the maximum entropy ( bits for DNA, about for protein). A column with one letter has zero. The information at a position is how far it sits below the maximum.
A small sample lies in a particular way: with few sequences, a column can look conserved by chance. The chart applies the small-sample correction from Schneider's original paper, on by default (correction), and clamps the result at zero. This is why a logo built from five sequences looks short and one from five hundred looks tall at the same conserved positions. The comparison is against a uniform background. There is no adjustment for the base composition of the genome.
From bits to letters
Each letter's height in a stack is its share of the column times the column's information. The stack always sums to , and the tallest letters sit on top, with the smallest at the baseline (they are sorted by height, ascending, from the bottom up). The vertical axis runs from to , with a tick at each whole bit.
Letters are drawn as real glyph shapes for A, C, G, T and U, scaled to fill their box: a letter as wide as its column and as tall as its height. Letters under half a pixel tall are skipped. With units set to probability instead of bits, heights are just and the axis runs from to , which shows frequency instead of information.
Real life usage
The consensus that was only 60 percent sure
Ayesha was a second-year PhD student in a lab that studied how a soil bacterium turned on its antibiotic genes. She had 84 short DNA sequences that a certain regulatory protein bound, pulled from the genome after a long and expensive experiment. Her advisor wanted a figure, and the figure had to explain, in half a column, what the protein looked for.
The honest version of that figure is a consensus, and she wrote it down: TGTGA, a gap, then TCACA. The advisor looked at it and asked how sure she was about each letter. She said "fairly", which is the kind of answer that gets a student a longer meeting.
She needed to show the confidence at each of the 20 positions, along with the alternatives that really occurred, in one panel and without a table of counts. Anything less and a reviewer would ask for the table anyway.
She put the sequences into <SequenceLogo> from zopra-charts, set start to -10 so the numbers would match the transcription start, and left the alphabet on auto. The stacks came up like a skyline: a tall run of five letters at the left, a flat marshland in the middle, and five tall letters on the right, nearly a mirror of the first five.
She had expected the left side to be strong. What she had not expected was that position 4, which she had written as a confident G in the consensus, was a stack of G on top and a thick slab of A beneath, almost 40% of the sequences. Her consensus had been a plausible lie. The logo was the first thing that made the protein look like a real, slightly sloppy protein.
The figure went into the paper as the first panel. A reviewer said it was "unusually informative", which Ayesha has framed. Her advisor stopped asking how sure she was and started asking what the A did.
Two years later, someone mutated it, and the answer was in the logo all along.
Pitfalls
- Alignment is your job. The chart takes the position in the string as the column. A single insertion shifts everything after it and washes out the logo.
- Gaps and other characters are ignored. A dash or an N does not count as a letter in the column, which means a position full of gaps can look as conserved as a position full of data. Check the counts.
- Few sequences, short logo. The small-sample correction deliberately lowers the height when you have little data. Turn it off only if you know why.
- Bits are against a uniform background. There is no correction for an AT-rich or GC-rich genome, so a column of A in an AT-rich genome looks more informative than it is.
- Units change the story. With
Probabilitythe stack height is frequency, not information, and every column reaches the top.
From around the web