mkt.databases.cbioportal
cBioPortal API client and extraction of missense kinase mutations, treatments, and panels.
Builds on cBioPortal/cBioPortalQuery to pull study, mutation,
treatment, and gene-panel data; KinaseMissenseMutations extracts missense
mutations restricted to kinase genes.
Classes
|
Class to get clinical information from a cBioPortal study. |
|
Class to get patient-level clinical information from a cBioPortal study. |
|
Class to get sample-level clinical information from a cBioPortal study. |
|
Class to get gene panel information from a cBioPortal study. |
|
Class to get kinase mutations from a cBioPortal study. |
|
Class to get mutations from a cBioPortal study. |
|
Class to get gene panel information from a cBioPortal instance. |
|
Class to get mutations from a cBioPortal study. |
|
Class to get treatment information from a cBioPortal study. |
Class to interact with the cBioPortal API. |
|
|
Class to get data from a cBioPortal instance. |
- class mkt.databases.cbioportal.Clinical(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str, bool_sample: bool)[source]
Bases:
StudyDataClass to get clinical information from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str, bool_sample: bool) None
- bool_sample: bool
If True, return sample-level clinical data; if False, return patient-level clinical data.
- class mkt.databases.cbioportal.ClinicalPatient(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str)[source]
Bases:
ClinicalClass to get patient-level clinical information from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str) None
- bool_sample: bool = False
If True, return sample-level clinical data; if False, return patient-level clinical data
- class mkt.databases.cbioportal.ClinicalSample(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str)[source]
Bases:
ClinicalClass to get sample-level clinical information from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str) None
- bool_sample: bool = True
If True, return sample-level clinical data; if False, return patient-level clinical data
- class mkt.databases.cbioportal.GenePanel(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, panel_id: str)[source]
Bases:
PanelDataClass to get gene panel information from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, panel_id: str) None
- class mkt.databases.cbioportal.KinaseMissenseMutations(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, dict_replace: dict[str, str] = <factory>, str_blosom: str = 'BLOSUM80', pathfile_filter: str | None = None, *, study_id: str)[source]
Bases:
MutationsClass to get kinase mutations from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, dict_replace: dict[str, str] = <factory>, str_blosom: str = 'BLOSUM80', pathfile_filter: str | None = None, *, study_id: str) None
- annotate_kinase_regions(df: DataFrame, dict_in: dict) DataFrame[source]
Annotate kinase regions in a DataFrame of mutations.
- Parameters:
df (pd.DataFrame) – DataFrame of mutations
dict_in (dict) – Dictionary of HGNC gene names to KinaseInfo objects
- Returns:
DataFrame of mutations with kinase regions annotated
- Return type:
pd.DataFrame
- static convert_log_and_truncate(x: int | float | str, bool_log10: bool, max_value: int | None) int | float | str[source]
Convert a value to log10 and truncate if necessary.
- Parameters:
x (int | float | str) – Value to convert to log10
bool_truncate (bool) – Truncate the value to max_value if True; default is True
max_value (int) – Maximum value to truncate to if bool_truncate is True; default is 1.5
- Returns:
Log10 converted value if numeric, otherwise original value; truncated to max_value if bool_truncate is True
- Return type:
int | float | str
- dict_replace: dict[str, str]
“WHR1”}.
- Type:
Dictionary mapping cBioPortal to mkt gene names for mismatches; default is {“STK19”
- filter_single_aa_missense_mutations(df: DataFrame) DataFrame[source]
Filter DataFrame for single amino acid missense mutations.
- Parameters:
df (pd.DataFrame) – DataFrame of mutations
- Returns:
DataFrame of single amino acid missense mutations
- Return type:
pd.DataFrame
- generate_pivot_table(colname: str, bool_onehot: bool, bool_log10: bool, max_value: int | None) DataFrame[source]
Generate a pivot table of missense mutation counts by KLIFS region.
- Parameters:
colname (str) – Column name to pivot on; default is “klifs_region”
bool_onehot (bool) –
- Column name to pivot on; default is “klifs_region” (just counts);
- if “blosum_penalty”, the mean BLOSUM penalty is used instead;
if starts with “_”, it is treated as a one-hot encoded column
bool_log10 (bool) – Convert counts to log10 if True; default is True
max_value (int | None) –
- Maximum value to truncate the log10 counts to if bool_log10 is True;
if None, no truncation is applied; default is None
- Returns:
Pivot table of missense mutation counts by KLIFS region
- Return type:
pd.DataFrame
- get_kinase_missense_mutations(bool_save=False) None | DataFrame[source]
Get cBioPortal kinase mutations and optionally save as a CSV file.
- Parameters:
bool_save (bool) – Save cBioPortal kinase mutations as a CSV file if True
- Returns:
DataFrame of kinase mutations if successful, otherwise None
- Return type:
pd.DataFrame | None
- pathfile_filter: str | None = None
Path to CSV file for filtered kinase missense mutations; default is None.
- query_hgnc_gene_names(list_hgnc: list[str], dict_kinase: dict[str, object]) dict[str, str | None][source]
Query HGNC gene names from a DataFrame of mutations.
- Parameters:
list_hgnc (list[str]) – List of HGNC gene names to query
dict_kinase (dict[str, object]) – Dictionary mapping kinase names to KinaseInfo objects
- Returns:
Dictionary mapping HGNC gene names from cBioPortal to Uniprot IDs
- Return type:
dict
- remove_mismatched_uniprot_mutations(df: DataFrame, dict_in: dict) DataFrame[source]
Remove mutations with mismatches to canonical Uniprot sequence.
- Parameters:
df (pd.DataFrame) – DataFrame of mutations
dict_in (dict) – Dictionary of HGNC gene names to Uniprot IDs
- Returns:
DataFrame of mutations with mismatched Uniprot IDs removed
- Return type:
pd.DataFrame
- str_blosom: str = 'BLOSUM80'
BLOSUM matrix to use for mutation analysis; default is “BLOSUM80”.
- class mkt.databases.cbioportal.Mutations(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str)[source]
Bases:
StudyDataClass to get mutations from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str) None
- class mkt.databases.cbioportal.PanelData(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, panel_id: str)[source]
Bases:
cBioPortalQueryClass to get gene panel information from a cBioPortal instance.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, panel_id: str) None
- check_entity_id() bool[source]
Check if the panel ID is valid.
- Returns:
True if the panel ID is valid, False otherwise
- Return type:
bool
- panel_id: str
cBioPortal panel ID.
- class mkt.databases.cbioportal.StudyData(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str)[source]
Bases:
cBioPortalQueryClass to get mutations from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None, *, study_id: str) None
- check_entity_id() bool[source]
Check if the study ID is valid.
- Returns:
True if the study ID is valid, False otherwise
- Return type:
bool
- study_id: str
cBioPortal study ID.
- class mkt.databases.cbioportal.Treatment(bool_prefix: bool = True, list_col_explode: list[str] | None = <factory>, pathfile: str | None = None, *, study_id: str)[source]
Bases:
StudyDataClass to get treatment information from a cBioPortal study.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = <factory>, pathfile: str | None = None, *, study_id: str) None
- class mkt.databases.cbioportal.cBioPortal[source]
Bases:
APIKeySwaggerClientClass to interact with the cBioPortal API.
- __init__() None
- instance: str = ''
cBioPortal instance.
- maybe_get_token()[source]
Get API token, if available.
- Returns:
API token if available; None otherwise
- Return type:
str | None
- query_api()[source]
Query a Swagger API and return result.
- Parameters:
url (str) – API URL
- Returns:
API response
- Return type:
SwaggerClient
- url: str = ''
cBioPortal API URL.
- class mkt.databases.cbioportal.cBioPortalQuery(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None)[source]
Bases:
cBioPortalClass to get data from a cBioPortal instance.
- __init__(bool_prefix: bool = True, list_col_explode: list[str] | None = None, pathfile: str | None = None) None
- bool_prefix: bool = True
Add prefix to ABC column names if True; default is True.
- abstract check_entity_id() bool[source]
Check if the entity ID is valid.
- Returns:
True if the entity ID is valid, False otherwise
- Return type:
bool
- convert_api_query_to_dataframe() DataFrame | None[source]
Convert API to query to a dataframe.
- Returns:
DataFrame of API query if successful, otherwise None
- Return type:
pd.DataFrame | None
- abstract get_entity_id()[source]
Get the entity ID (study_id or panel_id).
- Returns:
Entity ID
- Return type:
str
- list_col_explode: list[str] | None = None
List of columns to explode in convert_api_query_to_dataframe; None if no columns to explode (post-init).
- load_from_csv(str_path: str | None = None) DataFrame | None[source]
Load DataFrame from CSV file.
- Parameters:
str_path (str | None) – Path to CSV file; if None, use self.pathfile
- Returns:
DataFrame loaded from CSV file if successful, otherwise None
- Return type:
pd.DataFrame | None
- pathfile: str | None = None
Path to load dataframe from CSV file; if None, regenerate (post-init).
- abstract query_sub_api()[source]
Query a sub-API of cBioPortal and return result.
- Returns:
API response
- Return type:
SwaggerClient
- regenerate_dataframe() DataFrame | None[source]
Regenerate DataFrame from API query.
- Returns:
DataFrame of API query if successful, otherwise None
- Return type:
pd.DataFrame | None
- return_adjusted_colname(colname: str, prefix: str = 'gene') str[source]
Return adjusted column name based on bool_prefix.
- Parameters:
colname (str) – Column name to adjust
prefix (str) – Prefix to add to the column name if bool_prefix is True; default is “gene”
- Returns:
Adjusted column name
- Return type:
str