mkt.databases.app.schema.MutationsConfig

class mkt.databases.app.schema.MutationsConfig(seq_align: SequenceAlignment, label_offset: float = 20.0, label_min_dist: float = 6.0, label_spring_strength: float = 0.0, label_size: int = 14, label_connector: bool = True, highlight_cartoon_transparency: float = 0.0, *, str_attr: str = 'Mutations', bool_mutations_by_group: bool, bool_klifs_only: bool, bool_show_sticks: bool = True, str_filepath_json: str)[source]

Bases: StructureConfig

Configuration for generating PyMOL files with mutation data.

__init__(seq_align: SequenceAlignment, label_offset: float = 20.0, label_min_dist: float = 6.0, label_spring_strength: float = 0.0, label_size: int = 14, label_connector: bool = True, highlight_cartoon_transparency: float = 0.0, *, str_attr: str = 'Mutations', bool_mutations_by_group: bool, bool_klifs_only: bool, bool_show_sticks: bool = True, str_filepath_json: str) None

Methods

__eq__(other)

Return self==value.

__init__(seq_align[, label_offset, ...])

__post_init__()

_filter_mutations_to_klifs()

Filter dict_mutations to only include residues in the 85 KLIFS pocket positions.

_generate_list_idx_from_dict_align_with_attr()

Generate list of 0-indexed attribute positions from dict_align.

_get_klifs_label(idx_0based)

Get KLIFS pocket label for a position (e.g., 'GK:45').

_get_klifs_uniprot_mapping(klifs_mapping[, ...])

Create mapping between UniProt positions and KLIFS indices.

_get_klifs_uniprot_positions(klifs_mapping)

Get the set of UniProt positions (1-indexed) in the KLIFS pocket.

_get_uniprot_label(idx_0based)

Get amino acid + UniProt position label (e.g., 'T790').

_index_mutation_region()

Extract the indices of the top mutation residues for stick highlighting.

_map_group_klifs_to_uniprot(dict_group_data)

Map group-averaged KLIFS-indexed data to target kinase's UniProt positions.

_preprocess_mutation_dict()

Preprocess mutation dictionary from JSON file.

generate_labels(list_idx)

Generate labels for top mutation residues.

generate_list_idx()

Generate list of 0-indexed positions for mutation residues.

generate_style_color_lists(list_idx)

Generate style and color lists for mutation residues.

return_list_cif_idx()

Return list of 0-indexed positions corresponding to the CIF sequence.

return_list_idx_intersect()

Return list of 0-indexed positions at intersection of CIF and attribute sequences.

return_list_intersect_color_style()

Generate the indices, styles, and colors for highlighting.

Attributes

__dataclass_fields__

__dataclass_params__

__match_args__

bool_show_sticks

True).

highlight_cartoon_transparency

Cartoon transparency applied to colored/highlighted residues (0 = opaque, 1 = invisible).

label_connector

Whether to draw leader/connector lines from each residue to its label.

label_min_dist

Minimum distance (angstroms) between labels for collision avoidance.

label_offset

Angstroms offset from CA for label pseudoatom placement.

label_size

Font size for residue labels.

label_spring_strength

Spring force pulling labels back toward ideal position (0 = no spring).

str_attr

'Mutations').

bool_mutations_by_group

Whether to average mutation counts by kinase group.

bool_klifs_only

Whether to only highlight KLIFS pocket residues.

str_filepath_json

File path to the JSON file containing the mutation dictionary.

dict_mutations

Dictionary of mutation positions (1-indexed) with corresponding normalized counts.

seq_align

SequenceAlignment object providing kinase info and dict_align.

list_idx

List of 1-indexed residue positions to be highlighted, generated in __post_init__.

list_color

List of colors for the residues to be highlighted, generated in __post_init__.

list_style

List of styles for the residues to be highlighted, generated in __post_init__.

list_label

List of labels for the residues to be highlighted (None for no label).

__init__(seq_align: SequenceAlignment, label_offset: float = 20.0, label_min_dist: float = 6.0, label_spring_strength: float = 0.0, label_size: int = 14, label_connector: bool = True, highlight_cartoon_transparency: float = 0.0, *, str_attr: str = 'Mutations', bool_mutations_by_group: bool, bool_klifs_only: bool, bool_show_sticks: bool = True, str_filepath_json: str) None
_filter_mutations_to_klifs() dict[int, float][source]

Filter dict_mutations to only include residues in the 85 KLIFS pocket positions.

Returns:

Filtered dictionary with only KLIFS pocket mutations.

Return type:

dict[int, float]

_get_klifs_label(idx_0based: int) str | None[source]

Get KLIFS pocket label for a position (e.g., ‘GK:45’).

Parameters:

idx_0based (int) – 0-indexed position in the alignment.

Returns:

KLIFS pocket label or None if not in KLIFS pocket.

Return type:

str | None

static _get_klifs_uniprot_mapping(klifs_mapping: dict | None, bool_uniprot_to_klifs: bool = True) dict[int, int][source]

Create mapping between UniProt positions and KLIFS indices.

Parameters:
  • klifs_mapping (dict | None) – KLIFS2UniProtIdx mapping from kinase object (ordered dict).

  • bool_uniprot_to_klifs (bool, optional) – If True, return UniProt position (1-indexed) -> KLIFS index (0-84). If False, return KLIFS index (0-84) -> UniProt position (1-indexed). Default is True.

Returns:

Mapping between UniProt positions and KLIFS indices.

Return type:

dict[int, int]

static _get_klifs_uniprot_positions(klifs_mapping: dict | None) set[int][source]

Get the set of UniProt positions (1-indexed) in the KLIFS pocket.

Parameters:

klifs_mapping (dict | None) – KLIFS2UniProtIdx mapping from kinase object.

Returns:

Set of 1-indexed UniProt positions in the KLIFS pocket.

Return type:

set[int]

_get_uniprot_label(idx_0based: int) str[source]

Get amino acid + UniProt position label (e.g., ‘T790’).

Parameters:

idx_0based (int) – 0-indexed position in the alignment.

Returns:

Label in format ‘X###’ where X is single-letter amino acid code.

Return type:

str

_index_mutation_region() list[int][source]

Extract the indices of the top mutation residues for stick highlighting.

Returns:

List of 0-indexed positions for the top mutation residues.

Return type:

list[int]

_map_group_klifs_to_uniprot(dict_group_data: dict[int, float]) dict[int, float][source]

Map group-averaged KLIFS-indexed data to target kinase’s UniProt positions.

Parameters:

dict_group_data (dict[int, float]) – Group-averaged normalized counts keyed by KLIFS index (0-84).

Returns:

Normalized counts mapped to target kinase’s UniProt positions (1-indexed).

Return type:

dict[int, float]

_preprocess_mutation_dict() dict[int, float][source]

Preprocess mutation dictionary from JSON file.

Handles two JSON formats: - New format: {"kinases": {...}, "kinase_groups": {...}} - Legacy format: {gene_name: {pos: count, ...}, ...}

For group-averaged mode, reads pre-computed group data (keyed by KLIFS index) and maps it to the target kinase’s UniProt positions.

Returns:

Mutation dictionary with UniProt position keys (1-indexed) and normalized counts.

Return type:

dict[int, float]

bool_klifs_only: bool

Whether to only highlight KLIFS pocket residues.

bool_mutations_by_group: bool

Whether to average mutation counts by kinase group.

bool_show_sticks: bool = True

True).

Type:

Whether to show top mutations as sticks (default

dict_mutations: dict[int, float]

Dictionary of mutation positions (1-indexed) with corresponding normalized counts.

abstract generate_labels(list_idx: list[int]) list[str | None][source]

Generate labels for top mutation residues.

Must be implemented by subclasses to provide config-specific label formats.

Parameters:

list_idx (list[int]) – List of 0-indexed residue positions.

Returns:

List of labels (None for residues that should not be labeled).

Return type:

list[str | None]

generate_list_idx() list[int][source]

Generate list of 0-indexed positions for mutation residues.

Returns:

List of 0-indexed positions for the residues to be highlighted.

Return type:

list[int]

generate_style_color_lists(list_idx: list[int]) tuple[list[str], list[str]][source]

Generate style and color lists for mutation residues.

Uses piecewise red gradient coloring: - Zero counts get lightgray - Non-zero counts are scaled piecewise and interpolated from light red to red

Parameters:

list_idx (list[int]) – List of 0-indexed residue positions.

Returns:

Tuple of (list_style, list_color).

Return type:

tuple[list[str], list[str]]

list_color: list[str]

List of colors for the residues to be highlighted, generated in __post_init__.

list_idx: list[int]

List of 1-indexed residue positions to be highlighted, generated in __post_init__.

list_label: list[str | None]

List of labels for the residues to be highlighted (None for no label).

list_style: list[str]

List of styles for the residues to be highlighted, generated in __post_init__.

seq_align: SequenceAlignment

SequenceAlignment object providing kinase info and dict_align.

str_attr: str = 'Mutations'

‘Mutations’).

Type:

Attribute to highlight in the structure (default

str_filepath_json: str

File path to the JSON file containing the mutation dictionary.