Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UMLS STY #306

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/pyobo/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from .sgd import SGDGetter
from .signor import SignorGetter
from .slm import SLMGetter
from .umls import UMLSGetter
from .umls import UMLSGetter, UMLSSTyGetter
from .unimod import UnimodGetter
from .uniprot import UniProtGetter, UniProtPtmGetter
from .wikipathways import WikiPathwaysGetter
Expand Down Expand Up @@ -125,6 +125,7 @@
"SLMGetter",
"SignorGetter",
"UMLSGetter",
"UMLSSTyGetter",
"UniProtGetter",
"UniProtPtmGetter",
"UnimodGetter",
Expand Down
2 changes: 2 additions & 0 deletions src/pyobo/sources/umls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Converter for UMLS."""

from .sty import UMLSSTyGetter
from .umls import UMLSGetter

__all__ = [
"UMLSGetter",
"UMLSSTyGetter",
]
57 changes: 57 additions & 0 deletions src/pyobo/sources/umls/sty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Converter for UMLS Semantic Types."""

from collections.abc import Iterable

from pyobo import Obo, Reference, Term, default_reference
from pyobo.struct.typedef import has_category
from pyobo.utils.path import ensure_df

__all__ = [
"UMLSSTyGetter",
]

PREFIX = "sty"

URL = "https://www.nlm.nih.gov/research/umls/knowledge_sources/semantic_network/SemGroups.txt"


class UMLSSTyGetter(Obo):
"""An ontology representation of UMLS Semantic Types."""

ontology = PREFIX
bioversions_key = "umls"
typedefs = [has_category]

def iter_terms(self, force: bool = False) -> Iterable[Term]:
"""Iterate over terms in the ontology."""
return iter_terms(version=self._version_or_raise)


COLUMNS = [
"group",
"group_label",
"sty_id",
"sty_name",
]


def iter_terms(version: str) -> Iterable[Term]:
"""Iterate over UMLS terms."""
df = ensure_df(PREFIX, url=URL, version=version, sep="|", header=None, names=COLUMNS)

extras = {
group: Term(
reference=default_reference(PREFIX, group, name=group_label),
)
for group, group_label in df[["group", "group_label"]].drop_duplicates().values
}
yield from extras.values()

for group, _group_label, sty_id, sty_name in df.values:
term = Term(reference=Reference(prefix="sty", identifier=sty_id, name=sty_name))
term.append_parent(extras[group])
yield term


if __name__ == "__main__":
UMLSSTyGetter.cli()
Loading