Skip to content
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dependencies = [
"cachier",
"pystow>=0.7.0",
"bioversions>=0.8.44",
"bioregistry>=0.12.27",
"bioregistry>=0.12.30",
"bioontologies>=0.7.2",
"ssslm>=0.0.13",
"zenodo-client>=0.3.6",
Expand Down
60 changes: 59 additions & 1 deletion src/pyobo/struct/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,10 +939,21 @@ def _iterate_property_pairs(self) -> Iterable[Annotation]:
license_literal = OBOLiteral.string(license_spdx_id)
yield Annotation(v.has_license, license_literal)

# Description
if description := bioregistry.get_description(self.ontology):
description = obo_escape_slim(description.strip())
yield Annotation(v.has_description, OBOLiteral.string(description.strip()))
if homepage := bioregistry.get_homepage(self.ontology):
yield Annotation(v.has_homepage, OBOLiteral.uri(homepage))
if repository := bioregistry.get_repository(self.ontology):
yield Annotation(v.has_repository, OBOLiteral.uri(repository))
if logo := bioregistry.get_logo(self.ontology):
yield Annotation(v.has_logo, OBOLiteral.uri(logo))
if mailing_list := bioregistry.get_mailing_list(self.ontology):
yield Annotation(v.has_mailing_list, OBOLiteral.string(mailing_list))
if maintainer_orcid := bioregistry.get_contact_orcid(self.ontology):
yield Annotation(
v.has_maintainer, Reference(prefix="orcid", identifier=maintainer_orcid)
)

# Root terms
for root_term in self.root_terms or []:
Expand Down Expand Up @@ -2281,6 +2292,7 @@ class AdHocOntologyBase(Obo):

def build_ontology(
prefix: str,
*,
terms: list[Term] | None = None,
synonym_typedefs: list[SynonymTypeDef] | None = None,
typedefs: list[TypeDef] | None = None,
Expand All @@ -2291,12 +2303,58 @@ def build_ontology(
subsetdefs: list[tuple[Reference, str]] | None = None,
properties: list[Annotation] | None = None,
imports: list[str] | None = None,
description: str | None = None,
homepage: str | None = None,
mailing_list: str | None = None,
logo: str | None = None,
repository: str | None,
) -> Obo:
"""Build an ontology from parts."""
resource = bioregistry.get_resource(prefix, strict=True)
if name is None:
name = resource.get_name()
# TODO auto-populate license and other properties

if properties is None:
properties = []
if typedefs is None:
typedefs = []

if description:
from .typedef import has_description

properties.append(Annotation.string(has_description.reference, description))
if has_description not in typedefs:
typedefs.append(has_description) # TODO get proper typedef

if homepage:
from .typedef import has_homepage

properties.append(Annotation.uri(has_homepage.reference, homepage))
if has_homepage not in typedefs:
typedefs.append(has_homepage)

if logo:
from .typedef import has_depiction

properties.append(Annotation.uri(has_depiction.reference, logo))
if has_depiction not in typedefs:
typedefs.append(has_depiction)

if mailing_list:
from .typedef import has_mailing_list

properties.append(Annotation.string(has_mailing_list.reference, mailing_list))
if has_mailing_list not in typedefs:
typedefs.append(has_mailing_list)

if repository:
from .typedef import has_repository

properties.append(Annotation.uri(has_repository.reference, repository))
if has_repository not in typedefs:
typedefs.append(has_repository)

return make_ad_hoc_ontology(
_ontology=prefix,
_name=name,
Expand Down
10 changes: 10 additions & 0 deletions src/pyobo/struct/struct_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def float(cls, predicate: Reference, value: float) -> Self:
"""Return a literal property for a float."""
return cls(predicate, OBOLiteral.float(value))

@classmethod
def uri(cls, predicate: Reference, uri: str) -> Self:
"""Return a literal property for a URI."""
return cls(predicate, OBOLiteral.uri(uri))

@classmethod
def string(cls, predicate: Reference, value: str, *, language: str | None = None) -> Self:
"""Return a literal property for a float."""
return cls(predicate, OBOLiteral.string(value, language=language))

@staticmethod
def _sort_key(x: Annotation):
return x.predicate, _reference_or_literal_key(x.value)
Expand Down
13 changes: 6 additions & 7 deletions src/pyobo/struct/typedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"has_gene_product",
"has_homepage",
"has_inchi",
"has_mailbox",
"has_mature",
"has_member",
"has_part",
Expand Down Expand Up @@ -266,13 +267,11 @@

has_inchi = TypeDef(reference=v.has_inchi, is_metadata_tag=True).append_xref(v.debio_has_inchi)

has_homepage = TypeDef(
reference=Reference(prefix="foaf", identifier="homepage", name="homepage"), is_metadata_tag=True
)
has_depiction = TypeDef(
reference=Reference(prefix="foaf", identifier="depicted_by", name="depicted by"),
is_metadata_tag=True,
)
has_homepage = TypeDef(reference=v.has_homepage, is_metadata_tag=True)
has_depiction = TypeDef(reference=v.has_depiction, is_metadata_tag=True)
has_mailbox = TypeDef(reference=v.has_mailbox, is_metadata_tag=True)
has_mailing_list = TypeDef(reference=v.has_mailing_list, is_metadata_tag=True)
has_repository = TypeDef(reference=v.has_repository, is_metadata_tag=True)

has_category = TypeDef(
reference=Reference(prefix="biolink", identifier="category", name="has category"),
Expand Down
8 changes: 8 additions & 0 deletions src/pyobo/struct/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def _c(c: curies.Reference) -> Reference:
has_license = _c(_v.has_license)
has_title = _c(_v.has_title)

has_homepage = Reference(prefix="foaf", identifier="homepage", name="has homepage")
has_logo = Reference(prefix="foaf", identifier="logo", name="has logo")
has_mailbox = Reference(prefix="foaf", identifier="mbox", name="has mailbox")
has_depiction = Reference(prefix="foaf", identifier="depicted_by", name="depicted by")
has_repository = Reference(prefix="doap", identifier="repository", name="has repository")
has_mailing_list = Reference(prefix="doap", identifier="mailing-list", name="has mailing list")
has_maintainer = Reference(prefix="doap", identifier="maintainer", name="has maintainer")

has_part = Reference(prefix=BFO_PREFIX, identifier="0000051", name="has part")
part_of = Reference(prefix=BFO_PREFIX, identifier="0000050", name="part of")
orthologous = Reference(
Expand Down
5 changes: 4 additions & 1 deletion src/pyobo/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
VERSION_REWRITES = {
"$Date: 2009/11/15 10:54:12 $": "2009-11-15", # for owl
"http://www.w3.org/2006/time#2016": "2016", # for time
"https://purl.org/ontology/modalia#1.0.0": "1.0.0", # for dalia
}
STATIC_VERSION_REWRITES = {
"orth": "2",
}
STATIC_VERSION_REWRITES = {"orth": "2"}
VERSION_PREFIXES = [
"http://www.orpha.net/version",
"https://www.orphadata.com/data/ontologies/ordo/last_version/ORDO_en_",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_obo_reader/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"for synonyms fails on the open squiggly bracket {"
)

ADNAN_MALIK = Reference(prefix="orcid", identifier="0000-0001-8123-5351")


class TestUtils(unittest.TestCase):
"""Test utilities for the reader."""
Expand Down Expand Up @@ -1361,5 +1363,9 @@ def test_get_references(self) -> None:
std1.prefix: {std1},
"dcterms": {v.has_description, v.has_license, v.has_title},
v.has_dbxref.prefix: {v.has_exact_synonym},
# these get automatically added
"doap": {v.has_maintainer, v.has_repository},
"foaf": {v.has_homepage, v.has_logo},
"orcid": {ADNAN_MALIK},
}
self.assertEqual(expected_references, ontology._get_references())
7 changes: 7 additions & 0 deletions tests/test_struct/test_obo/test_struct_obo.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ def test_18_properties_bioregistry(self) -> None:
"""\
format-version: 1.4
idspace: dcterms http://purl.org/dc/terms/ "Dublin Core Metadata Initiative Terms"
idspace: doap http://usefulinc.com/ns/doap# "Description of a Project"
idspace: foaf http://xmlns.com/foaf/0.1/ "Friend of a Friend"
idspace: orcid https://orcid.org/ "Open Researcher and Contributor"
ontology: go
property_value: dcterms:license "CC-BY-4.0" xsd:string
property_value: dcterms:description "The Gene Ontology project provides a controlled vocabulary to describe gene and gene product attributes in any organism." xsd:string
property_value: foaf:homepage "http\\://geneontology.org/" xsd:anyURI
property_value: doap:repository "https\\://github.com/geneontology/go-ontology" xsd:anyURI
property_value: foaf:logo "https\\://obofoundry.org/images/go_logo.png" xsd:anyURI
property_value: doap:maintainer orcid:0000-0001-6787-2901
""",
ontology,
)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_struct/test_ofn/test_obo_to_ofn.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def test_simple_conversion(self) -> None:
self.assertEqual(
dedent("""\
Prefix(dcterms:=<http://purl.org/dc/terms/>)
Prefix(doap:=<http://usefulinc.com/ns/doap#>)
Prefix(foaf:=<http://xmlns.com/foaf/0.1/>)
Prefix(GO:=<http://purl.obolibrary.org/obo/GO_>)
Prefix(IAO:=<http://purl.obolibrary.org/obo/IAO_>)
Prefix(obo:=<http://purl.obolibrary.org/obo/>)
Prefix(oboInOwl:=<http://www.geneontology.org/formats/oboInOwl#>)
Prefix(OMO:=<http://purl.obolibrary.org/obo/OMO_>)
Prefix(orcid:=<https://orcid.org/>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Expand All @@ -62,6 +65,10 @@ def test_simple_conversion(self) -> None:
Annotation(dcterms:title "Gene Ontology"^^xsd:string)
Annotation(dcterms:license "CC-BY-4.0"^^xsd:string)
Annotation(dcterms:description "The Gene Ontology project provides a controlled vocabulary to describe gene and gene product attributes in any organism."^^xsd:string)
Annotation(foaf:homepage "http://geneontology.org/"^^xsd:anyURI)
Annotation(doap:repository "https://github.com/geneontology/go-ontology"^^xsd:anyURI)
Annotation(foaf:logo "https://obofoundry.org/images/go_logo.png"^^xsd:anyURI)
Annotation(doap:maintainer orcid:0000-0001-6787-2901)
Annotation(IAO:0000700 GO:1234567)
Annotation(owl:versionInfo "30"^^xsd:string)
Annotation(oboInOwl:auto-generated-by "PyOBO"^^xsd:string)
Expand Down
Loading