Skip to content

Commit

Permalink
Adding some preliminary KGCL bindings.
Browse files Browse the repository at this point in the history
These may move to another package - see althonos/pronto#180
  • Loading branch information
cmungall committed Jul 6, 2022
1 parent c127546 commit 39a7a09
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/oaklib/implementations/pronto/pronto_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,15 @@ def apply_patch(self, patch: kgcl.Change) -> None:
elif isinstance(patch, kgcl.NodeObsoletion):
t = self._entity(patch.about_node, strict=True)
t.obsolete = True
elif isinstance(patch, kgcl.NodeDeletion):
t = self._entity(patch.about_node, strict=True)
raise NotImplementedError
elif isinstance(patch, kgcl.NodeCreation):
self.create_entity(patch.about_node, patch.name)
elif isinstance(patch, kgcl.SynonymReplacement):
t = self._entity(patch.about_node, strict=True)
for syn in t.synonyms:
if syn.description == patch.old_value:
syn.description = patch.new_value
else:
raise NotImplementedError
21 changes: 18 additions & 3 deletions tests/test_implementations/test_pronto.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
INPUT_DIR,
NUCLEUS,
OUTPUT_DIR,
VACUOLE,
VACUOLE, NUCLEAR_ENVELOPE, CELLULAR_COMPONENT,
)

TEST_ONT = INPUT_DIR / "go-nucleus.obo"
Expand All @@ -42,7 +42,6 @@ def setUp(self) -> None:
def test_obo_json(self) -> None:
resource = OntologyResource(slug="go-nucleus.json", directory=INPUT_DIR, local=True)
json_oi = ProntoImplementation(resource)
self.oi
curies = list(json_oi.all_entity_curies())
# for e in curies:
# print(e)
Expand Down Expand Up @@ -315,4 +314,20 @@ def test_patcher(self):
oi.apply_patch(kgcl.NodeObsoletion(id=generate_change_id(), about_node=NUCLEUS))
with self.assertRaises(ValueError):
oi.apply_patch(kgcl.NodeObsoletion(id="x", about_node="NO SUCH TERM"))
oi.dump(str(OUTPUT_DIR / "post-kgcl.obo"), syntax="obo")
#oi.apply_patch(kgcl.NodeDeletion(id=generate_change_id(), about_node=NUCLEAR_ENVELOPE))
oi.apply_patch(kgcl.SynonymReplacement(id="x",
about_node=CELLULAR_COMPONENT,
old_value="subcellular entity",
new_value="foo bar"))
out_file = str(OUTPUT_DIR / "post-kgcl.obo")
oi.dump(out_file, syntax="obo")
resource = OntologyResource(slug=out_file, local=True)
oi2 = ProntoImplementation(resource)
self.assertCountEqual(["cell or subcellular entity",
"cellular component",
"cellular_component",
"foo bar"],
oi2.aliases_by_curie(CELLULAR_COMPONENT))



0 comments on commit 39a7a09

Please sign in to comment.