Skip to content

Commit

Permalink
Merge pull request #117 from biolink/fix_uri_for
Browse files Browse the repository at this point in the history
add class and slot uris in get_element method, fixes #116
  • Loading branch information
sierra-moxon authored Mar 20, 2023
2 parents bbdec06 + baee8ea commit 10ecfbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bmt/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ def get_element(self, name: str) -> Optional[Element]:
for e, el in self.view.all_elements().items():
if el.name.lower() == name.lower():
element = el

if type(element) == ClassDefinition and element.class_uri is None:
element.class_uri = format_element(element)
if type(element) == SlotDefinition and element.slot_uri is None:
element.slot_uri = format_element(element)
return element

def get_slot_domain(
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_get_model_version(toolkit):

def test_get_id_prefixes(toolkit):
tclass = toolkit.get_element('biolink:Gene')
print(tclass.id_prefixes)
assert tclass.class_uri == "biolink:Gene"


def test_get_element_via_alias(toolkit):
Expand Down Expand Up @@ -351,6 +351,10 @@ def test_is_permissible_value_of_enum(toolkit):

def test_ancestors(toolkit):
assert RELATED_TO in toolkit.get_ancestors(CAUSES)
a = toolkit.get_ancestors(GENE)
ancs = [toolkit.get_element(ai)['class_uri'] for ai in a]
assert "biolink:NamedThing" in ancs

assert "biolink:ChemicalEntityOrGeneOrGeneProduct" in toolkit.get_ancestors(
GENE, formatted=True
)
Expand Down Expand Up @@ -381,6 +385,8 @@ def test_ancestors(toolkit):
)
assert THING_WITH_TAXON in toolkit.get_ancestors(PHENOTYPIC_FEATURE)

assert GENE not in toolkit.get_ancestors("biolink:ChemicalEntity", reflexive=False)


def test_permissible_value_ancestors(toolkit):
assert "increased" in toolkit.get_permissible_value_ancestors("upregulated", "DirectionQualifierEnum")
Expand Down

0 comments on commit 10ecfbd

Please sign in to comment.