Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def parse_obo_file(file_iterator):
'is_category': False,
}
elif line.startswith("is_a: "):
# OBO format: "<id>" optionally followed by " ! <label>" and/or trailing " {<modifiers>}"
is_a = re.sub(r'\s*\{[^}]*\}\s*$', '', value).split(' ! ')[0].strip()
# Match the HPO id directly; OBO modifiers ({...}) and comments (! ...) may appear in any order around it.
match = re.search(r'HP:\d{7}', value)
if not match:
raise ValueError("is_a line missing HPO id: %s" % line)
is_a = match.group(0)
if is_a == "HP:0000118":
hpo_id_to_record[hpo_id]['is_category'] = True
hpo_id_to_record[hpo_id]['parent_id'] = is_a
Expand Down
19 changes: 16 additions & 3 deletions reference_data/management/tests/update_hpo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@
'name: trailer with xref only\n',
'is_a: HP:0000118 {xref="PMID:31677808"}\n',
'\n',
'[Term]\n', # is_a with label and xref
'[Term]\n', # is_a with label and xref (label then modifier)
'id: HP:9999002\n',
'name: trailer with label and xref\n',
'is_a: HP:0000118 ! Phenotypic abnormality {xref="PMID:31677808"}\n',
'\n',
'[Term]\n', # is_a with xref then label (OBO 1.4 standard ordering)
'id: HP:9999003\n',
'name: trailer with xref then label\n',
'is_a: HP:0000118 {xref="PMID:31677808"} ! Phenotypic abnormality\n',
]

EXPECTED_DB_DATA = {
Expand Down Expand Up @@ -150,6 +155,14 @@
'hpo_id': 'HP:9999002',
'category_id': 'HP:9999002',
},
'HP:9999003': {
'is_category': True,
'definition': None,
'name': 'trailer with xref then label',
'parent_id': 'HP:0000118',
'hpo_id': 'HP:9999003',
'category_id': 'HP:9999003',
},
}

class UpdateHpoTest(TestCase):
Expand Down Expand Up @@ -178,7 +191,7 @@ def test_update_hpo_command(self, mock_tempfile, mock_logger):
call_command('update_human_phenotype_ontology')

calls = [
mock.call('Deleting HumanPhenotypeOntology table with 12 records and creating new table with 7 records'),
mock.call('Deleting HumanPhenotypeOntology table with 12 records and creating new table with 8 records'),
mock.call('Done'),
]
mock_logger.info.assert_has_calls(calls)
Expand All @@ -189,7 +202,7 @@ def test_update_hpo_command(self, mock_tempfile, mock_logger):
call_command('update_human_phenotype_ontology', tmp_file)

calls = [
mock.call('Deleting HumanPhenotypeOntology table with 7 records and creating new table with 7 records'),
mock.call('Deleting HumanPhenotypeOntology table with 8 records and creating new table with 8 records'),
mock.call('Done'),
]
mock_logger.info.assert_has_calls(calls)
Expand Down
Loading