diff --git a/bin/trait_mapping/create_table_for_manual_curation.py b/bin/trait_mapping/create_table_for_manual_curation.py index af5c71af..0517ab41 100755 --- a/bin/trait_mapping/create_table_for_manual_curation.py +++ b/bin/trait_mapping/create_table_for_manual_curation.py @@ -35,7 +35,8 @@ def find_replacement_mapping(trait_name, previous_uri, ontology, preferred_ontol preferred_ontologies) # If this term is also obsolete, try to find its replacement (at most max_depth times) if mapping_source == MappingSource.TARGET_OBSOLETE and replacement_uri.startswith('http') and max_depth > 0: - return find_replacement_mapping(replacement_uri, ontology, preferred_ontologies, max_depth-1) + return find_replacement_mapping(trait_name, replacement_uri, ontology, preferred_ontologies, + max_depth=max_depth-1) trait_string = '|'.join([replacement_uri, label, str(match_type), mapping_source.to_string(ontology, preferred_ontologies)]) return trait_string diff --git a/tests/trait_mapping/test_create_table.py b/tests/trait_mapping/test_create_table.py index 1ce9759e..680f9b5c 100644 --- a/tests/trait_mapping/test_create_table.py +++ b/tests/trait_mapping/test_create_table.py @@ -1,6 +1,6 @@ import pytest -from bin.trait_mapping.create_table_for_manual_curation import get_mapping_attributes_from_ols +from bin.trait_mapping.create_table_for_manual_curation import get_mapping_attributes_from_ols, find_replacement_mapping from cmat.trait_mapping.ols import MappingSource, MatchType @@ -15,3 +15,20 @@ def test_get_mapping_attributes(): assert label == 'WAGR syndrome' assert match_type == MatchType.EXACT_MATCH_SYNONYM assert mapping_source == MappingSource.TARGET_CURRENT + + +@pytest.mark.integration +def test_find_replacement_mapping(): + trait_name = 'genetic transient congenital hypothyroidism' + target_ontology = 'efo' + preferred_ontologies = ['mondo', 'hp'] + + # Current in EFO - no replacement term + assert find_replacement_mapping(trait_name, 'http://purl.obolibrary.org/obo/MONDO_0011792', target_ontology, preferred_ontologies) == '' + + # Deprecated in EFO with current replacement term + assert find_replacement_mapping(trait_name, 'http://www.ebi.ac.uk/efo/EFO_0000665', target_ontology, preferred_ontologies) == 'http://purl.obolibrary.org/obo/MONDO_0037939|porphyria|TOKEN_MATCH_SYNONYM|EFO_CURRENT' + + # Deprecated in EFO but replacement is also deprecated. + # The replacement itself has a replacement in Mondo but not in EFO, so no replacement is found + assert find_replacement_mapping(trait_name, 'http://www.orpha.net/ORDO/Orphanet_226316', target_ontology, preferred_ontologies) == ''