Skip to content
Merged
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
19 changes: 9 additions & 10 deletions pori_python/graphkb/vocab.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Callable, Dict, Iterable, List, Set, cast, Union
from typing import Callable, Dict, Iterable, List, Set, Union, cast

from pori_python.types import Ontology

from . import GraphKBConnection
from .util import convert_to_rid_list

DEFAULT_RETURN_PROPERTIES = ['sourceId', 'sourceIdVersion', 'deprecated', 'name', '@rid']


def query_by_name(ontology_class: str, base_term_name: Union[str, list[str]]) -> Dict:
return {'target': ontology_class, 'filters': {'name': base_term_name}}
Expand All @@ -17,6 +19,7 @@ def get_equivalent_terms(
ontology_class: str = 'Vocabulary',
ignore_cache: bool = False,
build_base_query: Callable = query_by_name,
return_properties=DEFAULT_RETURN_PROPERTIES,
) -> List[Ontology]:
"""
Get a list of terms equivalent to the current term up to the root term
Expand All @@ -35,7 +38,7 @@ def get_equivalent_terms(
'target': {'target': base_records, 'queryType': 'descendants'},
'queryType': 'similarTo',
'treeEdges': [],
'returnProperties': ['sourceId', 'sourceIdVersion', 'deprecated', 'name', '@rid'],
'returnProperties': return_properties,
},
ignore_cache=ignore_cache,
),
Expand All @@ -54,13 +57,7 @@ def get_equivalent_terms(
'target': {'target': root_records, 'queryType': 'descendants'},
'queryType': 'similarTo',
'treeEdges': [],
'returnProperties': [
'sourceId',
'sourceIdVersion',
'deprecated',
'name',
'@rid',
],
'returnProperties': ['@rid'],
},
ignore_cache=ignore_cache,
)
Expand All @@ -78,6 +75,7 @@ def get_term_tree(
include_superclasses: bool = True,
ignore_cache: bool = False,
build_base_query: Callable = query_by_name,
return_properties=DEFAULT_RETURN_PROPERTIES,
) -> List[Ontology]:
"""
Get terms equivalent to the base term by traversing the subclassOf tree and expanding related
Expand Down Expand Up @@ -105,7 +103,7 @@ def get_term_tree(
'target': {'target': base_records, 'queryType': 'ancestors'},
'queryType': 'similarTo',
'treeEdges': [],
'returnProperties': ['sourceId', 'sourceIdVersion', 'deprecated', 'name', '@rid'],
'returnProperties': return_properties,
},
ignore_cache=ignore_cache,
),
Expand All @@ -119,6 +117,7 @@ def get_term_tree(
ontology_class=ontology_class,
ignore_cache=ignore_cache,
build_base_query=build_base_query,
return_properties=return_properties,
)
else:
parent_terms = []
Expand Down
Loading