Skip to content

Commit

Permalink
Merge pull request #164 from biolink/handle_names_in_descendants
Browse files Browse the repository at this point in the history
Handle aliases in queries for  get_descendants
  • Loading branch information
sierra-moxon authored Apr 8, 2024
2 parents 5a1dedc + 89b7eee commit 3382ee7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [ "3.9", "3.10" ]
python: [ "3.9", "3.10", "3.11" ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/initialize-toolkit-daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [ "3.9", "3.10" ]
python: [ "3.9", "3.10", "3.11" ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [ "3.9", "3.10" ]
python: [ "3.9", "3.10", "3.11" ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
7 changes: 5 additions & 2 deletions bmt/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Url = str
Path = str

LATEST_BIOLINK_RELEASE = "4.1.5"
LATEST_BIOLINK_RELEASE = "4.1.6"

REMOTE_PATH = f"https://raw.githubusercontent.com/biolink/biolink-model/v{LATEST_BIOLINK_RELEASE}/biolink-model.yaml"
PREDICATE_MAP = f"https://raw.githubusercontent.com/biolink/biolink-model/v{LATEST_BIOLINK_RELEASE}/predicate_mapping.yaml"
Expand Down Expand Up @@ -884,8 +884,11 @@ def get_element(self, name: str) -> Optional[Element]:
logger.debug(parsed_name)
element = self.view.get_element(parsed_name)
if element is None and self.view.all_aliases() is not None:
if parsed_name.startswith("biolink:"):
parsed_name = parsed_name.replace("biolink:", "")
parsed_name = parsed_name.replace("_", " ")
for e in self.view.all_aliases():
if name in self.view.all_aliases()[e]:
if name in self.view.all_aliases()[e] or parsed_name in self.view.all_aliases()[e]:
element = self.view.get_element(e)
if element is None and "_" in name:
element = self.get_element(name.replace("_", " "))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bmt"
version = "1.1.2.post14.dev0+08be61e"
version = "1.2.1"
description = "Biolink Model Toolkit: A Python API for working with the Biolink Model"
authors = ["Sierra Taylor Moxon <[email protected]>"]
license = "BSD"
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def test_not_valid_edge(toolkit):

def test_get_element_via_alias(toolkit):
el = toolkit.get_element('definition')
pred_alias = toolkit.get_element("biolink:realized_in_response_to")
print(pred_alias)
ameliorates_aliase = toolkit.get_element("biolink:ameliorates")
assert ameliorates_aliase.name == "ameliorates condition"
assert pred_alias.name == "caused by"
assert el.name == 'description'


Expand Down Expand Up @@ -885,6 +890,9 @@ def test_descendants(toolkit):
assert INTERACTS_WITH in toolkit.get_descendants(RELATED_TO)
assert PHENOTYPIC_FEATURE in toolkit.get_descendants(NAMED_THING)
assert RELATED_TO not in toolkit.get_descendants(NAMED_THING)
assert "ameliorates condition" in toolkit.get_descendants("biolink:ameliorates")
assert "biolink:ameliorates_condition" in toolkit.get_descendants("biolink:ameliorates", formatted=True)

with pytest.raises(ValueError):
toolkit.get_descendants('biolink:invalid')
assert "biolink:PhenotypicFeature" in toolkit.get_descendants(
Expand Down

0 comments on commit 3382ee7

Please sign in to comment.