mkt.schema.utils
Schema utility helpers: recursive attribute access, UUID generation, and kinase-group adjudication.
Provides rgetattr()/rsetattr() for traversing nested Pydantic models,
random_uuid(), return_kinase_gene_set(), and
adjudicate_kinase_group().
Module Attributes
Default tqdm bar format with comma-separated thousands in counts. |
|
Hand-curated name pairs that |
Functions
|
Adjudicates the kinase group for a given kinase. |
|
Collapse prefix-homologous kinase names into compact labeled groups. |
Generate a random UUID that allows to set a seed. |
|
|
Return the set of kinase HGNC gene symbols for gene-level membership tests. |
|
Get attribute from object recursively. |
|
Set attribute from object recursively. |
|
Split a trailing multi-domain index suffix off a kinase name. |
- mkt.schema.utils.SET_HOMOLOG_DO_NOT_MERGE = frozenset({frozenset({'BUB1', 'BUB1B'})})
Hand-curated name pairs that
group_name_homologs()must never collapse together, overriding the prefix heuristic. BUB1 / BUB1B are distinct genes (BUB1B is BUBR1) whoseBsuffix is not the receptorRcase caught generically.- Type:
frozenset[frozenset[str]]
- mkt.schema.utils.TQDM_BAR_FORMAT = '{l_bar}{bar}| {n:,}/{total:,} [{elapsed}<{remaining}, {rate_fmt}{postfix}]'
Default tqdm bar format with comma-separated thousands in counts.
- mkt.schema.utils.adjudicate_kinase_group(str_kinase: str, bool_lipid: bool = True) str | None[source]
Adjudicates the kinase group for a given kinase.
- Parameters:
str_kinase (str) – The name of the kinase (e.g., “PIK3CA”).
bool_lipid (bool, optional) – Flag to indicate if lipid kinases should be classified as “Lipid” group, by default True.
- Returns:
The adjudicated kinase group (e.g., “Lipid”, “TK”, “CMGC”), or None if the kinase is not found.
- Return type:
str | None
- mkt.schema.utils.group_name_homologs(names: list[str], min_prefix: int = 3, show_count: bool = True) list[tuple[str, list[str]]][source]
Collapse prefix-homologous kinase names into compact labeled groups.
Names are grouped when they share a common base stem of at least
min_prefixcharacters, each member’s remaining variant is a single letter or a pure number (so distinct subfamilies such as EPHA10 / EPHB6 stay apart), and they carry the same multi-domain suffix (seesplit_domain_suffix()). The stem is trimmed back off any mid-number boundary so a shorter member number is not split out of a longer one (NEK1 vs NEK10/NEK11), and numeric variants are sorted numerically. Each group is labeled by factoring out the stem, e.g.["JAK1_1", "JAK2_1", "JAK3_1"] -> ("JAK1/2/3_1 (3)", [...])or["NEK1", "NEK10", "NEK2"] -> ("NEK1/2/10", [...]). The defaultmin_prefixof 3 keeps coincidental two-character matches apart (e.g. the unrelated ATM, ATR). A complete gene name and itsstem + "R"receptor paralog are never merged (e.g. INSR / INSRR stay apart), and any pair inSET_HOMOLOG_DO_NOT_MERGEis held apart by hand (BUB1 / BUB1B).- Parameters:
names (list[str]) – Kinase names to group. Order is not significant: names are sorted by
(domain_suffix, name)internally so homologs are adjacent.min_prefix (int, optional) – Minimum shared base-stem length required to merge, by default 3.
show_count (bool, optional) – Append a
" (N)"member count to each merged group’s label, by default True.
- Returns:
(label, members)pairs in sorted order; a singleton is(name, [name]).- Return type:
list[tuple[str, list[str]]]
- mkt.schema.utils.random_uuid()[source]
Generate a random UUID that allows to set a seed.
- Returns:
A random UUID as a string.
- Return type:
str
- mkt.schema.utils.return_kinase_gene_set(dict_kinase: dict | None = None) set[str][source]
Return the set of kinase HGNC gene symbols for gene-level membership tests.
Multi-kinase-domain genes are keyed with a
_1/_2domain suffix (seesplit_domain_suffix()); those are collapsed to the base gene symbol (e.g.JAK1_1/JAK1_2->JAK1) so a symbol like"JAK1"is not missed when testing membership against cohort gene symbols.- Parameters:
dict_kinase (dict | None) – Mapping keyed by kinase name (optionally carrying a
_<digit>domain suffix). If None, the canonicalDICT_KINASEis deserialized.- Returns:
Base HGNC gene symbols of every kinase.
- Return type:
set[str]
- mkt.schema.utils.rgetattr(obj, attr, *args)[source]
Get attribute from object recursively.
- Parameters:
obj (Any) – Object to get attribute from.
attr (str) – Attribute to get.
*args (Any) – Any additional arguments to pass to getattr.
- Returns:
Value of attribute if found.
- Return type:
Any
- mkt.schema.utils.rsetattr(obj, attr, val)[source]
Set attribute from object recursively.
- Parameters:
obj (Any) – Object to get attribute from.
attr (str) – Attribute to get.
val (Any) – Value to set attribute to.
- Returns:
Value of attribute if found, otherwise default value.
- Return type:
Any
- mkt.schema.utils.split_domain_suffix(name: str) tuple[str, str][source]
Split a trailing multi-domain index suffix off a kinase name.
Multi-domain kinases are represented with a
_1/_2suffix denoting the individual kinase domains (e.g."JAK1_1"is the first kinase domain of JAK1).- Parameters:
name (str) – Kinase name, optionally carrying a
_<digit>domain suffix.- Returns:
(base, suffix)wheresuffixis"_<digit>"or""(e.g."JAK1_1" -> ("JAK1", "_1"),"BTK" -> ("BTK", "")).- Return type:
tuple[str, str]