|
1 | 1 | # /// script |
2 | 2 | # requires-python = ">=3.12" |
3 | 3 | # dependencies = [ |
4 | | -# "bioregistry", |
| 4 | +# "bioregistry>=0.13.34", |
5 | 5 | # "bioversions", |
6 | 6 | # "bioontologies", |
7 | 7 | # "pyobo[sources]", |
|
27 | 27 | import datetime |
28 | 28 | import functools |
29 | 29 | import gzip |
30 | | -import json |
31 | 30 | import os |
32 | 31 | import shutil |
33 | 32 | import subprocess |
34 | 33 | import traceback |
35 | 34 | from pathlib import Path |
36 | 35 | from textwrap import dedent |
37 | | -from typing import Any, TypedDict |
| 36 | +from typing import TypedDict |
38 | 37 |
|
39 | 38 | import bioregistry |
40 | 39 | import bioregistry.version |
@@ -445,8 +444,9 @@ def _write(s: str) -> None: |
445 | 444 | _write(f"[{prefix}] done converting to OBO Graph JSON") |
446 | 445 |
|
447 | 446 | 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") |
450 | 450 | _, rv["ols"] = _prepare_artifact(prefix, ols_config_path, False, ".json") |
451 | 451 |
|
452 | 452 | purls_table_rows = [ |
@@ -502,79 +502,6 @@ def _write(s: str) -> None: |
502 | 502 | return rv, errored |
503 | 503 |
|
504 | 504 |
|
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 | | - |
578 | 505 | @click.command() |
579 | 506 | @verbose_option |
580 | 507 | @click.option("-m", "--minimum") |
@@ -656,11 +583,11 @@ def main( # noqa:C901 |
656 | 583 | "errors": previous_data.get("errors", {}), |
657 | 584 | } |
658 | 585 |
|
659 | | - _tqdm_kwargs = {"unit": "ontology", "total": len(it), "desc": "obo-db-ingest"} |
| 586 | + tqdm_kwargs = {"unit": "ontology", "total": len(it), "desc": "obo-db-ingest"} |
660 | 587 | 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) |
662 | 589 | else: |
663 | | - mm = tqdm(map(make_wrapped, it), **_tqdm_kwargs) |
| 590 | + mm = tqdm(map(make_wrapped, it), **tqdm_kwargs) |
664 | 591 |
|
665 | 592 | for prefix, result, errored in mm: |
666 | 593 | rv["resources"][prefix] = result |
|
0 commit comments