wadi.api_utils module
- wadi.api_utils.translate_strings(strings, src_lang, dst_lang, max_attempts)
This method attempts to translate a list of strings from src_lang to dst_lang using Google Translate.
- Parameters:
src_lang (str) – String that specifies the language to translate from. Default: “NL”.
dst_lang (str) – String that specifies the language to translate to. Default: “EN”.
max_attempts (int) – The maximum number of attempts to connect to the Google Translate API. Default: 10.
- wadi.api_utils.get_pubchem_json(url)
This method interacts with the PubChem REST API by sending a URL and, when successful, returns a json dict.
- Parameters:
url (str) – The URL containing the query/request.
- Returns:
result – Returns the json dictonary returned by the PubChem API, or None if an error occurred.
- Return type:
dict or None
- wadi.api_utils.query_pubchem_fuzzy(s)
This method uses the PubChem REST auto-complete API service that supports fuzzy matching of input strings.
- Parameters:
s (str) – The string to look up
- Returns:
result – A two-element list. The first element is the first compound name returned if the request was successful, the second the first synonym returned by calling query_pubchem_synonyms. Returns [None, None] if any error occurred.
- Return type:
list
- wadi.api_utils.query_pubchem_synonyms(s, namespace='name')
This method uses the PubChem REST API service to look up synonyms of a PubChem compound based on its name or other allowed namespace. See https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Input.
- Parameters:
s (str) – The string to look up
namespace (str, optional) – The namespace to seach for (for example, ‘name’, ‘cid’, ‘smiles’, …). Default: ‘name’
- Returns:
result – The return value is the list that is stored in the ‘Information’ item of the json dict. This list contains a dict (or perhaps more?) with the CID and a list of synonyms. Returns None if an error occurred.
- Return type:
list
- wadi.api_utils.query_pubchem_cas(s, namespace='name', allow_multiple=False)
This method uses the PubChem REST API service to look up the CAS of a PubChem compound based on its name or other allowed namespace. See https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Input. The CAS number returned is the first number matched by a regular expression in the list of synonyms for the compound.
- Parameters:
s (str) – The string to look up
namespace (str, optional) – The namespace to seach for (for example, ‘name’, ‘cid’, ‘smiles’, …). Default: ‘name’
allow_multiple (bool, optional) – When False only the first CAS that was identified is returned. When True all CAS numbers in the synonym list are returned. Default: False.
- Returns:
result – The return value is the list that is stored in the ‘Information’ item of the json dict. This list contains a dict (or perhaps more?) with the CID and a list of synonyms. Returns None if an error occurred.
- Return type:
list
- wadi.api_utils.get_pubchem_molecular_weight(s, namespace='name')
This method uses the PubChem REST API service to look up the molecular weight of a PubChem compound based on its name or other allowed namespace. See https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Input.
- Parameters:
s (str) – The string to look up
namespace (str, optional) – The namespace to seach for (for example, ‘name’, ‘cid’, ‘smiles’, …). Default: ‘name’
- Returns:
result – The return value is the ‘MolecularWeight’ item of the json dict returned by PubChem or None if an error occurred.
- Return type:
float
- wadi.api_utils.get_pubchem_properties(cids, props)
This method uses the PubChem REST API service to retrieve a table of compound properties for one or more compounds based on their cid(s).
- Parameters:
cids (int, str or list) – The PubChem ID(s) of the compound(s) to look up.
props (str or list) – The names of the properties to return. For possible values see https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Compound-Property-Tables
- Returns:
result – A list with the requested properties, or None if the request was unsuccessful.
- Return type:
list