Skip to content

Commit da7534c

Browse files
authored
Externalize ROBOT (#474)
1 parent 5a17f25 commit da7534c

6 files changed

Lines changed: 19 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ dependencies = [
7171
"pystow>=0.7.5",
7272
"bioversions>=0.8.243",
7373
"bioregistry>=0.12.30",
74-
"bioontologies>=0.7.2",
7574
"ssslm>=0.0.13",
7675
"zenodo-client>=0.4.1",
7776
"class_resolver>=0.6.0",
@@ -92,6 +91,7 @@ dependencies = [
9291
"obographs>=0.0.8",
9392
"sssom_pydantic>=0.2.0",
9493
"pytz",
94+
"robot-obo-tool",
9595
]
9696

9797
# see https://peps.python.org/pep-0735/ and https://docs.astral.sh/uv/concepts/dependencies/#dependency-groups

src/pyobo/getters.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from textwrap import indent
1818
from typing import Any, TypeVar
1919

20-
import bioontologies.robot
2120
import bioregistry
2221
import click
2322
import pystow.utils
@@ -80,10 +79,10 @@ class UnhandledFormatError(NoBuildError):
8079

8180

8281
def _convert_to_obo(path: Path) -> Path:
83-
import bioontologies.robot
82+
import robot_obo_tool
8483

8584
_converted_obo_path = path.with_suffix(".obo")
86-
bioontologies.robot.convert(path, _converted_obo_path, check=False)
85+
robot_obo_tool.convert(path, _converted_obo_path, check=False)
8786
return _converted_obo_path
8887

8988

@@ -338,6 +337,8 @@ def iter_helper_helper(
338337
339338
:yields: A prefix and the result of the callable ``f``
340339
"""
340+
from robot_obo_tool import ROBOTError
341+
341342
strict = kwargs.get("strict", True)
342343
prefixes = list(
343344
_prefixes(
@@ -382,7 +383,7 @@ def iter_helper_helper(
382383
if "DrugBank" not in str(e):
383384
raise
384385
logger.warning("[drugbank] invalid credentials")
385-
except (subprocess.CalledProcessError, bioontologies.robot.ROBOTError):
386+
except (subprocess.CalledProcessError, ROBOTError):
386387
logger.warning("[%s] ROBOT was unable to convert OWL to OBO", prefix)
387388
except ValueError as e:
388389
if _is_xml(e):

src/pyobo/struct/functional/ontology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def to_funowl_args(self) -> str:
250250

251251
def get_rdf_graph_oracle(boxes: list[Box], *, prefix_map: dict[str, str]) -> Graph:
252252
"""Serialize to turtle via OFN and conversion with ROBOT."""
253-
import bioontologies.robot
253+
import robot_obo_tool
254254

255255
ontology = Ontology(
256256
iri=EXAMPLE_ONTOLOGY_IRI,
@@ -265,7 +265,7 @@ def get_rdf_graph_oracle(boxes: list[Box], *, prefix_map: dict[str, str]) -> Gra
265265
ofn_path.write_text(text)
266266
ttl_path = stub.with_suffix(".ttl")
267267
try:
268-
bioontologies.robot.convert(ofn_path, ttl_path)
268+
robot_obo_tool.convert(ofn_path, ttl_path)
269269
except subprocess.CalledProcessError:
270270
raise RuntimeError(f"failed to convert axioms from:\n\n{text}") from None
271271
graph.parse(ttl_path)

src/pyobo/struct/obograph/export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_parsed_obograph_oracle(
3333
obo: Obo, *, converter: Converter | None = None
3434
) -> og.StandardizedGraphDocument:
3535
"""Serialize to OBO, convert to OBO Graph JSON with ROBOT, load, then parse."""
36-
import bioontologies.robot
36+
import robot_obo_tool
3737

3838
if converter is None:
3939
converter = get_converter()
@@ -43,7 +43,7 @@ def to_parsed_obograph_oracle(
4343
obo_path = stub.with_suffix(".obo")
4444
obograph_path = stub.with_suffix(".json")
4545
obo.write_obo(obo_path)
46-
bioontologies.robot.convert(input_path=obo_path, output_path=obograph_path)
46+
robot_obo_tool.convert(input_path=obo_path, output_path=obograph_path)
4747
raw = og.read(obograph_path, squeeze=False)
4848
rv = raw.standardize(converter)
4949
for graph in rv.graphs:

src/pyobo/struct/struct.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,12 +1067,12 @@ def write_ofn(self, path: str | Path) -> None:
10671067

10681068
def write_owl(self, path: str | Path) -> None:
10691069
"""Write OWL, by first outputting OFN then converting with ROBOT."""
1070-
from bioontologies import robot
1070+
import robot_obo_tool
10711071

10721072
with tempfile.TemporaryDirectory() as directory:
10731073
ofn_path = Path(directory).joinpath("tmp.ofn")
10741074
self.write_ofn(ofn_path)
1075-
robot.convert(ofn_path, path)
1075+
robot_obo_tool.convert(ofn_path, path)
10761076

10771077
def write_rdf(self, path: str | Path) -> None:
10781078
"""Write as Turtle RDF."""
@@ -1312,19 +1312,19 @@ def write_default(
13121312
tqdm.write(f"[{self._prefix_version}] writing OBO Graph to {self._obograph_path}")
13131313
self.write_obograph(self._obograph_path)
13141314
else:
1315-
import bioontologies.robot
1315+
import robot_obo_tool
13161316

13171317
tqdm.write(
13181318
f"[{self.ontology}] converting OFN to OBO Graph at {self._obograph_path}"
13191319
)
1320-
bioontologies.robot.convert(
1320+
robot_obo_tool.convert(
13211321
self._ofn_path, self._obograph_path, debug=True, merge=False, reason=False
13221322
)
13231323
if write_owl and (not self._owl_path.is_file() or force):
13241324
tqdm.write(f"[{self._prefix_version}] writing OWL to {self._owl_path}")
1325-
import bioontologies.robot
1325+
import robot_obo_tool
13261326

1327-
bioontologies.robot.convert(
1327+
robot_obo_tool.convert(
13281328
self._ofn_path, self._owl_path, debug=True, merge=False, reason=False
13291329
)
13301330
if write_ttl and (not self._ttl_path.is_file() or force):

tests/test_struct/test_obo/test_struct_obo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pathlib import Path
77
from textwrap import dedent
88

9-
import bioontologies.robot
9+
import robot_obo_tool
1010

1111
from pyobo import default_reference
1212
from pyobo.struct.reference import OBOLiteral
@@ -33,7 +33,7 @@ def assert_ofn_lines(self, text: str, ontology: Obo, oracle: bool = False) -> No
3333
if oracle:
3434
tmp_path = Path(directory).joinpath("tmp.obo")
3535
ontology.write_obo(tmp_path)
36-
bioontologies.robot.convert(tmp_path, in_path, check=True, debug=True)
36+
robot_obo_tool.convert(tmp_path, in_path, check=True, debug=True)
3737
else:
3838
ontology.write_ofn(in_path)
3939
self.assert_lines(text, in_path.read_text().splitlines())
@@ -50,7 +50,7 @@ def assert_owl_lines(self, text: str, ontology: Obo, method: str = "ofn") -> Non
5050
else:
5151
raise ValueError
5252
out_path = Path(directory).joinpath("tmp.owl")
53-
bioontologies.robot.convert(in_path, out_path, check=True, debug=True)
53+
robot_obo_tool.convert(in_path, out_path, check=True, debug=True)
5454
lines = out_path.read_text().splitlines()
5555
lines = [
5656
"" if not line.strip() else line.rstrip()

0 commit comments

Comments
 (0)