Example #1
0
    def test_is_in_efo(self):
        with requests_mock.mock() as m:
            url = "http://www.ebi.ac.uk/ols/api/ontologies/efo/terms/http%253A%252F%252Fwww.orpha.net%252FORDO%252FOrphanet_425"
            m.get(url,
                  json=test_ols_data.TestIsInEfoData.orphanet_425_ols_efo_json)

            self.assertEqual(
                ols.is_in_efo("http://www.orpha.net/ORDO/Orphanet_425"), True)
    def test_is_in_efo(self):
        with requests_mock.mock() as m:
            url = "https://www.ebi.ac.uk/ols/api/ontologies/efo/terms/http%253A%252F%252Fwww.orpha.net%252FORDO%252FOrphanet_425"
            m.get(url,
                  json=test_ols_data.TestIsInEfoData.orphanet_425_ols_efo_json)

            self.assertEqual(ols.is_in_efo("http://www.orpha.net/ORDO/Orphanet_425"),
                             True)
def find_previous_mapping(trait_name, previous_mappings):
    if trait_name not in previous_mappings:
        return ''
    uri = previous_mappings[trait_name]
    label = get_ontology_label_from_ols(uri)
    uri_is_current_and_in_efo = is_current_and_in_efo(uri)
    uri_in_efo = is_in_efo(uri)
    if uri_in_efo:
        trait_status = 'EFO_CURRENT' if uri_is_current_and_in_efo else 'EFO_OBSOLETE'
    else:
        trait_status = 'NOT_CONTAINED'
    trait_string = '|'.join([uri, label, 'NOT_SPECIFIED', 'previously-used', trait_status])
    return trait_string
def find_previous_mapping(trait_name, previous_mappings):
    if trait_name not in previous_mappings:
        return ''
    uri = previous_mappings[trait_name]
    label = get_ontology_label_from_ols(uri)
    uri_is_current_and_in_efo = is_current_and_in_efo(uri)
    uri_in_efo = is_in_efo(uri)
    if uri_in_efo:
        trait_status = 'EFO_CURRENT' if uri_is_current_and_in_efo else 'EFO_OBSOLETE'
    else:
        trait_status = 'NOT_CONTAINED'
    trait_string = '|'.join(
        [uri, label, 'NOT_SPECIFIED', 'previously-used', trait_status])
    return trait_string
Example #5
0
def get_zooma_results(trait_name: str, filters: dict, zooma_host: str) -> list:
    """
    Given a trait name, Zooma filters in a dict and a hostname to use, query Zooma and return a list
    of Zooma mappings for this trait.

    First get the URI, label from a selected source, confidence and source:
    http://snarf.ebi.ac.uk:8580/spot/zooma/v2/api/services/annotate?propertyValue=intellectual+disability
    Then the ontology label to replace the label from a source:
    http://www.ebi.ac.uk/ols/api/terms?iri=http%3A%2F%2Fwww.ebi.ac.uk%2Fefo%2FEFO_0003847

    :param trait_name: A string containing a trait name from a ClinVar record.
    :param filters: A dictionary containing filters used when querying OxO
    :param zooma_host: Hostname of a Zooma instance to query.
    :return: List of ZoomaResults
    """
    url = build_zooma_query(trait_name, filters, zooma_host)
    zooma_response_list = request_retry_helper(zooma_query_helper, 4, url)

    if zooma_response_list is None:
        return None

    zooma_result_list = get_zooma_results_for_trait(zooma_response_list)

    for zooma_result in zooma_result_list:
        for zooma_mapping in zooma_result.mapping_list:
            label = get_ontology_label_from_ols(zooma_mapping.uri)
            # If no label is returned (shouldn't really happen) keep the existing one
            if label is not None:
                zooma_mapping.ontology_label = label
            else:
                logging.warning(
                    "Couldn't retrieve ontology label from OLS for trait '{}'".
                    format(trait_name))

            uri_is_current_and_in_efo = is_current_and_in_efo(
                zooma_mapping.uri)
            if not uri_is_current_and_in_efo:
                uri_is_in_efo = is_in_efo(zooma_mapping.uri)
                zooma_mapping.in_efo = uri_is_in_efo
            else:
                zooma_mapping.in_efo = uri_is_current_and_in_efo
                zooma_mapping.is_current = uri_is_current_and_in_efo

    return zooma_result_list
Example #6
0
def get_oxo_results_from_response(oxo_response: dict) -> list:
    """
    For a json(/dict) response from an OxO request, parse the data into a list of OxOResults

    :param oxo_response: Response from OxO request
    :return: List of OxOResults based upon the response from OxO
    """
    oxo_result_list = []
    results = oxo_response["_embedded"]["searchResults"]
    for result in results:
        if len(result["mappingResponseList"]) == 0:
            continue
        query_id = result["queryId"]
        label = result["label"]
        curie = result["curie"]
        oxo_result = OxOResult(query_id, label, curie)
        for mapping_response in result["mappingResponseList"]:
            mapping_label = mapping_response["label"]
            mapping_curie = mapping_response["curie"]
            mapping_distance = mapping_response["distance"]
            oxo_mapping = OxOMapping(mapping_label, mapping_curie,
                                     mapping_distance, query_id)

            uri = str(oxo_mapping.uri)

            ontology_label = get_ontology_label_from_ols(uri)
            if ontology_label is not None:
                oxo_mapping.ontology_label = ontology_label

            uri_is_current_and_in_efo = is_current_and_in_efo(uri)
            if not uri_is_current_and_in_efo:
                uri_is_in_efo = is_in_efo(uri)
                oxo_mapping.in_efo = uri_is_in_efo
            else:
                oxo_mapping.in_efo = uri_is_current_and_in_efo
                oxo_mapping.is_current = uri_is_current_and_in_efo

            oxo_result.mapping_list.append(oxo_mapping)

        oxo_result_list.append(oxo_result)

    return oxo_result_list
Example #7
0
def get_oxo_results_from_response(oxo_response: dict) -> list:
    """
    For a json(/dict) response from an OxO request, parse the data into a list of OxOResults

    :param oxo_response: Response from OxO request
    :return: List of OxOResults based upon the response from OxO
    """
    oxo_result_list = []
    results = oxo_response["_embedded"]["searchResults"]
    for result in results:
        if len(result["mappingResponseList"]) == 0:
            continue
        query_id = result["queryId"]
        label = result["label"]
        curie = result["curie"]
        oxo_result = OxOResult(query_id, label, curie)
        for mapping_response in result["mappingResponseList"]:
            mapping_label = mapping_response["label"]
            mapping_curie = mapping_response["curie"]
            mapping_distance = mapping_response["distance"]
            oxo_mapping = OxOMapping(mapping_label, mapping_curie, mapping_distance, query_id)

            uri = str(oxo_mapping.uri)

            ontology_label = get_ontology_label_from_ols(uri)
            if ontology_label is not None:
                oxo_mapping.ontology_label = ontology_label

            uri_is_current_and_in_efo = is_current_and_in_efo(uri)
            if not uri_is_current_and_in_efo:
                uri_is_in_efo = is_in_efo(uri)
                oxo_mapping.in_efo = uri_is_in_efo
            else:
                oxo_mapping.in_efo = uri_is_current_and_in_efo
                oxo_mapping.is_current = uri_is_current_and_in_efo

            oxo_result.mapping_list.append(oxo_mapping)

        oxo_result_list.append(oxo_result)

    return oxo_result_list
Example #8
0
def get_zooma_results(trait_name: str, filters: dict, zooma_host: str) -> list:
    """
    Given a trait name, Zooma filters in a dict and a hostname to use, query Zooma and return a list
    of Zooma mappings for this trait.

    First get the URI, label from a selected source, confidence and source:
    http://snarf.ebi.ac.uk:8580/spot/zooma/v2/api/services/annotate?propertyValue=intellectual+disability
    Then the ontology label to replace the label from a source:
    https://www.ebi.ac.uk/ols/api/terms?iri=http%3A%2F%2Fwww.ebi.ac.uk%2Fefo%2FEFO_0003847

    :param trait_name: A string containing a trait name from a ClinVar record.
    :param filters: A dictionary containing filters used when querying OxO
    :param zooma_host: Hostname of a Zooma instance to query.
    :return: List of ZoomaResults
    """
    url = build_zooma_query(trait_name, filters, zooma_host)
    zooma_response_list = request_retry_helper(zooma_query_helper, 4, url)

    if zooma_response_list is None:
        return None

    zooma_result_list = get_zooma_results_for_trait(zooma_response_list)

    for zooma_result in zooma_result_list:
        for zooma_mapping in zooma_result.mapping_list:
            label = get_ontology_label_from_ols(zooma_mapping.uri)
            # If no label is returned (shouldn't really happen) keep the existing one
            if label is not None:
                zooma_mapping.ontology_label = label
            else:
                logging.warning("Couldn't retrieve ontology label from OLS for trait '{}'".format(trait_name))

            uri_is_current_and_in_efo = is_current_and_in_efo(zooma_mapping.uri)
            if not uri_is_current_and_in_efo:
                uri_is_in_efo = is_in_efo(zooma_mapping.uri)
                zooma_mapping.in_efo = uri_is_in_efo
            else:
                zooma_mapping.in_efo = uri_is_current_and_in_efo
                zooma_mapping.is_current = uri_is_current_and_in_efo

    return zooma_result_list