developer.autocomplete_metadata module

Script for membrane metadata autocomplete.

This script will try to fill further attributes in a membrane metadata file based on the information queried with the inchikey from: - UniChem - ChEMBL - ChEBI - PubChem - CAS Common Chemistry (requires the CAS_API_KEY environment variable)

Note

This file is meant to be used by automated workflows.

Several upstream services (notably EBI’s UniChem and ChEBI) intermittently answer with transient 5xx errors. Requests are therefore retried a few times with exponential backoff that honors any Retry-After header, so a blip does not abort metadata completion while staying polite to the servers. The retry budget can be overridden with the AUTOCOMPLETE_MAX_RETRIES environment variable (set it to 0 to disable retries entirely).

developer.autocomplete_metadata.fetch(req, timeout=15)[source]

Open req (a URL string or urllib.request.Request) robustly.

Returns the response body as bytes for an HTTP 200 response, or None when the resource is unavailable. Transient failures (HTTP 429/5xx and connection-level errors such as timeouts) are retried with backed-off, Retry-After-aware delays; definitive errors (e.g. 404) are not retried.

developer.autocomplete_metadata.fetch_json(req, timeout=15)[source]

Like fetch(), but decode the body as JSON. Returns None on any failure (request error or malformed payload).

developer.autocomplete_metadata.get_chembl(inchikey)[source]
developer.autocomplete_metadata.get_pubchem(inchikey)[source]
developer.autocomplete_metadata.get_pubchem_synonyms(cid)[source]
developer.autocomplete_metadata.get_chebi(chebi_id)[source]
developer.autocomplete_metadata.get_metabolights(chebi_id)[source]
developer.autocomplete_metadata.get_cas(inchikey)[source]
developer.autocomplete_metadata.get_unichem(inchikey)[source]
developer.autocomplete_metadata.extract_sameas(sources)[source]
developer.autocomplete_metadata.get_chembl_id_from_unichem(sources)[source]
developer.autocomplete_metadata.clean_text(value)[source]
developer.autocomplete_metadata.safe_float(value)[source]
developer.autocomplete_metadata.sanitize_sameas(sameas)[source]
developer.autocomplete_metadata.load_existing_metadata(path)[source]
developer.autocomplete_metadata.update_metadata(existing, new_data)[source]
developer.autocomplete_metadata.main()[source]