mkt.databases.cbioportal.cBioPortalQuery
- 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
Methods
__eq__(other)Return self==value.
__init__([bool_prefix, list_col_explode, ...])__post_init__()Post-initialization to check study ID in instance and query API data.
_stamp_from_response(res)Record query datetime + cache provenance from a requests-cache response.
_stamp_now()Record current UTC datetime; cache provenance unknown.
Check if the entity ID is valid.
check_response(res)Check the response status code for errors.
Convert API to query to a dataframe.
get_cbioportal()Get cBioPortal API object.
get_data()Get cBioPortal data.
get_df()Get DataFrame of cBioPortal data in dataframe.
Get the entity ID (study_id or panel_id).
get_instance()Get cBioPortal instance.
get_url()Get cBioPortal API URL.
load_from_csv([str_path])Load DataFrame from CSV file.
maybe_get_token()Get API token, if available.
query_api()Query a Swagger API and return result.
Query a sub-API of cBioPortal and return result.
Regenerate DataFrame from API query.
return_adjusted_colname(colname[, prefix])Return adjusted column name based on bool_prefix.
set_api_key()Set API key for cBioPortal API.
Attributes
__dataclass_fields____dataclass_params____match_args___cbioportalcBioPortal API object (post-init).
_dataList of cBioPortal sub-API queries; None if ID not found (post-init).
_dfDataFrame of cBioPortal data; None if DataFrame could not be created (post-init).
Add prefix to ABC column names if True; default is True.
from_cacheWhether the most recent response was served from requests-cache.
instancecBioPortal instance.
List of columns to explode in convert_api_query_to_dataframe; None if no columns to explode (post-init).
Path to load dataframe from CSV file; if None, regenerate (post-init).
query_datetimeUTC datetime the underlying network query was made (cache creation time if served from cache).
urlcBioPortal API URL.
- __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