def get_oxo_results(id_list: list, target_list: list, distance: int) -> list: """ Use list of ontology IDs, datasource targets and distance call function to query OxO and return a list of OxOResults. :param id_list: List of ontology IDs with which to find xrefs using OxO :param target_list: List of ontology datasources to include :param distance: Number of steps to take through xrefs to find mappings :return: List of OxOResults based upon results from request made to OxO """ url = "https://www.ebi.ac.uk/spot/oxo/api/search?size=5000" payload = build_oxo_payload(id_list, target_list, distance) try: oxo_response = json_request(url, payload, requests.post) except requests.HTTPError: # Sometimes, OxO fails to process a completely valid request even after several attempts. # See https://github.com/EBISPOT/OXO/issues/26 for details logger.error( 'OxO failed to process request for id_list {} (probably a known bug in OxO)' .format(id_list)) return [] if oxo_response is None: return [] if "_embedded" not in oxo_response: logger.warning( "Cannot parse the response from OxO for the following identifiers: {}" .format(','.join(id_list))) return [] return get_oxo_results_from_response(oxo_response)
def get_ontology_label_from_ols(ontology_uri: str) -> str: """ Using provided ontology URI, build an OLS URL with which to make a request to find the term label for this URI. :param ontology_uri: A URI for a term in an ontology. :return: Term label for the ontology URI provided in the parameters. """ url = build_ols_query(ontology_uri) json_response = json_request(url) if not json_response: return None # If the '_embedded' section is missing from the response, it means that the term is not found in OLS if '_embedded' not in json_response: if '/medgen/' not in url and '/omim/' not in url: logger.warning( 'OLS queried OK but did not return any results for URL {}'. format(url)) return None # Go through all terms found by the requested identifier and try to find the one where the _identifier_ and the # _term_ come from the same ontology (marked by a special flag). Example of such a situation would be a MONDO term # in the MONDO ontology. Example of a reverse situation is a MONDO term in EFO ontology (being *imported* into it # at some point). for term in json_response["_embedded"]["terms"]: if term["is_defining_ontology"]: return term["label"] if '/medgen/' not in url and '/omim/' not in url: logger.warning( 'OLS queried OK, but there is no defining ontology in its results for URL {}' .format(url)) return None
def get_zooma_uris(trait_name, zooma_host, filters): url = build_zooma_query(trait_name, filters, zooma_host) json_response = json_request(url) if json_response is None: return None uri_set = set() for result in json_response: if result["confidence"].lower() == "high": uri_set.update(result["semanticTags"]) return uri_set