Skip to content

Commit 1b6450a

Browse files
authored
Handle CVX obsolete/replaced/placeholder entries (#171)
* Skip CVX obsolete/placeholder entries * Add replacement info
1 parent ca4ea65 commit 1b6450a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/pyobo/sources/cvx.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pandas as pd
99

10-
from pyobo import Obo, Term
10+
from pyobo import Obo, Reference, Term
1111

1212
__all__ = [
1313
"CVXGetter",
@@ -28,6 +28,11 @@ def iter_terms(self, force: bool = False) -> Iterable[Term]:
2828
return iter_terms()
2929

3030

31+
# This got split, which it's not obvious how to deal with this
32+
MANUAL_OBSOLETE = {"15"}
33+
REPLACEMENTS = {"31": "85", "154": "86", "180": "13"}
34+
35+
3136
def iter_terms() -> Iterable[Term]:
3237
"""Iterate over terms in CVX."""
3338
dd = defaultdict(set)
@@ -60,11 +65,22 @@ def iter_terms() -> Iterable[Term]:
6065
cvx_df[col] = cvx_df[col].map(lambda s: s.strip() if pd.notna(s) else s)
6166
terms = {}
6267
for cvx, short_name, full_name, notes, status, nonvaccine, _updated in cvx_df.values:
63-
term = Term.from_triple(PREFIX, cvx, full_name)
68+
if cvx == "99":
69+
continue # this is a placeholder
70+
71+
is_obsolete = cvx in MANUAL_OBSOLETE or (pd.notna(notes) and "do not use" in notes.lower())
72+
term = Term(
73+
reference=Reference(prefix=PREFIX, identifier=cvx, name=full_name),
74+
is_obsolete=is_obsolete,
75+
)
6476
if short_name != full_name:
6577
term.append_synonym(short_name)
6678
if pd.notna(notes):
6779
term.append_comment(notes)
80+
if is_obsolete:
81+
replacement_identifier = REPLACEMENTS.get(cvx)
82+
if replacement_identifier:
83+
term.append_replaced_by(Reference(prefix=PREFIX, identifier=replacement_identifier))
6884
if pd.notna(status):
6985
term.append_property("status", status)
7086
if pd.notna(nonvaccine):

src/pyobo/struct/struct.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
orthologous,
5454
part_of,
5555
see_also,
56+
term_replaced_by,
5657
)
5758
from .utils import comma_separate, obo_escape_slim
5859
from ..constants import (
@@ -299,6 +300,11 @@ def append_comment(self, value: str) -> "Term":
299300
self.append_property(comment.curie, value)
300301
return self
301302

303+
def append_replaced_by(self, reference: ReferenceHint) -> "Term":
304+
"""Add a replaced by relationship."""
305+
self.append_relationship(term_replaced_by, reference)
306+
return self
307+
302308
def append_parent(self, reference: ReferenceHint) -> "Term":
303309
"""Add a parent to this entity."""
304310
reference = _ensure_ref(reference)

0 commit comments

Comments
 (0)