Skip to content

Commit f0b3d58

Browse files
authored
Update OLS config generation (#31)
1 parent c46b2cd commit f0b3d58

2 files changed

Lines changed: 31 additions & 86 deletions

File tree

build.py

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# /// script
22
# requires-python = ">=3.12"
33
# dependencies = [
4-
# "bioregistry",
4+
# "bioregistry>=0.13.34",
55
# "bioversions",
66
# "bioontologies",
77
# "pyobo[sources]",
@@ -27,14 +27,13 @@
2727
import datetime
2828
import functools
2929
import gzip
30-
import json
3130
import os
3231
import shutil
3332
import subprocess
3433
import traceback
3534
from pathlib import Path
3635
from textwrap import dedent
37-
from typing import Any, TypedDict
36+
from typing import TypedDict
3837

3938
import bioregistry
4039
import bioregistry.version
@@ -445,8 +444,9 @@ def _write(s: str) -> None:
445444
_write(f"[{prefix}] done converting to OBO Graph JSON")
446445

447446
if owl_config := rv.get("owl"):
448-
ols_config = _get_ols_config(prefix, owl_config["iri"])
449-
ols_config_path.write_text(json.dumps(ols_config, indent=2, ensure_ascii=False) + "\n")
447+
resource = bioregistry.get_resource(prefix, strict=True)
448+
ols_config = resource.get_ols_config(owl_config["iri"])
449+
ols_config_path.write_text(ols_config.model_dump_json(indent=2, ensure_ascii=False) + "\n")
450450
_, rv["ols"] = _prepare_artifact(prefix, ols_config_path, False, ".json")
451451

452452
purls_table_rows = [
@@ -502,79 +502,6 @@ def _write(s: str) -> None:
502502
return rv, errored
503503

504504

505-
def _get_ols_config(prefix: str, ontology_purl: str) -> dict[str, Any]:
506-
resource = bioregistry.get_resource(prefix, strict=True)
507-
508-
creators = []
509-
if contact := resource.get_contact():
510-
creators.append(contact.name)
511-
if resource.contact_extras:
512-
creators.extend(ce.name for ce in resource.contact_extras if ce.name)
513-
else:
514-
creators = [
515-
"Converted to OWL by Charles Tapley Hoyt (cthoyt@gmail.com), "
516-
"no primary contact information is available."
517-
]
518-
519-
description = resource.get_description()
520-
if license_ := resource.get_license():
521-
description += f" Licensed under {license_}."
522-
523-
values = {
524-
# as per https://github.com/EBISPOT/ols4/pull/896#discussion_r2126144218
525-
"id": resource.prefix,
526-
"reasoner": "none",
527-
"oboSlims": False,
528-
"is_foundary": resource.get_obofoundry_prefix() is not None,
529-
"ontology_purl": ontology_purl,
530-
######################################################################
531-
# The remainder are ontology metadata, which could be part of the #
532-
# ontology itself. #
533-
# #
534-
# See https://github.com/OBOFoundry/OBOFoundry.github.io/issues/1365 #
535-
######################################################################
536-
# Property: dcterms:creator
537-
"creator": creators,
538-
# http://purl.org/vocab/vann/preferredNamespacePrefix
539-
"preferredPrefix": resource.get_preferred_prefix() or resource.prefix,
540-
# Property: dcterms:title
541-
"title": resource.get_name(),
542-
# Property: dcterms:description
543-
"description": description,
544-
# TODO figure out why there's dupicate on `uri` and `homepage`
545-
"uri": resource.get_homepage(),
546-
# Property: foaf:homepage
547-
"homepage": resource.get_homepage(),
548-
# Property: http://usefulinc.com/ns/doap#mailing-list
549-
"mailing_list": resource.get_mailing_list() or resource.get_contact_email(),
550-
# TODO add to OMO
551-
"label_property": "https://www.w3.org/2000/01/rdf-schema#label",
552-
# TODO add to OMO
553-
"definition_property": [
554-
"http://purl.org/dc/terms/description",
555-
],
556-
# TODO add to OMO
557-
"synonym_property": [
558-
"http://www.geneontology.org/formats/oboInOwl#hasExactSynonym",
559-
"http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym",
560-
"http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym",
561-
"http://www.geneontology.org/formats/oboInOwl#hasCloseSynonym",
562-
],
563-
# See https://github.com/information-artifact-ontology/ontology-metadata/pull/193
564-
"hierarchical_property": [
565-
"https://www.w3.org/2000/01/rdf-schema#subClassOf",
566-
],
567-
"hidden_property": [],
568-
# http://purl.org/vocab/vann/preferredNamespaceUri
569-
"base_uri": [
570-
resource.get_rdf_uri_prefix() or resource.get_uri_prefix(),
571-
],
572-
# TODO root terms IAO_0000700 (preferred_root_term)
573-
}
574-
575-
return values
576-
577-
578505
@click.command()
579506
@verbose_option
580507
@click.option("-m", "--minimum")
@@ -656,11 +583,11 @@ def main( # noqa:C901
656583
"errors": previous_data.get("errors", {}),
657584
}
658585

659-
_tqdm_kwargs = {"unit": "ontology", "total": len(it), "desc": "obo-db-ingest"}
586+
tqdm_kwargs = {"unit": "ontology", "total": len(it), "desc": "obo-db-ingest"}
660587
if MULTIPROCESSING:
661-
mm = process_map(make_wrapped, it, max_workers=4, **_tqdm_kwargs)
588+
mm = process_map(make_wrapped, it, max_workers=4, **tqdm_kwargs)
662589
else:
663-
mm = tqdm(map(make_wrapped, it), **_tqdm_kwargs)
590+
mm = tqdm(map(make_wrapped, it), **tqdm_kwargs)
664591

665592
for prefix, result, errored in mm:
666593
rv["resources"][prefix] = result

generate-ols-requests.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1+
# /// script
2+
# requires-python = ">=3.14"
3+
# dependencies = [
4+
# "bioregistry>=0.13.34",
5+
# "click>=8.3.2",
6+
# "openpyxl>=3.1.5",
7+
# "pandas>=3.0.2",
8+
# "pyyaml>=6.0.3",
9+
# "requests>=2.33.1",
10+
# "tabulate>=0.10.0",
11+
# ]
12+
# ///
13+
114
"""Generate an OLS sheet."""
215

316
import json
417
from pathlib import Path
518

19+
import bioregistry
620
import click
721
import pandas as pd
822
import requests
923
import yaml
1024
from bioregistry import manager
1125
from tabulate import tabulate
1226

13-
from build import _get_ols_config
14-
1527
HERE = Path(__file__).parent.resolve()
1628
MANIFEST = HERE.joinpath("docs", "_data", "manifest.yml")
1729

@@ -50,10 +62,10 @@ def main(write_excel: bool, regenerate_old: bool) -> None:
5062

5163
rows = sorted(
5264
(prefix in pre_indexed, prefix, manager.get_name(prefix))
53-
for prefix, data in manifest["resources"].items()
65+
for prefix in manifest["resources"]
5466
if prefix not in NEVER
5567
)
56-
click.echo(tabulate(rows))
68+
click.echo(tabulate(rows, headers=["pre-indexed", "prefix", "name"], tablefmt="github") + "\n")
5769

5870
for prefix, data in manifest["resources"].items():
5971
if prefix in NEVER:
@@ -64,7 +76,13 @@ def main(write_excel: bool, regenerate_old: bool) -> None:
6476
click.echo(f"no OWL for {prefix}")
6577
continue
6678

67-
values = _get_ols_config(prefix, data["owl"]["iri"])
79+
resource = bioregistry.get_resource(prefix, strict=True)
80+
try:
81+
ols_config = resource.get_ols_config(data["owl"]["iri"])
82+
except ValueError as e:
83+
click.secho(f"[{prefix}] could not generate config: {e}", fg="red")
84+
continue
85+
values = ols_config.model_dump()
6886

6987
if write_excel:
7088
specific_df: pd.DataFrame = df.copy()

0 commit comments

Comments
 (0)