Class Motif - Documentation

March 12, 2018 ยท View on GitHub

The Motif class is a convenience class to compute and plot a position-weight matrix (PWM). The only functionality is the plot function. The PWM and corresponding entropy values can be accessed using the self.pwm and self.entropies members, if so desired. All uppercase alphanumeric characters and the following additional characters can be part of the alphabet: "()[]{}<>,.|*".

Methods - Overview

namedescription
__init__Initialize a motif by providing sequences or a PWM.
plotPlot the motif.

__init__

def __init__(self, alphabet, sequences = None, pwm = None)

Initialize a motif by providing sequences or a PWM.

Either a list of sequences or a PWM with shape (sequence length, alphabet length) must be provided.

parametertypedescription
alphabetstrThe alphabet of the sequences.
sequences[str]A list of strings. All strings must have the same length.
pwmnumpy.ndarrayA matrix of shape (sequence length, alphabet length) containing probabilities.

plot

def plot(self, colors={}, scale=1)

Plot the motif.

The color of individual letters can be defined via the colors dict using RGB values, e.g. {'A': '#FF0000', 'C': '#0000FF'} will result in red A's and blue C's. Non-defined characters will be plotted black.

The alphabets 'ACGT', 'ACGU', and 'HIMS' have predefined colors (that can be overwritten):

"ACGT" -> {'A': '#00CC00', 'C': '#0000CC', 'G': '#FFB300', 'T': '#CC0000'}
"ACGU" -> {'A': '#00CC00', 'C': '#0000CC', 'G': '#FFB300', 'U': '#CC0000'}
"HIMS" -> {'H': '#CC0000', 'I': '#FFB300', 'M': '#00CC00', 'S': '#CC00FF'}

Using, for instance, a scale parameter of 0.5 halves both height and width of the plot.

parametertypedescription
colorsdict of char->strA dict with individual alphabet characters as keys and hexadecimal RGB specifiers as values.
scalefloatAdjust the size of the plot (should be > 0).
returnstypedescription
imagePIL.image.imageA Pillow image object.