SeqLogo Functions

By Malcolm McLean homepage

This is a C-callable function to produce a sequence logo.


Sequence logos were invented by Schneider and Stephens in 1990. They show DNA binding sites or consenus sequences, with the weight of the sequence represented by the size of the letter. Letter sizes are scaled by by the Shannon entropy of the column in the Position-Weight Matrix.

1 2 3 4 5 6 7
A 0.17 0.80 0.00 0.50 0.10 0.90 0.00
C 0.17 0.00 0.00 0.40 0.90 0.03 0.30
G 0.10 0.20 1.00 0.00 0.00 0.03 0.30
T 0.56 0.00 0.00 0.10 0.00 0.04 0.40
The sequence logo

A program to generate sequence logos is available on the web . There is also a standalong program, Delila , which is written in Pascal. There is a need for a C-callable function to create sequence logos, to be incorporated into any program which can accept the C interface.

Function documentation

unsigned char *seqlogo(double *pwm, int Nbases, int width, int height);

Probably the only function that you need. Call with a position-weight matrix, with the columns of the matrix minor, i.e. in the form A1, C1, G1, T1, A2, C2, G2, T2, A3 ... The columns must all sum to unity and contain no negative values. Also pass in the number of bases in the matrix, and the width and height of logo that you want. Width is typically Nbases * 16, height typically 128. The function returns a malloced 24-bit rgb buffer containing the logo, or 0 on fail.

int *getheightsfrompwm(double *pwm, int Nbases, int maxheight);
unsigned char *getlogofromheights(int *heights, int Nbases, int width, int height);

These two functions are made public to give you more control over the logo if you desire. The fucntion getheightsfrompwm() returns the height of each letter, in pixels, in a matrix the same size as the position weight matrix. maxheight is the height of a full letter (1.0 in the pwm). Typically this will be slightly less than the height of the logo. The function getlogofromheights() creates the logo, width and height refer to the width and height of the logo, in pixels. Call this function directly if you want to manipulate the letter heights for some reason.

void setseqlogocolor(char letter, unsigned char red, unsigned char green, unsigned char blue);

Call this function to set the colour used for each letter. Default is A - green, C - blue, G - yellow, T - red. Colour is held as a global state.



Crooks GE, Hon G, Chandonia JM, Brenner SE WebLogo: A sequence logo generator,
Genome Research, 14:1188-1190, (2004) [Full Text ]

Schneider TD, Stephens RM. 1990. Sequence Logos: A New Way to Display Consensus Sequences. Nucleic Acids Res. 18:6097-6100