vampire.anno.pl.logo_from_matrix

vampire.anno.pl.logo_from_matrix#

vampire.anno.pl.logo_from_matrix(matrix, *, letters, feature='information', colormap=None, conserved_color='#cccccc', title='', figsize=(None, None), save=None, **kwargs)[source]#

Plot the logo plot from 2D matrix, such as count matrix, frequency matrix and position weight matrix (PWM).

Parameters:
  • matrix (ndarray) –

    The 2D position-by-symbol matrix used to construct a sequence logo. Shape is (L, K). L = number of positions (x-axis, sequence length) K = number of symbols (defined by letters)

    matrix[i, j] gives the contribution (count/probability/information) of symbol letters[j] at position i.

  • letters (list[str]) – Symbols corresponding to matrix columns, e.g. [“A”, “C”, “G”, “T”, “-“].

  • feature (Literal['count', 'probability', 'information']) – The feature to use. Default is “information”.

  • colormap (dict | None) – The colors of the bases. Default is None, using default colormap.

  • conserved_color (str | None) – Override color for conserved sites (non-variant positions). Default is “#cccccc”. If set to None, conserved sites will use the general base color instead.

  • title (str) – The title of the plot. Default is empty.

  • figsize (tuple[int | None, int | None]) – Figure size as (width, height) in pixels. Default is (None, None).

  • save (str | bool | None) – If True or a str, save the figure.A string is appended to the default filename. Infer the filetype if ending on {'.pdf', '.png', '.svg'}.

  • **kwargs – Additional keyword arguments passed to Plotly update_layout. Used to control figure-level styling (e.g. template, margin, background color, legend settings).

Returns:

The logo figure.

Return type:

Figure

Examples

>>> import numpy as np
>>> import vampire as vp
>>> vp.anno.pl.set_default_plotstyle()
>>> vp.anno.pl.logo_from_matrix(
...     np.array([
...         [8, 1, 0, 1, 0, 0, 0],
...         [0, 7, 0, 0, 1, 2, 0],
...         [0, 0, 9, 0, 0, 0, 1],
...         [0, 2, 0, 7, 0, 1, 0],
...         [1, 1, 1, 0, 7, 0, 0],
...         [0, 1, 0, 1, 0, 8, 0],
...         [1, 0, 0, 1, 0, 0, 8],
...     ]),
...     feature = "count",
...     letters = ["V", "A", "M", "P", "I", "R", "E"],
...     colormap = {"V": "#f64021", "A": "#f98016", "M": "#ffff00", "P": "#00cc66", "I": "#496ddb", "R": "#7209b7", "E": "#a01a7d"}
... )