mkt.databases.hgnc.HGNC
- class mkt.databases.hgnc.HGNC(input_symbol_or_id: str, input_is_hgnc_symbol: bool = True, url: str = 'https://rest.genenames.org')[source]
Bases:
RESTAPIClientClass to interact with the HGNC API.
- __init__(input_symbol_or_id: str, input_is_hgnc_symbol: bool = True, url: str = 'https://rest.genenames.org') None
Methods
__eq__(other)Return self==value.
__init__(input_symbol_or_id[, ...])__post_init__()Post-initialization to set HGNC gene symbol or Ensembl gene ID.
Extract a list of values from the response documents of an HGNC REST API request.
_generate_key_set_hgnc_response_docs(res_input)Generate a set of keys present in the response documents of an HGNC REST API request.
_stamp_from_response(res)Record query datetime + cache provenance from a requests-cache response.
_stamp_now()Record current UTC datetime; cache provenance unknown.
check_response(res)Check the response status code for errors.
Get gene information for a given HGNC gene name from gene symbol report using HGNC REST API.
Get gene name from HGNC REST API using either a gene symbol or an Ensembl gene ID.
query_api(**kwargs)Default HGNC query: forwards to maybe_get_symbol_from_hgnc_search.
Attributes
__dataclass_fields____dataclass_params____match_args__from_cacheWhether the most recent response was served from requests-cache.
If True, input_symbol_or_id is a gene symbol, otherwise it is an Ensembl gene ID.
query_datetimeUTC datetime the underlying network query was made (cache creation time if served from cache).
HGNC API URL.
Gene symbol or Ensembl gene ID.
- __init__(input_symbol_or_id: str, input_is_hgnc_symbol: bool = True, url: str = 'https://rest.genenames.org') None
- static _extract_list_from_hgnc_response_docs(res_input: Response, str_to_extract: str) list[str][source]
Extract a list of values from the response documents of an HGNC REST API request.
- Parameters:
res_input (requests.models.Response) – Response object from an HGNC REST API request
str_to_extract (str) – Key to extract from the response documents
- Returns:
List of values extracted from the response documents
- Return type:
list[str]
- static _generate_key_set_hgnc_response_docs(res_input: Response) set[str][source]
Generate a set of keys present in the response documents of an HGNC REST API request.
- Parameters:
res_input (requests.models.Response) – Response object from an HGNC REST API request
- Returns:
Set of keys present in the response documents
- Return type:
set[str]
- input_is_hgnc_symbol: bool = True
If True, input_symbol_or_id is a gene symbol, otherwise it is an Ensembl gene ID.
- input_symbol_or_id: str
Gene symbol or Ensembl gene ID.
- maybe_get_info_from_hgnc_fetch(list_to_extract: list[str] | None = None, bool_verbose: bool = False) dict | None[source]
Get gene information for a given HGNC gene name from gene symbol report using HGNC REST API.
- Parameters:
hgnc_gene_symbol (str) – HGNC gene symbol
list_to_extract (list[str] | None) – List of fields to extract from the response; if None, defaults to [“locus_type”]
bool_verbose (bool, optional) – Whether to log verbose messages, by default False.
- Returns:
Dictionary of gene information; empty list if no match and None if request fails or field not found
- Return type:
dict | None
Notes
The list of extractable fields can be found at https://www.genenames.org/help/rest/ under “storedFields” in the JSON or XML outputs.
- maybe_get_symbol_from_hgnc_search(custom_field: str | None = None, custom_term: str | None = None, bool_verbose: bool = False) list[str] | None[source]
Get gene name from HGNC REST API using either a gene symbol or an Ensembl gene ID.
- Parameters:
custom_field (str | None) – Optional: custom field to search for in the HGNC REST API; otherwise defaults to “symbol” or “ensembl_gene_id” See https://www.genenames.org/help/rest/ under “searchableFields” for options
custom_term (str | None) – Optional: custom term to search for in the HGNC REST API
bool_verbose (bool, optional) – Whether to log verbose messages, by default False.
- Returns:
List of gene names that match input_symbol_or_id; empty list if no match and None if request fails
- Return type:
list[str] | None
- query_api(**kwargs) list[str] | None[source]
Default HGNC query: forwards to maybe_get_symbol_from_hgnc_search.
Parameters:
- **kwargs
Forwarded to maybe_get_symbol_from_hgnc_search.
Returns:
- list[str] | None
Result of the search; see maybe_get_symbol_from_hgnc_search for details.
- url: str = 'https://rest.genenames.org'
HGNC API URL.