Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

make ontology work with any kind of parental relationships #540

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 13 additions & 9 deletions bionty_base/_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def to_df(
self,
source: Optional[str] = None,
include_id_prefixes: Optional[Dict[str, List[str]]] = None,
include_rel: Optional[str] = None,
):
"""Convert pronto.Ontology to a DataFrame with columns id, name, parents."""

Expand Down Expand Up @@ -90,17 +91,20 @@ def filter_include_id_prefixes(terms: pronto.ontology._OntologyTerms):
synonyms = None # type:ignore

# get 1st degree parents as a list
superclasses = [
s.id
for s in term.superclasses(distance=1, with_self=False).to_set()
]
if include_rel is not None:
if include_rel in [i.id for i in term.relationships]:
superclasses.extend([s.id for s in term.objects(self.get_relationship(include_rel))])
if prefix_list is not None:
superclasses = [
s.id
for s in term.superclasses(distance=1, with_self=False).to_set()
if s.id.startswith(tuple(prefix_list))
]
else:
superclasses = [
s.id
for s in term.superclasses(distance=1, with_self=False).to_set()
]
s
for s in superclasses
if s.startswith(tuple(prefix_list))
]


df_values.append((term.id, term.name, definition, synonyms, superclasses))

Expand Down
Loading