mkt.databases.oncokb
OncoKB API client for therapeutic levels, protein-change annotations, and the cancer gene list.
Provides OncoKBInfo and OncoKBProteinChange REST clients plus helpers
(get_oncokb_levels(), adjudicate_prefix()) for OncoKB therapeutic-level and
variant annotations, and OncoKBCancerGeneList for fetching/caching the OncoKB
cancer gene list.
Module Attributes
Mapping of OncoKB level prefixes to their corresponding keys in the highest level dictionary. |
|
Record keys whose values are lists; json-encoded when writing to CSV. |
Functions
|
Adjudicate the prefix for a given level string. |
Query the OncoKB API for the current levels of evidence. |
Classes
|
OncoKB API client. |
|
Client for the OncoKB cancer gene list endpoint. |
|
OncoKB API client for OncoKB information. |
|
OncoKB API client for protein changes. |
- mkt.databases.oncokb.DICT_ONCOKB_PREFIXES = {'Diagnostic_Implication': 'LEVEL_Dx', 'FDA': 'LEVEL_Fda', 'Prognostic_Implication': 'LEVEL_Px', 'Resistance': 'LEVEL_R', 'Sensitive': 'LEVEL_'}
Mapping of OncoKB level prefixes to their corresponding keys in the highest level dictionary.
- mkt.databases.oncokb.LIST_COLUMNS = ('geneAliases',)
Record keys whose values are lists; json-encoded when writing to CSV.
- class mkt.databases.oncokb.OncoKB(url: str = 'https://www.oncokb.org/api/v1', header: dict = <factory>)[source]
Bases:
APIKeyRESTAPIClient,ABCOncoKB API client.
- __init__(url: str = 'https://www.oncokb.org/api/v1', header: dict = <factory>) None
- static extract_level_as_int(str_in: str | None) int | None[source]
Extract the level from a string and convert it to an integer.
- Parameters:
str_in (str | None) – String containing the level information
- Returns:
Level as integer if found, otherwise None
- Return type:
int | None
- has_json() dict | None[source]
Get the JSON response from the OncoKB API query.
- Returns:
JSON response if available, otherwise None
- Return type:
dict | None
- header: dict
OncoKB API token, if available.
- maybe_get_token() str | None[source]
Get API token, if available.
- Returns:
API token if available; None otherwise
- Return type:
str | None
- url: str = 'https://www.oncokb.org/api/v1'
Base URL for the OncoKB API.
- url_query: str | None = None
URL to update for specific queries.
- class mkt.databases.oncokb.OncoKBCancerGeneList(url: str = 'https://www.oncokb.org/api/v1/utils/cancerGeneList')[source]
Bases:
RESTAPIClientClient for the OncoKB cancer gene list endpoint.
Fetches the full OncoKB cancer gene list (
/utils/cancerGeneList) in a single network call, exposing the raw JSON in_jsonand a tidy table in_df. The endpoint is public (no token required), so this subclasses the plainRESTAPIClientrather than the token-bearingOncoKBhierarchy used for therapeutic-level/variant annotations. Mirrors the cancerhotspots client: query once, filter client-side viaget_gene(), and round-trip to CSV viato_csv()/from_csv().- __init__(url: str = 'https://www.oncokb.org/api/v1/utils/cancerGeneList') None
- property df: DataFrame | None
Cancer gene list as a DataFrame (one row per gene).
- classmethod from_csv(path: str) OncoKBCancerGeneList[source]
Build a client from a CSV written by
to_csv(), without querying.- Parameters:
path (str) – Path to a CSV previously written by
to_csv().- Returns:
Instance backed by the cached table.
- Return type:
- classmethod from_dataframe(df: DataFrame) OncoKBCancerGeneList[source]
Build a client from an existing table without querying the API.
Bypasses
__post_init__(which would issue the network query) viaobject.__new__and sets_dfdirectly, so cached data can be reloaded offline._jsonis left None.- Parameters:
df (pd.DataFrame) – Cancer gene list table (e.g. from
read_csv()ordf).- Returns:
Instance backed by
df;get_gene()works as usual.- Return type:
- get_gene(hugo_symbol: str) DataFrame[source]
Return the cancer gene list record(s) for a single gene.
- Parameters:
hugo_symbol (str) – HGNC gene symbol to filter on (e.g.
"BRAF").- Returns:
Rows of
dfwhosehugoSymbolmatches; empty if none.- Return type:
pd.DataFrame
- static read_csv(path: str) DataFrame[source]
Read a cancer gene list written by
to_csv()back into a DataFrame.Inverts
to_csv(): json-decodes the list-valued columns.
- to_csv(path: str) None[source]
Write the cancer gene list to CSV, json-encoding list-valued columns.
- Parameters:
path (str) – Output CSV path.
- url: str = 'https://www.oncokb.org/api/v1/utils/cancerGeneList'
URL for the OncoKB cancer gene list endpoint.
- class mkt.databases.oncokb.OncoKBInfo(url: str = 'https://www.oncokb.org/api/v1', header: dict = <factory>)[source]
Bases:
OncoKBOncoKB API client for OncoKB information.
- class mkt.databases.oncokb.OncoKBProteinChange(url: str = 'https://www.oncokb.org/api/v1', header: dict = <factory>, gene_name: str | None = None, alteration: str | None = None, dict_highest_level: dict[str, int] = <factory>, list_treatment: list[str] = <factory>, oncogenic: str | None = None, vus: bool | None = None, known_effect: str | None = None, verbose: bool = True)[source]
Bases:
OncoKBOncoKB API client for protein changes.
- __init__(url: str = 'https://www.oncokb.org/api/v1', header: dict = <factory>, gene_name: str | None = None, alteration: str | None = None, dict_highest_level: dict[str, int] = <factory>, list_treatment: list[str] = <factory>, oncogenic: str | None = None, vus: bool | None = None, known_effect: str | None = None, verbose: bool = True) None
- alteration: str | None = None
Alteration type (e.g., V600E if BRAF is gene).
- dict_highest_level: dict[str, int]
Dictionary to store the highest level of evidence for each alteration.
- gene_name: str | None = None
Gene associated with the protein change.
- known_effect: str | None = None
Effect of the mutation on the protein (e.g., missense, nonsense).
- list_treatment: list[str]
List of treatments associated with the alteration.
- oncogenic: str | None = None
Oncogenic status of the alteration.
- verbose: bool = True
Whether to log warnings for missing data.
- vus: bool | None = None
Whether the alteration is a Variant of Uncertain Significance (VUS).
- mkt.databases.oncokb.adjudicate_prefix(str_in: str) str | None[source]
Adjudicate the prefix for a given level string.
- Parameters:
str_in (str) – String containing the level information (e.g., “LEVEL_1_SENSITIVE”)
- Returns:
Prefix of the level string (e.g., “Sensitive”) if found, otherwise None
- Return type:
str | None