mkt.databases.colors

Color palettes and colormap helpers for amino acids and percentile-based plotting.

Defines the AminoAcidPalette, amino-acid-to-color mapping helpers, and utilities for interpolating colors and building percentile colormaps with legends.

Module Attributes

AA_MAPPING

Set of amino acid mappings (lower) to single-letter code and 3-letter code (upper)

DICT_COLORS

Mapping amino acid to color using specified dictionary.

DEFAULT_NULL_COLOR

Default color for null/zero values in colormaps.

DICT_QUARTILE_HEATMAP_COLORMAP

Quartile heatmap colormap for mutation visualization.

DICT_QUARTILE_HEATMAP_COLORMAP_PLASMA

Plasma-inspired colormap for mutation visualization.

DICT_QUARTILE_HEATMAP_COLORMAP_VIRIDIS

Viridis-inspired colormap for mutation visualization.

DICT_BIOCHEM_PROP_COLORS

Dictionary mapping biochemical properties to colors.

COLOR_DARK_TEXT

Near-black grey for axis labels, ticks, and logo text.

COLOR_CONSERVATION_PRIMARY

Primary conservation accent (>=threshold line; breakpoint node fill).

COLOR_CONSERVATION_SECONDARY

Secondary conservation accent.

CMAP_CRITICAL_DEPTH

Colormap for the per-KLIFS-column critical-depth track.

COLOR_DEPTH_NA

Grey for KLIFS columns that never survive up (no finite critical depth).

COLOR_TREE_BREAK

Tree node fill for a split that carries >=1 fixed-difference breakpoint.

COLOR_TREE_NO_BREAK

Tree node fill for a split with no fixed difference (structural only).

COLOR_TREE_MIXED_FAMILY

Branch color once a clade mixes families (not monophyletic).

COLOR_TREE_PSEUDO

Family color for a pseudokinase-pure clade (and inherited-conserved logo letters).

COLOR_LOGO_BAR

Neutral fill for the per-column logo frequency bars.

COLOR_LOGO_SUBTHRESHOLD

Logo letter color for residues present but below the conservation threshold.

COLOR_TREE_TABLE_NO_CONSENSUS

Static conservation-table cell fill where no residue is >=80% conserved in a leaf row.

COLOR_TREE_TABLE_GAP

Static conservation-table cell fill where a gap ('-') is the >=80% consensus -- a mid grey distinct from the blank no-consensus cell and from the amino-acid palette greys (I = #808080, E = #191919); paired with a '-' glyph to disambiguate.

COLOR_TREE_GUIDE

Thin guide line linking each dendrogram leaf to its conservation-table row.

COLOR_TREE_FALLBACK

Fallback fill for a tree leaf whose kinase has no group/family color.

COLOR_TREE_SPLIT_MARKER

Dashed marker on the summary dendrogram showing the top/bottom detail-panel split.

DICT_CONSURF_GRADE_COLORS

Canonical ConSurf 9-grade conservation palette (grade 1 = most variable teal, grade 9 = most conserved maroon).

COLOR_CONSURF_UNGRADED

ConSurf's 'insufficient data' color (RGB 255,255,150) for positions with no grade — an all-gap alignment column, or a group below the minimum size for grading.

Functions

generate_colormap_legend(color_stops[, ...])

Generate a vertical colormap legend image (SVG and PNG) from color stops.

get_consurf_grade_color(grade)

Return the ConSurf palette color for a conservation grade.

interpolate_color(norm_value, ...)

Interpolate between two colors based on normalized value.

map_aa_to_single_letter_code(aa)

Map any amino acid input from name or 3-letter or single-letter code to validated single-letter code.

map_single_letter_aa_to_color(aa, dict_color)

Map amino acid to color using specified dictionary.

percentile_colormap(values, color_stops[, ...])

Map numeric values to colors using percentile-based interpolation.

readable_text_color(color)

Return "black" or "white" for legible text on a background color.

Classes

AminoAcidPalette(value)

Enumeration of supported color palettes for amino acid visualization.

mkt.databases.colors.AA_MAPPING = [('alanine', 'A', 'ALA'), ('arginine', 'R', 'ARG'), ('asparagine', 'N', 'ASN'), ('aspartic acid', 'D', 'ASP'), ('cysteine', 'C', 'CYS'), ('glutamic acid', 'E', 'GLU'), ('glutamine', 'Q', 'GLN'), ('glycine', 'G', 'GLY'), ('histidine', 'H', 'HIS'), ('isoleucine', 'I', 'ILE'), ('leucine', 'L', 'LEU'), ('lysine', 'K', 'LYS'), ('methionine', 'M', 'MET'), ('phenylalanine', 'F', 'PHE'), ('proline', 'P', 'PRO'), ('serine', 'S', 'SER'), ('threonine', 'T', 'THR'), ('tryptophan', 'W', 'TRP'), ('tyrosine', 'Y', 'TYR'), ('valine', 'V', 'VAL')]

Set of amino acid mappings (lower) to single-letter code and 3-letter code (upper)

Type:

list[tuple[str, str, str]]

class mkt.databases.colors.AminoAcidPalette(value)[source]

Bases: str, Enum

Enumeration of supported color palettes for amino acid visualization.

ALPHABET_PROJECT = 'ALPHABET_PROJECT'
ASAP = 'ASAP'
CLUSTALX = 'CLUSTALX'
RASMOL = 'RASMOL'
SHAPELY = 'SHAPELY'
ZAPPO = 'ZAPPO'
mkt.databases.colors.CMAP_CRITICAL_DEPTH = 'plasma'

Colormap for the per-KLIFS-column critical-depth track.

mkt.databases.colors.COLOR_CONSERVATION_PRIMARY = '#2E5B9C'

Primary conservation accent (>=threshold line; breakpoint node fill).

mkt.databases.colors.COLOR_CONSERVATION_SECONDARY = '#7B3F8D'

Secondary conservation accent.

mkt.databases.colors.COLOR_CONSURF_UNGRADED = '#FFFF96'

ConSurf’s ‘insufficient data’ color (RGB 255,255,150) for positions with no grade — an all-gap alignment column, or a group below the minimum size for grading. Matches the grade-0 color in the ConSurf rasmol_gradesPE_and_pipe.pm.

mkt.databases.colors.COLOR_DARK_TEXT = '#2E2E2E'

Near-black grey for axis labels, ticks, and logo text.

mkt.databases.colors.COLOR_DEPTH_NA = '#D9D9D9'

Grey for KLIFS columns that never survive up (no finite critical depth).

mkt.databases.colors.COLOR_LOGO_BAR = '#EFEFEF'

Neutral fill for the per-column logo frequency bars.

mkt.databases.colors.COLOR_LOGO_SUBTHRESHOLD = '#C9C9C9'

Logo letter color for residues present but below the conservation threshold.

mkt.databases.colors.COLOR_TREE_BREAK = '#2E5B9C'

Tree node fill for a split that carries >=1 fixed-difference breakpoint.

mkt.databases.colors.COLOR_TREE_FALLBACK = '#999999'

Fallback fill for a tree leaf whose kinase has no group/family color.

mkt.databases.colors.COLOR_TREE_GUIDE = '#777777'

Thin guide line linking each dendrogram leaf to its conservation-table row.

mkt.databases.colors.COLOR_TREE_MIXED_FAMILY = '#CFCFCF'

Branch color once a clade mixes families (not monophyletic).

mkt.databases.colors.COLOR_TREE_NO_BREAK = '#C9C9C9'

Tree node fill for a split with no fixed difference (structural only).

mkt.databases.colors.COLOR_TREE_PSEUDO = '#000000'

Family color for a pseudokinase-pure clade (and inherited-conserved logo letters).

mkt.databases.colors.COLOR_TREE_SPLIT_MARKER = '#D00000'

Dashed marker on the summary dendrogram showing the top/bottom detail-panel split.

mkt.databases.colors.COLOR_TREE_TABLE_GAP = '#BDBDBD'

Static conservation-table cell fill where a gap (‘-’) is the >=80% consensus – a mid grey distinct from the blank no-consensus cell and from the amino-acid palette greys (I = #808080, E = #191919); paired with a ‘-’ glyph to disambiguate.

mkt.databases.colors.COLOR_TREE_TABLE_NO_CONSENSUS = '#EAEAEA'

Static conservation-table cell fill where no residue is >=80% conserved in a leaf row.

mkt.databases.colors.DEFAULT_NULL_COLOR = 'darkgray'

Default color for null/zero values in colormaps.

Type:

str

mkt.databases.colors.DICT_BIOCHEM_PROP_COLORS = {'Charge': '#1f77b4', 'Polarity': '#2ca02c', 'Volume': '#ff7f0e'}

Dictionary mapping biochemical properties to colors. Keys are property names (e.g., “Charge”, “Volume”, “Polarity”), and values are hex color codes. This dictionary can be used to look up colors for biochemical properties in visualizations.

Type:

dict[str, str]

mkt.databases.colors.DICT_COLORS = {'ALPHABET_PROJECT': {'DICT_ANNOTATION': None, 'DICT_COLORS': {'-': '#FFFFFF', 'A': '#F0A3FF', 'B': '#0075DC', 'C': '#993F00', 'D': '#4C005C', 'E': '#191919', 'F': '#005C31', 'G': '#2BCE48', 'H': '#FFCC99', 'I': '#808080', 'J': '#94FFB5', 'K': '#8F7C00', 'L': '#9DCC00', 'M': '#C20088', 'N': '#003380', 'O': '#FFA405', 'P': '#FFA8BB', 'Q': '#426600', 'R': '#FF0010', 'S': '#5EF1F2', 'T': '#00998F', 'U': '#E0FF66', 'V': '#740AFF', 'W': '#990000', 'X': '#FFFF80', 'Y': '#FFE100', 'Z': '#FF5005'}}, 'ASAP': {'DICT_ANNOTATION': None, 'DICT_COLORS': {'-': 'white', 'A': 'red', 'C': 'orange', 'D': 'yellow', 'E': 'cyan', 'F': 'navy', 'G': 'magenta', 'H': 'pink', 'I': 'brown', 'K': 'lime', 'L': 'gray', 'M': 'teal', 'N': 'green', 'P': 'olive', 'Q': 'purple', 'R': 'blue', 'S': 'maroon', 'T': 'silver', 'V': 'violet', 'W': 'gold', 'Y': 'skyblue'}}, 'CLUSTALX': {'DICT_ANNOTATION': {'aromatic': 'cyan', 'cysteine': 'pink', 'glycine': 'orange', 'hydrophobic': 'blue', 'negative': 'magenta', 'polar': 'green', 'positive': 'red', 'proline': 'yellow'}, 'DICT_COLORS': {'-': 'white', 'A': 'blue', 'C': 'pink', 'D': 'magenta', 'E': 'magenta', 'F': 'blue', 'G': 'orange', 'H': 'cyan', 'I': 'blue', 'K': 'red', 'L': 'blue', 'M': 'blue', 'N': 'green', 'P': 'yellow', 'Q': 'green', 'R': 'red', 'S': 'green', 'T': 'green', 'V': 'blue', 'W': 'blue', 'Y': 'cyan'}}, 'RASMOL': {'DICT_ANNOTATION': {'-': '#BEA06E', 'A': '#C8C8C8', 'C, M': '#E6E600', 'D, E': '#E60A0A', 'F, Y': '#3232AA', 'G': '#EBEBEB', 'H': '#8282D2', 'I, L, V': '#0F820F', 'N, Q': '#00DCDC', 'P': '#DC9682', 'R, K': '#145AFF', 'S, T': '#FA9600', 'W': '#B45AB4'}, 'DICT_COLORS': {'-': '#BEA06E', 'A': '#C8C8C8', 'C': '#E6E600', 'D': '#E60A0A', 'E': '#E60A0A', 'F': '#3232AA', 'G': '#EBEBEB', 'H': '#8282D2', 'I': '#0F820F', 'K': '#145AFF', 'L': '#0F820F', 'M': '#E6E600', 'N': '#00DCDC', 'P': '#DC9682', 'Q': '#00DCDC', 'R': '#145AFF', 'S': '#FA9600', 'T': '#FA9600', 'V': '#0F820F', 'W': '#B45AB4', 'Y': '#3232AA'}}, 'SHAPELY': {'DICT_ANNOTATION': {'-': '#000000', 'A': '#8CFF8C', 'C, M': '#FFFF70', 'D, E': '#A00042', 'F, Y': '#534C42', 'G': '#FFFFFF', 'H': '#7070FF', 'I, L, V': '#004C00', 'N, Q': '#FF7C70', 'P': '#525252', 'R, K': '#00007C', 'S, T': '#FF7042', 'W': '#4F4600'}, 'DICT_COLORS': {'-': '#000000', 'A': '#8CFF8C', 'C': '#FFFF70', 'D': '#A00042', 'E': '#A00042', 'F': '#534C42', 'G': '#FFFFFF', 'H': '#7070FF', 'I': '#004C00', 'K': '#00007C', 'L': '#004C00', 'M': '#FFFF70', 'N': '#FF7C70', 'P': '#525252', 'Q': '#FF7C70', 'R': '#00007C', 'S': '#FF7042', 'T': '#FF7042', 'V': '#004C00', 'W': '#4F4600', 'Y': '#534C42'}}, 'ZAPPO': {'DICT_ANNOTATION': {'aliphatic hydrophobic': '#ffafaf', 'aromatic': '#ffc803', 'conformationally special': '#ff00ff', 'cysteine': '#ffff00', 'hydrophilic': '#02ff00', 'negative': '#ff0000', 'positive': '#6464ff'}, 'DICT_COLORS': {'-': '#000000', 'A': '#ffafaf', 'C': '#ffff00', 'D': '#ff0000', 'E': '#ff0000', 'F': '#ffc803', 'G': '#ff00ff', 'H': '#6464ff', 'I': '#ffafaf', 'K': '#6464ff', 'L': '#ffafaf', 'M': '#ffafaf', 'N': '#02ff00', 'P': '#ff00ff', 'Q': '#02ff00', 'R': '#6464ff', 'S': '#02ff00', 'T': '#02ff00', 'V': '#ffafaf', 'W': '#ffc803', 'Y': '#ffc803'}}}

Mapping amino acid to color using specified dictionary. Dictionaries include color schemes from: - 2010 Colour Alphabet Project (ALPHABET_PROJECT) - ASAP Discovery palette (ASAP) - RasMol amino color scheme (RASMOL) - Shapely amino color scheme (SHAPELY) - Clustal X color scheme (CLUSTALX) - Zappo color scheme (ZAPPO) Dictionary keys include: - DICT_COLORS: Dictionary mapping single-letter amino acid to color - DICT_ANNOTATION: Dictionary mapping amino acid groups to color if one exists

Type:

dict[dict[str, str], dict[str, str]]

mkt.databases.colors.DICT_CONSURF_GRADE_COLORS = {1: '#10C8D1', 2: '#8CFFFF', 3: '#D7FFFF', 4: '#EAFFFF', 5: '#FFFFFF', 6: '#FCEDF4', 7: '#FAC9DE', 8: '#F07DAB', 9: '#A02560'}

Canonical ConSurf 9-grade conservation palette (grade 1 = most variable teal, grade 9 = most conserved maroon). Hex values are the exact RGB tuples from the ConSurf server’s rasmol_gradesPE_and_pipe.pm (github.com/Rostlab/ConSurf), so they carry over to PyMOL/Chimera structure coloring unchanged.

mkt.databases.colors.DICT_QUARTILE_HEATMAP_COLORMAP = {1: ('#228B22', '#FFD700'), 2: ('#FFD700', '#FF8C00'), 3: ('#FF8C00', '#FF0000'), 4: ('#FF0000', '#8B0000')}

Quartile heatmap colormap for mutation visualization. Maps quartile bin number (1-indexed) to (start_hex, end_hex) tuples for use with percentile_colormap.

Type:

dict[int, tuple[str, str]]

mkt.databases.colors.DICT_QUARTILE_HEATMAP_COLORMAP_PLASMA = {1: ('#0D0887', '#7E03A8'), 2: ('#7E03A8', '#CC4778'), 3: ('#CC4778', '#F89441'), 4: ('#F89441', '#F0F921')}

Plasma-inspired colormap for mutation visualization. Colorblind-accessible. Travels purple→magenta→orange→yellow, avoiding green entirely. Maps quartile bin number (1-indexed) to (start_hex, end_hex) tuples for use with percentile_colormap.

Type:

dict[int, tuple[str, str]]

mkt.databases.colors.DICT_QUARTILE_HEATMAP_COLORMAP_VIRIDIS = {1: ('#440154', '#31688E'), 2: ('#31688E', '#35B779'), 3: ('#35B779', '#90D743'), 4: ('#90D743', '#FDE725')}

Viridis-inspired colormap for mutation visualization. Perceptually uniform with good luminance gradient. Note: passes through green tones. Maps quartile bin number (1-indexed) to (start_hex, end_hex) tuples for use with percentile_colormap.

Type:

dict[int, tuple[str, str]]

mkt.databases.colors.generate_colormap_legend(color_stops: dict[int, tuple[str, str]], output_path: str | None = None, zero_color: str = 'darkgray', n_gradient_steps: int = 256, null_steps: int | None = None, figsize: tuple[float, float] = (0.75, 5.5)) None[source]

Generate a vertical colormap legend image (SVG and PNG) from color stops.

Creates a vertical gradient bar from bottom (null/zero color) to top (highest density), with percentile tick labels at 0, 0.25, 0.5, 0.75, and 1. Colors are generated via percentile_colormap with a synthetic uniform dataset so the legend is guaranteed to match live usage.

Parameters:

color_stopsdict[int, tuple[str, str]]

Dict mapping bin number (1-indexed) to (start_hex, end_hex) tuples, e.g., DICT_QUARTILE_HEATMAP_COLORMAP.

output_pathstr | None

Directory path to save the plot. If None, saves to the repo root.

zero_colorstr

Color for the null/zero band at the bottom (default: DEFAULT_NULL_COLOR).

n_gradient_stepsint

Number of interpolation steps per bin (default: 256).

null_stepsint | None

Height in pixels of the null/zero color band at the bottom. Defaults to 1/10 the height of one bin (n_gradient_steps // 10).

figsizetuple[float, float]

Figure size in inches (width, height). Default: (1, 5).

mkt.databases.colors.get_consurf_grade_color(grade: int | None) str[source]

Return the ConSurf palette color for a conservation grade.

Parameters:

grade (int | None) – ConSurf grade (1-9), or None for an ungraded position.

Returns:

Hex color from DICT_CONSURF_GRADE_COLORS, or COLOR_CONSURF_UNGRADED when grade is None.

Return type:

str

mkt.databases.colors.interpolate_color(norm_value: float, start_color_hex: str, end_color_hex: str) str[source]

Interpolate between two colors based on normalized value.

Parameters:

norm_valuefloat

Normalized value between 0 and 1.

start_color_hexstr

Starting color in hex format (e.g., “#FFFFFF”).

end_color_hexstr

Ending color in hex format (e.g., “#FF0000”).

Returns:

str

Interpolated color in hex format.

mkt.databases.colors.map_aa_to_single_letter_code(aa: str) str | None[source]

Map any amino acid input from name or 3-letter or single-letter code to validated single-letter code.

Parameters:

aa (str) – Amino acid name or 3-letter or single-letter code

Returns:

Single-letter amino acid code if valid; otherwise None

Return type:

str | None

Notes

3-letter and single-letter AA converted to uppercase; AA name converted to lowercase

mkt.databases.colors.map_single_letter_aa_to_color(aa, dict_color)[source]

Map amino acid to color using specified dictionary.

Parameters:
  • aa (str) – Amino acid name or 3-letter or single-letter code

  • dict_color (dict[str, str]) – Dictionary mapping single-letter amino acid to color

Returns:

Color that corresponds to AA single-letter code in selected palette

Return type:

str

mkt.databases.colors.percentile_colormap(values: list[float], color_stops: dict[int, tuple[str, str]], zero_color: str = 'darkgray') list[str][source]

Map numeric values to colors using percentile-based interpolation.

Divides non-zero values into N equal percentile bins (where N is the number of color stops) and interpolates within each bin’s color range.

Parameters:

valueslist[float]

Numeric values to map to colors.

color_stopsdict[int, tuple[str, str]]

Dict mapping bin number (1-indexed) to (start_hex, end_hex) tuples. The number of entries determines the number of percentile bins (e.g., 4 entries = quartiles, 5 entries = quintiles).

zero_colorstr

Color for zero values (default: “darkgray”).

Returns:

list[str]

List of color strings (hex or named).

mkt.databases.colors.readable_text_color(color) str[source]

Return "black" or "white" for legible text on a background color.

Parameters:

color (str | tuple) – Any matplotlib-recognized color (hex string, named color, or RGB tuple).

Returns:

"black" for light backgrounds, "white" for dark ones, chosen by perceived luminance (0.299 R + 0.587 G + 0.114 B).

Return type:

str