Skip to content

Commit 6fdbc44

Browse files
committed
Merge branch 'main' into getter-versions
2 parents 67d5c6e + 7357785 commit 6fdbc44

5 files changed

Lines changed: 104 additions & 15 deletions

File tree

src/pyobo/cli/cli.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,7 @@ def _has_no_download(prefix: str) -> bool:
9090
@lru_cache(maxsize=1)
9191
def _no_download() -> set[str]:
9292
"""Get the list of prefixes not available as OBO."""
93-
return {
94-
prefix
95-
for prefix in bioregistry.read_registry()
96-
if bioregistry.get_obo_download(prefix) is None
97-
and bioregistry.get_owl_download(prefix) is None
98-
}
93+
return {resource.prefix for resource in bioregistry.resources() if not resource.has_download()}
9994

10095

10196
main.add_command(lookup)

src/pyobo/getters.py

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

20+
import bioontologies.robot
2021
import bioregistry
2122
import click
2223
import pystow.utils
@@ -252,6 +253,7 @@ def _ensure_ontology_path(
252253
"gwascentral.phenotype": "website is down? or API changed?", # FIXME
253254
"gwascentral.study": "website is down? or API changed?", # FIXME
254255
"snomedct": "dead source",
256+
"ero": "dead",
255257
}
256258

257259
X = TypeVar("X")
@@ -378,7 +380,7 @@ def iter_helper_helper(
378380
if "DrugBank" not in str(e):
379381
raise
380382
logger.warning("[drugbank] invalid credentials")
381-
except subprocess.CalledProcessError:
383+
except (subprocess.CalledProcessError, bioontologies.robot.ROBOTError):
382384
logger.warning("[%s] ROBOT was unable to convert OWL to OBO", prefix)
383385
except ValueError as e:
384386
if _is_xml(e):

src/pyobo/struct/struct.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ def _iterate_property_pairs(self) -> Iterable[Annotation]:
940940
yield Annotation(v.has_license, license_literal)
941941

942942
if description := bioregistry.get_description(self.ontology):
943-
description = obo_escape_slim(description.strip())
944943
yield Annotation(v.has_description, OBOLiteral.string(description.strip()))
945944
if homepage := bioregistry.get_homepage(self.ontology):
946945
yield Annotation(v.has_homepage, OBOLiteral.uri(homepage))
@@ -2307,12 +2306,11 @@ def build_ontology(
23072306
homepage: str | None = None,
23082307
mailing_list: str | None = None,
23092308
logo: str | None = None,
2310-
repository: str | None,
2309+
repository: str | None = None,
23112310
) -> Obo:
23122311
"""Build an ontology from parts."""
2313-
resource = bioregistry.get_resource(prefix, strict=True)
23142312
if name is None:
2315-
name = resource.get_name()
2313+
name = bioregistry.get_name(prefix)
23162314
# TODO auto-populate license and other properties
23172315

23182316
if properties is None:

src/pyobo/utils/misc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"http://purl.dataone.org/odo/SENSO/", # like in http://purl.dataone.org/odo/SENSO/0.1.0
4040
"https://purl.dataone.org/odo/ADCAD/",
4141
"http://identifiers.org/combine.specifications/teddy.rel-",
42+
"https://nfdi.fiz-karlsruhe.de/ontology/",
4243
]
4344
VERSION_PREFIX_SPLITS = [
4445
"http://www.ebi.ac.uk/efo/releases/v",

tests/test_struct/test_obo/test_struct_obo.py

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""Test for OBO header."""
22

3+
import tempfile
34
import unittest
45
from collections.abc import Iterable
6+
from pathlib import Path
57
from textwrap import dedent
68

9+
import bioontologies.robot
10+
711
from pyobo import default_reference
812
from pyobo.struct.reference import OBOLiteral
9-
from pyobo.struct.struct import Obo, make_ad_hoc_ontology
13+
from pyobo.struct.struct import Obo, build_ontology, make_ad_hoc_ontology
1014
from pyobo.struct.struct_utils import Annotation
1115
from pyobo.struct.typedef import has_license
1216

@@ -22,11 +26,33 @@ def assert_obo_lines(self, text, ontology: Obo) -> None:
2226
"""Assert OBO header has the right lines."""
2327
self.assert_lines(text, ontology.iterate_obo_lines())
2428

29+
def assert_ofn_lines(self, text: str, ontology: Obo) -> None:
30+
"""Assert OFN header has the right lines."""
31+
with tempfile.TemporaryDirectory() as directory:
32+
in_path = Path(directory).joinpath("tmp.ofn")
33+
ontology.write_ofn(in_path)
34+
self.assert_lines(text, in_path.read_text().splitlines())
35+
36+
def assert_owl_lines(self, text: str, ontology: Obo) -> None:
37+
"""Assert OWL header has the right lines."""
38+
with tempfile.TemporaryDirectory() as directory:
39+
in_path = Path(directory).joinpath("tmp.ofn")
40+
ontology.write_ofn(in_path)
41+
out_path = Path(directory).joinpath("tmp.owl")
42+
bioontologies.robot.convert(in_path, out_path, check=False)
43+
lines = out_path.read_text().splitlines()
44+
lines = [
45+
"" if not line.strip() else line.rstrip()
46+
for line in lines
47+
if line.strip() and not line.strip().startswith("<!-- Generated by the OWL API")
48+
]
49+
self.assert_lines(text, lines)
50+
2551
def test_2_data_version(self) -> None:
2652
"""Test ontology definition."""
27-
ontology = make_ad_hoc_ontology(
28-
_ontology="xxx",
29-
_data_version="1.0",
53+
ontology = build_ontology(
54+
prefix="xxx",
55+
version="1.0",
3056
)
3157
self.assert_obo_lines(
3258
"""\
@@ -174,6 +200,73 @@ def test_18_properties_bioregistry(self) -> None:
174200
ontology,
175201
)
176202

203+
def test_18_properties_escapes(self) -> None:
204+
"""Test escapes in property values, like for parentheses."""
205+
ontology = build_ontology(
206+
prefix="xxx",
207+
description="MeSH (Medical Subject Headings)",
208+
)
209+
self.assert_obo_lines(
210+
r"""
211+
format-version: 1.4
212+
idspace: dcterms http://purl.org/dc/terms/ "Dublin Core Metadata Initiative Terms"
213+
ontology: xxx
214+
property_value: dcterms:description "MeSH \(Medical Subject Headings\)" xsd:string
215+
216+
[Typedef]
217+
id: dcterms:description
218+
name: description
219+
is_metadata_tag: true
220+
""",
221+
ontology,
222+
)
223+
self.assert_ofn_lines(
224+
"""
225+
Prefix(dcterms:=<http://purl.org/dc/terms/>)
226+
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
227+
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
228+
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
229+
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
230+
231+
Ontology(<https://w3id.org/biopragmatics/resources/xxx/xxx.ofn>
232+
Annotation(dcterms:description "MeSH (Medical Subject Headings)"^^xsd:string)
233+
234+
Declaration(AnnotationProperty(dcterms:description))
235+
AnnotationAssertion(rdfs:label dcterms:description "description")
236+
)
237+
""",
238+
ontology,
239+
)
240+
self.assert_owl_lines(
241+
"""
242+
<?xml version="1.0"?>
243+
<rdf:RDF xmlns="https://w3id.org/biopragmatics/resources/xxx/xxx.ofn#"
244+
xml:base="https://w3id.org/biopragmatics/resources/xxx/xxx.ofn"
245+
xmlns:owl="http://www.w3.org/2002/07/owl#"
246+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
247+
xmlns:xml="http://www.w3.org/XML/1998/namespace"
248+
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
249+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
250+
xmlns:dcterms="http://purl.org/dc/terms/">
251+
<owl:Ontology rdf:about="https://w3id.org/biopragmatics/resources/xxx/xxx.ofn">
252+
<dcterms:description>MeSH (Medical Subject Headings)</dcterms:description>
253+
</owl:Ontology>
254+
<!--
255+
///////////////////////////////////////////////////////////////////////////////////////
256+
//
257+
// Annotation properties
258+
//
259+
///////////////////////////////////////////////////////////////////////////////////////
260+
-->
261+
<!-- http://purl.org/dc/terms/description -->
262+
<owl:AnnotationProperty rdf:about="http://purl.org/dc/terms/description">
263+
<rdfs:label>description</rdfs:label>
264+
</owl:AnnotationProperty>
265+
</rdf:RDF>
266+
""",
267+
ontology,
268+
)
269+
177270
def test_18_properties_external(self) -> None:
178271
"""Test properties."""
179272
ontology = make_ad_hoc_ontology(

0 commit comments

Comments
 (0)