Logomaker: beautiful sequence logos in Python

Abstract Summary Sequence logos are visually compelling ways of illustrating the biological properties of DNA, RNA and protein sequences, yet it is currently difficult to generate and customize such logos within the Python programming environment. Here we introduce Logomaker, a Python API for creating publication-quality sequence logos. Logomaker can produce both standard and highly customized logos from either a matrix-like array of numbers or a multiple-sequence alignment. Logos are rendered as native matplotlib objects that are easy to stylize and incorporate into multi-panel figures. Availability and implementation Logomaker can be installed using the pip package manager and is compatible with both Python 2.7 and Python 3.6. Documentation is provided at http://logomaker.readthedocs.io; source code is available at http://github.com/jbkinney/logomaker.


Introduction
Sequence logos provide evocative graphical representations of the functional properties of DNA, RNA and protein sequences. Logos consist of characters stacked upon one another at a series of integervalued positions, with the height of each character conveying some type of information about its biological importance. This graphical representation was introduced by Schneider and Stephens (1990) for illustrating statistical properties of multiple-sequence alignments. Although the specific representation they advocated is still widely used, sequence logos have since evolved into a general data visualization strategy that can be used to illustrate many different kinds of biological information (Kinney and McCandlish, 2019). For example, logos can be used to illustrate base-pair-specific contributions to protein-DNA binding energy (Foat et al., 2006), the effects of mutations in massively parallel selection experiments, and attribution method visualizations of deep neural networks (Jaganathan et al., 2019;Shrikumar et al., 2017).
A substantial number of software tools for generating sequence logos have been described (Bailey et al., 2009;Colaert et al., 2009;Crooks et al., 2004;Gorodkin et al., 1997;Maddelein et al., 2015;Menzel et al., 2012;Nettling et al., 2015;Olsen et al., 2013;O'Shea et al., 2013;Ou et al., 2018;Rapin et al., 2010;Schuster-Bö ckler et al., 2004;Sharma et al., 2012;Thomsen and Nielsen, 2012;Waese et al., 2016;Wheeler et al., 2014;Workman et al., 2005;Wu and Bartel, 2017;Ye et al., 2017;Yu et al., 2015). However, each of these tools substantially limits the kinds of logos that one can make and the ways in which those logos can be styled. For example, WebLogo (Crooks et al., 2004) was one of the first logo-generating tools to be described and is still perhaps the most widely used. WebLogo allows users to create two standard types of sequence logos (information logos and probability logos) from a list of input sequences. However, it does not allow one to generate logos from arbitrary matrices of character heights. This capability is needed for illustrating the DDG values of energy matrix models (Fig. 1B), the log-enrichment values obtained in high-throughput selection experiments ( Fig. 1E) or importance scores that describe the predictions of deep neural networks (Fig. 1F). Moreover, although WebLogo is available as a Python package, the graphics it generates are written directly to file. This prevents logos from being customized using the matplotlib routines familiar to most Python users, or automatically incorporated into multi-panel figures.
In contrast to WebLogo and the other tools described above, ggseqlogo (Wagih, 2017) enables the creation of sequence logos within the R programming environment from arbitrary userprovided data. Importantly, ggseqlogo renders logos using native vector graphics, which facilitates post-hoc styling and the incorporation of logos into multi-panel figures. However, similar software is not yet available in Python. Because many biological data analysis pipelines are written in Python, there is a clear need for such logogenerating capabilities. Here we describe Logomaker, a Python package that addresses this need.

Implementation
Logomaker is a flexible Python API for creating sequence logos. Logomaker takes a pandas DataFrame as input, one in which columns represent characters, rows represent positions and values represent character heights (Fig. 1A). This enables the creation of logos for any type of data that are amenable to such a representation. The resulting logo is drawn using vector graphics embedded within a standard matplotlib Axes object, thus facilitating a high level of customization as well as incorporation into complex figures. Indeed, Applications Note the logos in Figure 1 were generated as part of a single multi-panel matplotlib figure. Logomaker provides a variety of options for styling the characters within a logo, including the choice of font, color scheme, vertical and horizontal padding, etc. Logomaker also enables the highlighting of specific sequences within a logo (Fig. 1E), as well as the use of value-specific transparency in logos that illustrate probabilities (Fig. 1C). If desired, users can further customize individual characters within any rendered logo. Because sequence logos are still commonly used to represent the statistics of multiple-sequence alignments, Logomaker provides methods for processing such alignments into matrices that can then be used to generate logos. Multiple types of matrices can be generated in this way, including matrices that represent probabilities (Fig. 1C), log odds ratios (Fig. 1E) or the information values described by Schneider and Stephens (1990) (Fig. 1D). Methods for transforming between these types of matrices are also provided. Finally, Logomaker supports the creation of masked matrices and logos that, e.g., represent deep neural network importance scores (Shrikumar et al., 2017), as in Figure 1F.

Conclusion
Logomaker thus fills a major need in the Python community for flexible logo-generating software. Indeed, Logomaker has already been used to generate logos for multiple preprints and publications (Belliveau et al., 2018;Barnes et al., 2019;Forcier et al., 2018;Kinney and McCandlish, 2019;Mason et al., 2019;Nguyen et al., 2019;Wong et al., 2018). Logomaker is thoroughly tested, has minimal dependencies and can be installed from PyPI by executing 'pip install logomaker' at the command line. A step-by-step tutorial on how to use Logomaker, as well as comprehensive documentation, is available at http://logomaker.readthedocs.io.