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: cBioPortal

Class 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_entity_id()

Check if the entity ID is valid.

check_response(res)

Check the response status code for errors.

convert_api_query_to_dataframe()

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_entity_id()

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_sub_api()

Query a sub-API of cBioPortal and return result.

regenerate_dataframe()

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__

_cbioportal

cBioPortal API object (post-init).

_data

List of cBioPortal sub-API queries; None if ID not found (post-init).

_df

DataFrame of cBioPortal data; None if DataFrame could not be created (post-init).

bool_prefix

Add prefix to ABC column names if True; default is True.

from_cache

Whether the most recent response was served from requests-cache.

instance

cBioPortal instance.

list_col_explode

List of columns to explode in convert_api_query_to_dataframe; None if no columns to explode (post-init).

pathfile

Path to load dataframe from CSV file; if None, regenerate (post-init).

query_datetime

UTC datetime the underlying network query was made (cache creation time if served from cache).

url

cBioPortal 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

get_data()[source]

Get cBioPortal data.

get_df()[source]

Get DataFrame of cBioPortal data in dataframe.

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