Skip to content

Commit

Permalink
Merge pull request #145 from BIH-CEI/144-hpo
Browse files Browse the repository at this point in the history
144 hpo
  • Loading branch information
frehburg authored Oct 4, 2024
2 parents 029fbdd + 95f36c3 commit b822f86
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/phenopacket_mapper/api_requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from .api_request_super_class import APIRequestSuperClass
from .get import get
from .orpha_api_request import OrphaAPIRequest
from .hpo_api_request import HPOAPIRequest

__all__ = [
"APIRequestSuperClass",
"get",
"OrphaAPIRequest",
"HPOAPIRequest",

]
27 changes: 27 additions & 0 deletions src/phenopacket_mapper/api_requests/hpo_api_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Union

from phenopacket_mapper.data_standards import CodeSystem
from phenopacket_mapper.api_requests import APIRequestSuperClass
from phenopacket_mapper.api_requests import get as rest_get
from phenopacket_mapper.data_standards import Coding, HPO


class HPOAPIRequest(APIRequestSuperClass):
"""A class to request data from the HPO API."""

api_base_url = "https://ontology.jax.org/api/hp/terms/HP:"

def __init__(self, hpo_code_system: CodeSystem = HPO) -> None:
self.hpo_code_system = hpo_code_system

def get(self, concept_id: Union[str, int]) -> Coding:
"""Get details about a concept from the Orphanet API."""
json = rest_get(self.api_base_url + str(concept_id), json=True)

name = json['name']

return Coding(
system=self.hpo_code_system,
code=str(concept_id),
display=name
)
4 changes: 3 additions & 1 deletion src/phenopacket_mapper/api_requests/orpha_api_request.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

from bs4 import BeautifulSoup

from phenopacket_mapper.data_standards import CodeSystem
Expand All @@ -14,7 +16,7 @@ class OrphaAPIRequest(APIRequestSuperClass):
def __init__(self, orpha_code_system: CodeSystem = ORDO) -> None:
self.orpha_code_system = orpha_code_system

def get(self, concept_id: int) -> Coding:
def get(self, concept_id: Union[str, int]) -> Coding:
"""Get details about a concept from the Orphanet API."""
html = rest_get(self.api_base_url + str(concept_id))

Expand Down
7 changes: 7 additions & 0 deletions tests/api_requests/test_hpo_api_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from phenopacket_mapper.api_requests.hpo_api_request import HPOAPIRequest
from phenopacket_mapper.data_standards import Coding, HPO


def test_hpo_api_request():
hp = HPOAPIRequest()
assert hp.get("0000098") == Coding(system=HPO, code="0000098", display="Tall stature")

0 comments on commit b822f86

Please sign in to comment.