colors

Utilities for manipulating colors.

BNF

<sequence-color-spec> ::=
    {
        "A": <color-spec>,
        "C": <color-spec>,
        "G": <color-spec>,
        "T": <color-spec>
    }
<color-spec> ::=
    {"rgb": [<number>, <number>, <number>]}
  | {"rgba": [<number>, <number>, <number>, <number>]}
  | {"tol": <integer>}
  | {"tol-light": <integer>}
  | {"ibm": <integer>}
  | {"wong": <integer>}
  | [<number>, <number>, <number>«, <number>»]
<list-of-sequence-color-spec> ::=
    <sequence-color-spec>«, <list-of-sequence-color-spec
<list-of-color-spec> ::=
    <color-spec>«, <list-of-color-spec
bpreveal.colors.tol: tuple[tuple[float, float, float] | tuple[float, float, float, float], ...]

The muted color scheme by Paul Tol.

../_images/tol.png
Type:

tuple[RGB_T, …]

bpreveal.colors.ibm: tuple[tuple[float, float, float] | tuple[float, float, float, float], ...]

The IBM design library’s color blind palette.

../_images/ibm.png
Type:

tuple[RGB_T, …]

bpreveal.colors.wong: tuple[tuple[float, float, float] | tuple[float, float, float, float], ...]

Bang Wong’s palette. Used for DNA.

../_images/wong.png
Type:

tuple[RGB_T, …]

bpreveal.colors.tolLight: tuple[tuple[float, float, float] | tuple[float, float, float, float], ...]

The light color scheme by Paul Tol, but with light blue and olive deleted.

../_images/tolLight.png
Type:

tuple[RGB_T, …]

bpreveal.colors.dnaWong: DNA_COLOR_SPEC_T = {'A': {'wong': 3}, 'C': {'wong': 5}, 'G': {'wong': 4}, 'T': {'wong': 6}, 'd': {'wong': 0}, 'r': {'wong': 7}, 'Č': {'tol-light': 0}, 'ř': {'tol-light': 5}, 'Ť': {'tol-light': 4}, 'Ǎ': {'tol-light': 1}, 'Ǧ': {'tol-light': 3}}

The default color map for DNA bases.

A is green, C is blue, G is yellow, and T is red. Deletions are black. Insertions are lighter shades of the corresponding base. Random mutations are pink.

bpreveal.colors.defaultProfile: dict[Literal['rgb'], tuple[float, float, float]] | dict[Literal['rgba'], tuple[float, float, float, float]] | dict[Literal['tol'], int] | dict[Literal['tol-light'], int] | dict[Literal['ibm'], int] | dict[Literal['wong'], int] | tuple[float, float, float] | tuple[float, float, float, float]

The default color for profile plots. It’s tol[0].

Type:

COLOR_SPEC_T

bpreveal.colors.pisaClip = <matplotlib.colors.ListedColormap object>

The color map used for PISA plots, including green and pink clipping colors.

../_images/pisaClip.png
bpreveal.colors.pisaNoClip = <matplotlib.colors.ListedColormap object>

The color map for PISA plots but without the clipping warning colors.

../_images/pisaNoClip.png
bpreveal.colors.getGraphCmap(minValue, colorSpan, baseCmap)

Remove the central portion of a color map for PISA graphs.

Parameters:
  • minValue (float) – The value (in logit space) below which no lines will be drawn in the PISA graph. This is the region of the returned color map that will be white.

  • colorSpan (float) – The total range of the color map. Lines with higher PISA scores than colorSpan will be clipped to the extreme values of the color map.

  • baseCmap (Colormap) – The colormap to modify. This will be either pisaClip or pisaNoClip, or you may provide your own Colormap object.

Returns:

A new color map that can be used to color lines in a PISA graph.

Return type:

Colormap

bpreveal.colors.parseSpec(colorSpec)

Given a color-spec (See the BNF), convert it into an rgb or rgba tuple.

Parameters:

colorSpec (COLOR_SPEC_T | str) – The color specification.

Raises:

ValueError – if you provided an invalid spec.

Returns:

An rgb triple (or rgba quadruple).

Return type:

tuple[float, float, float] | tuple[float, float, float, float]

Based on the shape of colorSpec, this function interprets it differently. If colorSpec is a…

3-tuple

it is interpreted as an rgb color,

4-tuple

it is interpreted as rgba,

{"rgb": (0.1, 0.2, 0.3)}

it is interpreted as an rgb color,

{"rgba": (0.1, 0.2, 0.3, 0.8)}

it is interpreted as an rgba color,

{"<palette-name>": 3}

where <palette-name> is one of “tol”, “tol-light”, “wong”, or “ibm”), then the value is the color i in the corresponding palette.

"b"

or any other string, then it is interpreted as a matplotlib color string and is passed to matplotlib.colors.to_rgb.

bpreveal.colors.loadFonts(serif=True)

Configure the matplotlib default fonts to be in the Libertinus family.

Parameters:

serif (bool) – Should a serif font be used? The default is True, and this will use the Libertinus font family. If False, then instead the Fira Sans font family will be used.

Return type:

None

This places the given font (Libertinus or Fira Sans) at the top of the order for serif and sans-serif fontfamily, but does not overwrite the monospace family. It also sets the pdf backend to save text boxes rather than individual letters so that text can be easily edited later.