mkt.schema.conservation_schema
Persisted output of the KLIFS hierarchical-conservation clustering.
Defines KLIFSConservationData, a dependency-light (pure-Python, no
scipy/numpy) Pydantic artifact holding the pairwise distances, dendrogram, leaf
order, and display-leaf composition produced by
mkt.databases.conservation.KLIFSHierarchicalConservation, plus the
provenance metadata describing how they were assembled. Serialized via
mkt.schema.io_utils.serialize_conservation_data() and shipped as package data
so downstream consumers can reuse the tree/distances without recomputing them (or
importing scipy).
Module Attributes
Curated clade names keyed to a minimal set of anchor kinases that uniquely identify each clade by membership (not by display-order number, which is fragile to re-clustering). |
Classes
|
Persisted distances + dendrogram from the KLIFS conservation clustering. |
- mkt.schema.conservation_schema.DICT_CLADE_ANCHORS: dict[str, tuple[str, ...]] = {'EPH': ('EPHA3', 'EPHB1'), 'ERBB': ('EGFR', 'ERBB2'), 'FGFR': ('FGFR2', 'FGFR3'), 'INSR/ALK': ('INSR', 'ALK'), 'MET/AXL': ('MET', 'AXL'), 'PDGFR/VEGFR': ('KDR', 'KIT'), 'RET/TIE': ('RET', 'TEK'), 'SRC/ABL': ('SRC', 'ABL1'), 'TEC': ('BTK', 'TEC'), 'TRK/DDR': ('NTRK1', 'DDR2')}
Curated clade names keyed to a minimal set of anchor kinases that uniquely identify each clade by membership (not by display-order number, which is fragile to re-clustering). A display leaf is given a name only if it contains all of that name’s anchors, so a name silently disappears rather than mislabels if a clade splits. The SYK/ZAP70 pair is deliberately omitted – it clusters inside an EphA subclade rather than forming a clean Syk clade, and is excluded from the clade analysis.
- class mkt.schema.conservation_schema.KLIFSConservationData(*, metric: str, blosum_name: str, linkage_method: str, conservation_threshold: float, weighting: str, exclude_pseudokinases: bool, gap_chars: str, n_kinases: int, pocket_length: int, names: list[str], position_labels: list[str], distances_condensed: list[float], diagonal_is_similarity: bool = True, linkage_matrix: list[list[float]], leaves_order: list[int], display_leaves: list[dict] = <factory>, display_order: list[int] = <factory>)[source]
Bases:
BaseModelPersisted distances + dendrogram from the KLIFS conservation clustering.
The pairwise distances are stored as the condensed upper-triangle vector (the same row-major order SciPy’s
squareformuses), and the dendrogram as the SciPy linkage matrix (N-1rows of[child_a, child_b, height, count]), both as plain Python numbers so the schema stays free of numpy/scipy. The symmetric matrix and the(kin1, kin2, distance)long form are rebuilt on demand viarebuild_square()andto_long_form(); the full tree is reconstructed fromlinkage_matrixinmkt.databases(where scipy lives).- blosum_name: str
Substitution matrix name used by the
"blosum"metric.
- conservation_threshold: float
Minimum consensus-residue frequency for a column to count as conserved.
- diagonal_is_similarity: bool
rebuild as a similarity matrix (
1 - distance, diagonal 1.0) rather than raw distance (diagonal 0.0).- Type:
Documents
rebuild_square()’s default
- display_leaf_names(dict_anchors: dict[str, tuple[str, ...]] = {'EPH': ('EPHA3', 'EPHB1'), 'ERBB': ('EGFR', 'ERBB2'), 'FGFR': ('FGFR2', 'FGFR3'), 'INSR/ALK': ('INSR', 'ALK'), 'MET/AXL': ('MET', 'AXL'), 'PDGFR/VEGFR': ('KDR', 'KIT'), 'RET/TIE': ('RET', 'TEK'), 'SRC/ABL': ('SRC', 'ABL1'), 'TEC': ('BTK', 'TEC'), 'TRK/DDR': ('NTRK1', 'DDR2')}) list[str | None][source]
Return the curated clade name per display leaf (aligned to display_leaves).
- Parameters:
dict_anchors (dict[str, tuple[str, …]]) – Clade-name -> anchor-kinase mapping. Defaults to
DICT_CLADE_ANCHORS.- Returns:
One name (or None) per entry of
display_leaves, in that order.- Return type:
list[str | None]
- display_leaves: list[dict]
one entry per leaf as
{"members": list[int], "kind": str}(indices intonames).- Type:
Display-tree leaf rows from
build_display_tree
- display_order: list[int]
In-order (top-to-bottom) display order as indices into
display_leaves.
- distances_condensed: list[float]
Condensed upper-triangle distance vector (
N * (N - 1) / 2entries), in the row-major order used byscipy.spatial.distance.squareform.
- exclude_pseudokinases: bool
Whether predicted pseudokinases were dropped before clustering.
- gap_chars: str
Characters treated as gap/unknown and excluded from scoring.
- leaves_order: list[int]
Leaf order (
scipy.cluster.hierarchy.leaves_list), as indices intonames, cached so consumers need not import scipy.
- linkage_matrix: list[list[float]]
SciPy linkage matrix (
N-1rows of[child_a, child_b, height, count]); fully reconstructs the dendrogram viascipy.cluster.hierarchy.
- linkage_method: str
SciPy linkage method (
"average"UPGMA or"complete").
- metric: str
Pairwise distance metric used (
"blosum"or"identity").
- n_kinases: int
Number of kinases in the panel (
N; matrix dimension).
- name_for_members(member_idx: list[int], dict_anchors: dict[str, tuple[str, ...]] = {'EPH': ('EPHA3', 'EPHB1'), 'ERBB': ('EGFR', 'ERBB2'), 'FGFR': ('FGFR2', 'FGFR3'), 'INSR/ALK': ('INSR', 'ALK'), 'MET/AXL': ('MET', 'AXL'), 'PDGFR/VEGFR': ('KDR', 'KIT'), 'RET/TIE': ('RET', 'TEK'), 'SRC/ABL': ('SRC', 'ABL1'), 'TEC': ('BTK', 'TEC'), 'TRK/DDR': ('NTRK1', 'DDR2')}) str | None[source]
Return the curated clade name for a set of member indices.
A clade name applies only when the members contain all of that name’s anchor kinases (see
DICT_CLADE_ANCHORS), so the mapping is robust to display-order renumbering and never mislabels a split clade.- Parameters:
member_idx (list[int]) – Member indices into
names(e.g. adisplay_leavesentry’s"members").dict_anchors (dict[str, tuple[str, …]]) – Clade-name -> anchor-kinase mapping. Defaults to
DICT_CLADE_ANCHORS.
- Returns:
The matching clade name, or None if no anchor set is fully contained.
- Return type:
str | None
- names: list[str]
HGNC kinase names in panel order (distance-matrix row/column order).
- pocket_length: int
KLIFS pocket length (columns per kinase; 85 for the standard panel).
- position_labels: list[str]
KLIFS region labels (e.g.
"a.l:84") for the pocket columns.
- rebuild_square(as_similarity: bool = True, reorder_by_leaves: bool = False) list[list[float]][source]
Reconstruct the symmetric matrix from the condensed distance vector.
- Parameters:
as_similarity (bool) – If True (default), return a similarity matrix (
1 - distance) with a unit diagonal; if False, return raw distances with a zero diagonal.reorder_by_leaves (bool) – If True, reorder rows and columns by
leaves_order(dendrogram leaf order) rather than the panel order.
- Returns:
The symmetric
N x Nmatrix as nested lists.- Return type:
list[list[float]]
- to_long_form() list[tuple[str, str, float]][source]
Expand the condensed distances into
(kin1, kin2, distance)triples.- Returns:
One triple per upper-triangle pair, using
namesfor the labels.- Return type:
list[tuple[str, str, float]]
- weighting: str
Per-node consensus weighting (
"none"or"henikoff").