mkt.databases.plot

Plotting functions for kinase data.

Includes dynamic-range, ridgeline, stacked-bar, Venn-diagram, metrics-boxplot, and sequence-input schematic plots, plus SequenceAlignment rendering and Matplotlib RC configuration helpers.

Module Attributes

LIST_KINASE_GROUP_ORDER

canonical Manning kinome-tree ordering for kinase-group legends.

Functions

_collect_region_gap_specs(dict_in)

Collect inter- and intra-region gap specs with per-kinase gap lengths.

_collect_region_map_extras(dict_in)

Compute intra-split lengths and N-/C-terminal residue-count ranges.

_draw_map_block(ax, x0, length, y0, h, ...)

Draw a track block: light-grey interior residue dividers, heavy black box.

_draw_map_connector(ax, tx0, tx1, bx0, bx1, ...)

Connect a UniProt block to its KLIFS block (band or curved ribbon).

_draw_region_gap_violin_panel(ax, specs, ...)

Draw one grouped violin panel (log-scaled y-axis) on ax.

_draw_sequence_strip(ax, y, colors[, ...])

Draw a horizontal strip of colored rectangles representing a sequence.

_draw_uniprot_klifs_map(ax, inter_median, ...)

Render the two-track UniProt->KLIFS residue mapping diagram on ax.

_flatten_on_white(color, alpha)

Pre-blend color onto white at alpha (fully opaque output).

_get_klifs_position_colors()

Build a list of (region_name, color) for each of the 85 KLIFS pocket positions.

_map_aligned_to_klifs_colors(seq_aligned, ...)

Map each position in an aligned sequence to a color.

_region_map_segments(inter_median, splits, cfg)

Build the ordered UniProt-track segments and contiguous KLIFS blocks.

apply_matplotlib_rc(rc)

Apply global matplotlib rcParams from config.

convert_from_percentile(input[, orig_max, ...])

Convert percentile values back to Kd scale.

convert_to_percentile(input[, orig_max])

Convert Kd values to percentile scale.

generate_venn_diagram_dict(df_in)

Generate a dictionary for Venn diagram plotting.

kinase_group_legend_handles([fams, style, ...])

Build kinase-group legend handles in the canonical kinome-tree order.

order_kinase_groups([fams])

Order kinase-group labels by the canonical Manning kinome-tree grouping.

plot_dict_kinase_upset(dict_in, path_save[, cfg])

Plot a source-coverage upset plot of the DICT_KINASE KinaseInfo objects.

plot_dynamic_range(df_davis, df_pkis2, ...)

Create a histogram comparing dynamic assay ranges between Davis and PKIS2.

plot_metrics_boxplot(df, output_path[, cfg, ...])

Create a boxplot with jitter showing MSE values by col_kinase and source.

plot_region_gap_violin(dict_in, path_save[, ...])

Plot the combined UniProt->KLIFS residue map over region-gap violins.

plot_ridgeline(df, output_path[, cfg, rc, ...])

Create a ridgeline plot showing distribution of fraction_construct by family.

plot_sequence_input_schematic(df, output_path)

Create a 3-panel schematic comparing the three sequence input representations.

plot_stacked_barchart(df, output_path[, ...])

Create a stacked bar chart showing counts by family.

plot_venn_diagram(df, output_path, source_name)

Create a Venn diagram showing overlap of kinases across different sequence types.

remove_spines(ax)

Remove plot spines while keeping tick marks for cleaner appearance.

write_clade_membership_table(conservation_data)

Build a LaTeX (booktabs) table of named clades and their member kinases.

Classes

SequenceAlignment(list_sequences, list_ids, ...)

Class for sequence alignment plot.

mkt.databases.plot.LIST_KINASE_GROUP_ORDER = ['TK', 'TKL', 'STE', 'CK1', 'AGC', 'CAMK', 'CMGC', 'NEK', 'RGC', 'Other', 'Atypical', 'Lipid']

canonical Manning kinome-tree ordering for kinase-group legends.

Type:

list[str]

class mkt.databases.plot.SequenceAlignment(list_sequences: list[str], list_ids: list[str], dict_colors: dict[str, str], font_size: int = 9, plot_width: int = 800, plot_height: int = None, bool_top: bool = True, bool_reverse: bool = True, bool_gridplot: bool = True)[source]

Bases: object

Class for sequence alignment plot.

bool_gridplot: bool = True

Use gridplot or not.

bool_reverse: bool = True

Reverse the sequence or not.

bool_top: bool = True

Show entire sequence view on top or not (no text, with zoom).

create_coldatasource()[source]
dict_colors: dict[str, str]

Dictionary of colors for each sequence.

font_size: int = 9

Font size for alignment.

generate_bottom_plot() None[source]

Generate sequence alignment plot adapted from https://dmnfarrell.github.io/bioinformatics/bokeh-sequence-aligner.

generate_gridplot() None[source]

Generate sequence alignment gridplot.

generate_top_plot() None[source]

Generate sequence alignment plot adapted from https://dmnfarrell.github.io/bioinformatics/bokeh-sequence-aligner.

static get_colors(list_str: str, dict_colors: dict[str, str]) list[str][source]

Get colors for residue in a given sequence.

Parameters:
  • list_str (str) – List of residues in a sequence.

  • dict_colors (dict[str, str]) – Dictionary of colors for each residue.

Returns:

List of colors for each residue.

Return type:

list[str]

list_ids: list[str]

List of sequence IDs.

list_sequences: list[str]

List of sequences to show in aligner.

plot_height: int = None

Height of the plot; default None and will full-page heuristic.

plot_width: int = 800

Width of the plot.

show_plot() None[source]

Show sequence alignment plot via Bokeh in separate window.

mkt.databases.plot._collect_region_gap_specs(dict_in: dict[str, Any]) tuple[list[dict], list[dict]][source]

Collect inter- and intra-region gap specs with per-kinase gap lengths.

Inter-region gaps are derived from DICT_POCKET_KLIFS_REGIONS entries where contiguous is False (the gap spans from that region to the next one). Intra-region gaps are the KLIFS2UniProtSeq keys ending in "_intra". Gap length is the length of the stored sequence; None counts as 0.

Only kinases with a KLIFS pocket annotation are included: those with klifs.pocket_seq is None (no KLIFS object, or a KLIFS object without a pocket sequence) have no KLIFS2UniProtSeq region mapping, so counting them would inflate the zero-length bin with kinases that lack pocket data.

Parameters:

dict_in (dict[str, Any]) – Dictionary of KinaseInfo objects.

Returns:

(inter, intra) lists of spec dicts, each with keys key, label, color_left, color_right, lengths (np.ndarray) and median.

Return type:

tuple[list[dict], list[dict]]

mkt.databases.plot._collect_region_map_extras(dict_in: dict[str, Any]) tuple[source]

Compute intra-split lengths and N-/C-terminal residue-count ranges.

Returns (splits, nterm, cterm) where splits maps each split region (b.l, linker) to its modal (before, after) KLIFS-residue counts, and nterm/cterm are (min, max) residue counts preceding/following the KLIFS region across the pocket-annotated kinases.

mkt.databases.plot._draw_map_block(ax, x0, length, y0, h, color, cells) None[source]

Draw a track block: light-grey interior residue dividers, heavy black box.

mkt.databases.plot._draw_map_connector(ax, tx0, tx1, bx0, bx1, color, cfg) None[source]

Connect a UniProt block to its KLIFS block (band or curved ribbon).

mkt.databases.plot._draw_region_gap_violin_panel(ax, specs, group_label, y_max, show_ylabel, cfg) None[source]

Draw one grouped violin panel (log-scaled y-axis) on ax.

mkt.databases.plot._draw_sequence_strip(ax, y: float, colors: list[str], rect_height: float = 0.6, x_offset: float = 0) None[source]

Draw a horizontal strip of colored rectangles representing a sequence.

Parameters:

axmatplotlib.axes.Axes

Axes to draw on.

yfloat

Vertical center of the strip.

colorslist[str]

Color for each position.

rect_heightfloat

Height of each rectangle.

x_offsetfloat

Horizontal offset for the strip start.

mkt.databases.plot._draw_uniprot_klifs_map(ax, inter_median, ranges, splits, nterm, cterm, cfg) None[source]

Render the two-track UniProt->KLIFS residue mapping diagram on ax.

mkt.databases.plot._flatten_on_white(color: str, alpha: float) tuple[source]

Pre-blend color onto white at alpha (fully opaque output).

mkt.databases.plot._get_klifs_position_colors() list[tuple[str, str]][source]

Build a list of (region_name, color) for each of the 85 KLIFS pocket positions.

Returns:

list[tuple[str, str]]

List of (region_name, color) tuples, one per KLIFS pocket position (85 total).

mkt.databases.plot._map_aligned_to_klifs_colors(seq_aligned: str, seq_klifs_only: str, dict_aa_colors: dict[str, str], klifs_pos_colors: list[tuple[str, str]], gap_color: str = 'white') list[str][source]

Map each position in an aligned sequence to a color.

Core KLIFS pocket residues get their KLIFS region color; inter/intra MSA residues get alphabet palette colors; gaps get the gap color.

Parameters:

seq_alignedstr

Full aligned sequence (e.g. 970 chars).

seq_klifs_onlystr

KLIFS-residues-only sequence (85 chars).

dict_aa_colorsdict[str, str]

Amino acid to color mapping (alphabet palette).

klifs_pos_colorslist[tuple[str, str]]

Per-position (region_name, color) from _get_klifs_position_colors.

gap_colorstr

Color for gap characters.

Returns:

list[str]

Color string for each position in seq_aligned.

mkt.databases.plot._region_map_segments(inter_median: dict, splits: dict, cfg) tuple[source]

Build the ordered UniProt-track segments and contiguous KLIFS blocks.

mkt.databases.plot.apply_matplotlib_rc(rc: MatplotlibRCConfig) None[source]

Apply global matplotlib rcParams from config.

mkt.databases.plot.convert_from_percentile(input, orig_max=10, precision=3) float[source]

Convert percentile values back to Kd scale.

mkt.databases.plot.convert_to_percentile(input, orig_max=10) float[source]

Convert Kd values to percentile scale.

mkt.databases.plot.generate_venn_diagram_dict(df_in: DataFrame) dict[source]

Generate a dictionary for Venn diagram plotting.

Parameters:

df_inpd.DataFrame

DataFrame with columns: kinase_name, seq_construct_unaligned, seq_klifs_region_aligned, seq_klifs_residues_only

Returns:

dict

Dictionary with keys as sequence types and values as lists of kinase names.

mkt.databases.plot.kinase_group_legend_handles(fams: set[str] | None = None, *, style: str = 'patch', markersize: float = 8, edgecolor: str = 'none', fallback: str = '#999999') list[source]

Build kinase-group legend handles in the canonical kinome-tree order.

Shared across every figure that carries a kinase-group color legend so their ordering and colors stay consistent.

Parameters:
  • fams (set[str] | None) – Family labels present in the drawn subset; None uses all groups in DICT_KINASE_GROUP_COLORS.

  • style (str) – Handle style: "patch" for a filled swatch (matplotlib.patches.Patch) or "marker" for a square-marker matplotlib.lines.Line2D; default "patch".

  • markersize (float) – Marker size when style="marker"; default 8.

  • edgecolor (str) – Swatch edge color when style="patch"; default "none".

  • fallback (str) – Color for families absent from DICT_KINASE_GROUP_COLORS.

Returns:

One handle per family, in display order, each labeled with its family.

Return type:

list

mkt.databases.plot.order_kinase_groups(fams: set[str] | None = None) list[str][source]

Order kinase-group labels by the canonical Manning kinome-tree grouping.

Parameters:

fams (set[str] | None) – Family labels to order (Manning group or Lipid). When None, all groups in DICT_KINASE_GROUP_COLORS are used. Families outside the curated order are appended alphabetically.

Returns:

Family labels in display order.

Return type:

list[str]

mkt.databases.plot.plot_dict_kinase_upset(dict_in: dict[str, Any], path_save: str, cfg: UpsetPlotConfig | None = None) None[source]

Plot a source-coverage upset plot of the DICT_KINASE KinaseInfo objects.

Parameters:
  • dict_in (dict[str, Any]) – Dictionary of KinaseInfo objects.

  • path_save (str) – Path to save the plot.

  • cfg (UpsetPlotConfig | None) – Plot aesthetics config; uses defaults (original size) when None.

Returns:

None

Return type:

None

mkt.databases.plot.plot_dynamic_range(df_davis: DataFrame, df_pkis2: DataFrame, output_path: str, cfg: DynamicRangePlotConfig | None = None, rc: MatplotlibRCConfig | None = None) None[source]

Create a histogram comparing dynamic assay ranges between Davis and PKIS2.

Parameters:

df_davispd.DataFrame

DataFrame with ‘y’ column containing Kd values.

df_pkis2pd.DataFrame

DataFrame with ‘y’ column containing percent inhibition values.

output_pathstr

Path to save the plot files (will save both SVG and PNG).

cfgDynamicRangePlotConfig | None

Plot aesthetics config; uses defaults when None.

rcMatplotlibRCConfig | None

Matplotlib rcParams config; uses defaults when None.

mkt.databases.plot.plot_metrics_boxplot(df: DataFrame, output_path: str, cfg: MetricsBoxplotConfig | None = None, rc: MatplotlibRCConfig | None = None, color_cfg: ColKinaseColorConfig | None = None) None[source]

Create a boxplot with jitter showing MSE values by col_kinase and source.

Parameters:

dfpd.DataFrame

DataFrame with columns: col_kinase, source, fold, avg_stable_epoch, mse.

output_pathstr

Path to save the SVG file.

cfgMetricsBoxplotConfig | None

Plot aesthetics config; uses defaults when None.

rcMatplotlibRCConfig | None

Matplotlib rcParams config; uses defaults when None.

color_cfgColKinaseColorConfig | None

Col kinase color config; uses defaults when None.

mkt.databases.plot.plot_region_gap_violin(dict_in: dict[str, Any], path_save: str, cfg: RegionGapViolinConfig | None = None, rc: MatplotlibRCConfig | None = None) None[source]

Plot the combined UniProt->KLIFS residue map over region-gap violins.

The top panel maps the KLIFS-region span of the UniProt sequence (inter fillers sized to the median gap, intra fillers length 1, ellipses for the rest of the sequence) onto the contiguous KLIFS pocket residues via colored connectors (bands by default, ribbons when cfg.use_ribbon). The two bottom panels show the inter- and intra-region gap-length distributions as violins with jittered points on separate log-scaled axes. Only kinases with a KLIFS pocket annotation are included; all statistics are computed on the fly.

Parameters:
  • dict_in (dict[str, Any]) – Dictionary of KinaseInfo objects.

  • path_save (str) – Directory in which to save the plot.

  • cfg (RegionGapViolinConfig | None) – Plot aesthetics config; uses defaults when None.

  • rc (MatplotlibRCConfig | None) – Matplotlib rcParams config; uses defaults when None.

Return type:

None

mkt.databases.plot.plot_ridgeline(df: DataFrame, output_path: str, cfg: RidgelinePlotConfig | None = None, rc: MatplotlibRCConfig | None = None, family_cfg: FamilyColorConfig | None = None) None[source]

Create a ridgeline plot showing distribution of fraction_construct by family.

Parameters:

dfpd.DataFrame

DataFrame with columns: kinase_name, family, fraction_construct, source.

output_pathstr

Path to save the SVG file.

cfgRidgelinePlotConfig | None

Plot aesthetics config; uses defaults when None.

rcMatplotlibRCConfig | None

Matplotlib rcParams config; uses defaults when None.

family_cfgFamilyColorConfig | None

Family color config; uses defaults when None.

mkt.databases.plot.plot_sequence_input_schematic(df: DataFrame, output_path: str, list_kinases: list[str] | None = None, cfg: SequenceSchematicConfig | None = None, rc: MatplotlibRCConfig | None = None) None[source]

Create a 3-panel schematic comparing the three sequence input representations.

Panel A shows unaligned construct sequences (variable length, alphabet palette). Panel B shows KLIFS-region-aligned sequences (fixed length, KLIFS palette for pocket regions, alphabet palette for MSA inter/intra regions). Panel C shows KLIFS-residues-only sequences (85 positions, KLIFS palette).

Parameters:

dfpd.DataFrame

DataFrame with columns: kinase_name, seq_construct_unaligned, seq_klifs_region_aligned, seq_klifs_residues_only.

output_pathstr

Path to save the plot files.

list_kinaseslist[str] | None

Kinase names to display. If None, uses a default selection of 5 kinases with comparable unaligned sequence lengths.

cfgSequenceSchematicConfig | None

Plot aesthetics config; uses defaults when None.

rcMatplotlibRCConfig | None

Matplotlib rcParams config; uses defaults when None.

mkt.databases.plot.plot_stacked_barchart(df: DataFrame, output_path: str, cfg: StackedBarchartConfig | None = None, rc: MatplotlibRCConfig | None = None, family_cfg: FamilyColorConfig | None = None) None[source]

Create a stacked bar chart showing counts by family.

Parameters:

dfpd.DataFrame

DataFrame with columns: family, bool_uniprot2refseq, count, source.

output_pathstr

Path to save the SVG file.

cfgStackedBarchartConfig | None

Plot aesthetics config; uses defaults when None.

rcMatplotlibRCConfig | None

Matplotlib rcParams config; uses defaults when None.

family_cfgFamilyColorConfig | None

Family color config; uses defaults when None.

mkt.databases.plot.plot_venn_diagram(df: DataFrame, output_path: str, source_name: str, cfg: VennDiagramConfig | None = None, rc: MatplotlibRCConfig | None = None, color_cfg: ColKinaseColorConfig | None = None) None[source]

Create a Venn diagram showing overlap of kinases across different sequence types.

Parameters:

dfpd.DataFrame

DataFrame with columns: kinase_name, seq_construct_unaligned, seq_klifs_region_aligned, seq_klifs_residues_only.

output_pathstr

Path to save the SVG file.

source_namestr

Name of the source (e.g., ‘Davis’, ‘PKIS2’).

cfgVennDiagramConfig | None

Plot aesthetics config; uses defaults when None.

rcMatplotlibRCConfig | None

Matplotlib rcParams config; uses defaults when None.

color_cfgColKinaseColorConfig | None

Col kinase color config; uses defaults when None.

mkt.databases.plot.remove_spines(ax)[source]

Remove plot spines while keeping tick marks for cleaner appearance.

Parameters:

ax (matplotlib.axes.Axes) – The axes object from which to remove spines.

Return type:

None

mkt.databases.plot.write_clade_membership_table(conservation_data, str_group: str = 'TK', str_filepath: str | None = None, dict_anchors: dict[str, tuple[str, ...]] | None = None) str[source]

Build a LaTeX (booktabs) table of named clades and their member kinases.

Uses the curated anchor-based clade names (mkt.schema.conservation_schema.DICT_CLADE_ANCHORS) so the table is keyed to stable clade names rather than fragile display-order numbers. Rows are the named clades that fall within str_group (e.g. the TK sub-families), ordered by descending membership.

Parameters:
  • conservation_data (KLIFSConservationData) – Persisted KLIFS clustering artifact (e.g. from mkt.schema.io_utils.load_conservation_data()).

  • str_group (str) – Kinase group to restrict membership to (default "TK"). Pass None to keep every member regardless of group.

  • str_filepath (str | None) – If given, write the LaTeX source to this path.

  • dict_anchors (dict[str, tuple[str, …]] | None) – Clade-name -> anchor-kinase mapping; defaults to DICT_CLADE_ANCHORS.

Returns:

The LaTeX table source.

Return type:

str