diff --git a/notebooks/Bioregistry Taxonomy Curation via Wikidata.ipynb b/notebooks/Bioregistry Taxonomy Curation via Wikidata.ipynb index ccad2cc30..d524ac304 100644 --- a/notebooks/Bioregistry Taxonomy Curation via Wikidata.ipynb +++ b/notebooks/Bioregistry Taxonomy Curation via Wikidata.ipynb @@ -9,13 +9,14 @@ "source": [ "# Get wikidata taxonomy properties\n", "\n", - "import bioregistry\n", - "import bioregistry.version\n", - "import requests\n", "import pandas as pd\n", - "from bioregistry.utils import norm, query_wikidata\n", + "import requests\n", "from bs4 import BeautifulSoup\n", "\n", + "import bioregistry\n", + "import bioregistry.version\n", + "from bioregistry.utils import query_wikidata\n", + "\n", "pd.set_option(\"display.max_rows\", None)" ] }, diff --git a/notebooks/Preparing the GO Annotation Database for Integration.ipynb b/notebooks/Preparing the GO Annotation Database for Integration.ipynb index ef371fef5..6b13e328a 100644 --- a/notebooks/Preparing the GO Annotation Database for Integration.ipynb +++ b/notebooks/Preparing the GO Annotation Database for Integration.ipynb @@ -107,9 +107,10 @@ } ], "source": [ - "import bioregistry.pandas as brpd\n", "import pandas as pd\n", "\n", + "import bioregistry.pandas as brpd\n", + "\n", "# Focus on these columns when displaying the data\n", "columns = [0, 1, 4, 5, 7, 12]\n", "\n", diff --git a/src/bioregistry/__init__.py b/src/bioregistry/__init__.py index df1edaf4c..4db72855e 100644 --- a/src/bioregistry/__init__.py +++ b/src/bioregistry/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Extract registry information.""" from .collection_api import get_collection, get_context # noqa:F401 diff --git a/src/bioregistry/__main__.py b/src/bioregistry/__main__.py index bfd34258e..297df659c 100644 --- a/src/bioregistry/__main__.py +++ b/src/bioregistry/__main__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Command line interface for the bioregistry.""" from .cli import main # type:ignore diff --git a/src/bioregistry/analysis/__init__.py b/src/bioregistry/analysis/__init__.py index 9f7eab401..480b21c56 100644 --- a/src/bioregistry/analysis/__init__.py +++ b/src/bioregistry/analysis/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Analyses build on the Bioregistry.""" diff --git a/src/bioregistry/app/__init__.py b/src/bioregistry/app/__init__.py index 63dfdeaa4..fb3696a87 100644 --- a/src/bioregistry/app/__init__.py +++ b/src/bioregistry/app/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Web application for the Bioregistry.""" diff --git a/src/bioregistry/app/api.py b/src/bioregistry/app/api.py index 0a0eac3cf..73dccfe1c 100644 --- a/src/bioregistry/app/api.py +++ b/src/bioregistry/app/api.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """FastAPI blueprint and routes.""" from __future__ import annotations -from typing import Any, List, Mapping, Optional, Set +from collections.abc import Mapping +from typing import Any, List, Optional, Set import yaml from curies import Reference diff --git a/src/bioregistry/app/cli.py b/src/bioregistry/app/cli.py index 79d05d299..78d5d6681 100644 --- a/src/bioregistry/app/cli.py +++ b/src/bioregistry/app/cli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Web command for running the app.""" from pathlib import Path diff --git a/src/bioregistry/app/constants.py b/src/bioregistry/app/constants.py index e5c6989c7..7c1fe0a96 100644 --- a/src/bioregistry/app/constants.py +++ b/src/bioregistry/app/constants.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -* - """Large data chunks for the web app.""" from bioregistry import version diff --git a/src/bioregistry/app/impl.py b/src/bioregistry/app/impl.py index 309167c38..3e022d553 100644 --- a/src/bioregistry/app/impl.py +++ b/src/bioregistry/app/impl.py @@ -1,9 +1,10 @@ """App builder interface.""" import json +from collections.abc import Mapping from pathlib import Path from textwrap import dedent -from typing import TYPE_CHECKING, Any, Mapping, Optional, Union +from typing import TYPE_CHECKING, Any, Optional, Union from a2wsgi import WSGIMiddleware from curies.mapping_service import MappingServiceGraph, MappingServiceSPARQLProcessor diff --git a/src/bioregistry/app/test.py b/src/bioregistry/app/test.py index 4dd82bbab..284e6646a 100644 --- a/src/bioregistry/app/test.py +++ b/src/bioregistry/app/test.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Test the resolution API.""" import sys diff --git a/src/bioregistry/app/ui.py b/src/bioregistry/app/ui.py index 6487fbbc5..9e328fc79 100644 --- a/src/bioregistry/app/ui.py +++ b/src/bioregistry/app/ui.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """User blueprint for the bioregistry web application.""" from __future__ import annotations diff --git a/src/bioregistry/app/utils.py b/src/bioregistry/app/utils.py index 6e4984dbc..93cb3b0af 100644 --- a/src/bioregistry/app/utils.py +++ b/src/bioregistry/app/utils.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Utility functions for the Bioregistry :mod:`flask` app.""" import json +from collections.abc import Mapping, Sequence from functools import partial -from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple import yaml from flask import ( @@ -87,22 +86,22 @@ def _autocomplete(manager_: Manager, q: str, url_prefix: Optional[str] = None) - Before completion is of prefix: >>> from bioregistry import manager - >>> _autocomplete(manager, 'cheb') + >>> _autocomplete(manager, "cheb") {'query': 'cheb', 'results': [('chebi', ''), ('chebi', 'chebiid'), ('goche', 'gochebi')], 'success': True, 'reason': 'searched prefix', 'url': None} If only prefix is complete: - >>> _autocomplete(manager, 'chebi') + >>> _autocomplete(manager, "chebi") {'query': 'chebi', 'results': [('chebi', ''), ('chebi', 'chebiid'), ('goche', 'gochebi')], 'success': True, 'reason': 'matched prefix', 'url': '/chebi'} Not matching the pattern: - >>> _autocomplete(manager, 'chebi:NOPE') + >>> _autocomplete(manager, "chebi:NOPE") {'query': 'chebi:NOPE', 'prefix': 'chebi', 'pattern': '^\\d+$', 'identifier': 'NOPE', 'success': False, 'reason': 'failed validation', 'url': None} Matching the pattern: - >>> _autocomplete(manager, 'chebi:1234') + >>> _autocomplete(manager, "chebi:1234") {'query': 'chebi:1234', 'prefix': 'chebi', 'pattern': '^\\d+$', 'identifier': '1234', 'success': True, 'reason': 'passed validation', 'url': '/chebi:1234'} """ # noqa: E501 if url_prefix is None: diff --git a/src/bioregistry/app/wsgi.py b/src/bioregistry/app/wsgi.py index 6b990ed89..7fa2d7149 100644 --- a/src/bioregistry/app/wsgi.py +++ b/src/bioregistry/app/wsgi.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Web application for the Bioregistry.""" from bioregistry.app.impl import get_app diff --git a/src/bioregistry/benchmarks/__main__.py b/src/bioregistry/benchmarks/__main__.py index 35b19eecb..7cd81f544 100644 --- a/src/bioregistry/benchmarks/__main__.py +++ b/src/bioregistry/benchmarks/__main__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Run the benchmarks CLI.""" from .cli import main diff --git a/src/bioregistry/benchmarks/cli.py b/src/bioregistry/benchmarks/cli.py index d0bea12c2..3d519c5c0 100644 --- a/src/bioregistry/benchmarks/cli.py +++ b/src/bioregistry/benchmarks/cli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Run all benchmarks.""" import click diff --git a/src/bioregistry/benchmarks/curie_parsing.py b/src/bioregistry/benchmarks/curie_parsing.py index 1538931ce..2f0444104 100644 --- a/src/bioregistry/benchmarks/curie_parsing.py +++ b/src/bioregistry/benchmarks/curie_parsing.py @@ -3,8 +3,9 @@ import itertools as itt import random import time +from collections.abc import Iterable from statistics import mean -from typing import Iterable, Tuple +from typing import Tuple import click import matplotlib.pyplot as plt diff --git a/src/bioregistry/benchmarks/curie_validation.py b/src/bioregistry/benchmarks/curie_validation.py index 407a4cc68..217141e02 100644 --- a/src/bioregistry/benchmarks/curie_validation.py +++ b/src/bioregistry/benchmarks/curie_validation.py @@ -2,7 +2,8 @@ import random import time -from typing import Iterable, Tuple +from collections.abc import Iterable +from typing import Tuple import click import matplotlib.pyplot as plt diff --git a/src/bioregistry/benchmarks/uri_parsing.py b/src/bioregistry/benchmarks/uri_parsing.py index 7a5d52239..516c35730 100644 --- a/src/bioregistry/benchmarks/uri_parsing.py +++ b/src/bioregistry/benchmarks/uri_parsing.py @@ -1,8 +1,9 @@ """A benchmark for Bioregistry's URI parser.""" import time +from collections.abc import Iterable from statistics import mean -from typing import Iterable, Tuple +from typing import Tuple import click import matplotlib.pyplot as plt diff --git a/src/bioregistry/bibliometrics.py b/src/bioregistry/bibliometrics.py index 95c64ed0e..7f009ae37 100644 --- a/src/bioregistry/bibliometrics.py +++ b/src/bioregistry/bibliometrics.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Utilities for publications.""" import typing from collections import Counter -from typing import TYPE_CHECKING, Iterable, List +from collections.abc import Iterable +from typing import TYPE_CHECKING, List from .resource_manager import manager from .schema.struct import Publication, deduplicate_publications diff --git a/src/bioregistry/cli.py b/src/bioregistry/cli.py index dcaace6d0..6af06993f 100644 --- a/src/bioregistry/cli.py +++ b/src/bioregistry/cli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Command line interface for the bioregistry.""" import sys @@ -87,7 +85,7 @@ def align( secho(f"Aligning {aligner_cls.key}") try: aligner_cls.align(force_download=not no_force) - except (IOError, OLSBroken) as e: + except (OSError, OLSBroken) as e: secho(f"Failed to align {aligner_cls.key}: {e}", fg="red") if pre_digests != get_hexdigests(): diff --git a/src/bioregistry/collection_api.py b/src/bioregistry/collection_api.py index 5c751b4e3..e8c8b3c5a 100644 --- a/src/bioregistry/collection_api.py +++ b/src/bioregistry/collection_api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """API for collections.""" from typing import Optional diff --git a/src/bioregistry/compare.py b/src/bioregistry/compare.py index 30b153880..a53b908ff 100644 --- a/src/bioregistry/compare.py +++ b/src/bioregistry/compare.py @@ -94,7 +94,7 @@ def _get_has_present(func: Callable[[str], X | None]) -> Counter[X]: def _save( - fig: "matplotlib.figure.Figure", + fig: matplotlib.figure.Figure, name: str, *, svg: bool = True, @@ -733,8 +733,7 @@ def plot_xrefs(registry_infos, watermark: bool) -> FigAxPair: ax.text( x1, h + 1, - f"No identifier resources are\navailable in more than\n" - f"{max_mapped} external registries", + f"No identifier resources are\navailable in more than\n{max_mapped} external registries", horizontalalignment="center", verticalalignment="bottom", fontdict=dict(fontsize=12), @@ -766,7 +765,9 @@ def _get_licenses_mapped_counter(threshold: int = 30) -> List[str]: ( "None" if license_ is None - else license_ if licenses_counter[license_] > threshold else "Other" + else license_ + if licenses_counter[license_] > threshold + else "Other" ) for license_ in licenses ] diff --git a/src/bioregistry/constants.py b/src/bioregistry/constants.py index a4a10da73..450ba812f 100644 --- a/src/bioregistry/constants.py +++ b/src/bioregistry/constants.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Constants and utilities for registries.""" import importlib.metadata @@ -11,13 +9,13 @@ import pystow __all__ = [ - "HERE", - "DATA_DIRECTORY", + "BIOREGISTRY_MODULE", "BIOREGISTRY_PATH", - "METAREGISTRY_PATH", "COLLECTIONS_PATH", + "DATA_DIRECTORY", + "HERE", + "METAREGISTRY_PATH", "MISMATCH_PATH", - "BIOREGISTRY_MODULE", "RAW_DIRECTORY", ] diff --git a/src/bioregistry/curation/__init__.py b/src/bioregistry/curation/__init__.py index 5efe29de5..357522ecb 100644 --- a/src/bioregistry/curation/__init__.py +++ b/src/bioregistry/curation/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Curation tools.""" diff --git a/src/bioregistry/curation/add_co_providers.py b/src/bioregistry/curation/add_co_providers.py index c2d390685..769ab93fb 100644 --- a/src/bioregistry/curation/add_co_providers.py +++ b/src/bioregistry/curation/add_co_providers.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Add providers for Crop Ontology entries.""" import click diff --git a/src/bioregistry/curation/add_descriptions_from_gs.py b/src/bioregistry/curation/add_descriptions_from_gs.py index 04f3759ae..5245a2bd7 100644 --- a/src/bioregistry/curation/add_descriptions_from_gs.py +++ b/src/bioregistry/curation/add_descriptions_from_gs.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Add descriptions from a google curation sheet.""" import click diff --git a/src/bioregistry/curation/add_examples.py b/src/bioregistry/curation/add_examples.py index be915771d..e13a6bdf7 100644 --- a/src/bioregistry/curation/add_examples.py +++ b/src/bioregistry/curation/add_examples.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Script for adding examples automatically.""" import random diff --git a/src/bioregistry/curation/add_examples_from_javert.py b/src/bioregistry/curation/add_examples_from_javert.py index e4e581a5b..22f6497b1 100644 --- a/src/bioregistry/curation/add_examples_from_javert.py +++ b/src/bioregistry/curation/add_examples_from_javert.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Script for adding examples automatically.""" import gzip diff --git a/src/bioregistry/curation/add_examples_from_ols.py b/src/bioregistry/curation/add_examples_from_ols.py index 4b6a66b34..1ad34f167 100644 --- a/src/bioregistry/curation/add_examples_from_ols.py +++ b/src/bioregistry/curation/add_examples_from_ols.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- - """Add examples from OLS.""" import random -from typing import Mapping +from collections.abc import Mapping import requests from tqdm import tqdm diff --git a/src/bioregistry/curation/add_ontology_regexes.py b/src/bioregistry/curation/add_ontology_regexes.py index 65e2ecf9c..b06000edb 100644 --- a/src/bioregistry/curation/add_ontology_regexes.py +++ b/src/bioregistry/curation/add_ontology_regexes.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Assert regular expression patterns for common identifier styles.""" import re diff --git a/src/bioregistry/curation/bulk_import.py b/src/bioregistry/curation/bulk_import.py index 2adb5ab16..c5e098ac7 100644 --- a/src/bioregistry/curation/bulk_import.py +++ b/src/bioregistry/curation/bulk_import.py @@ -17,7 +17,8 @@ import sys from collections import defaultdict -from typing import Any, DefaultDict, Dict, Mapping, Optional +from collections.abc import Mapping +from typing import Any, DefaultDict, Dict, Optional import click import pandas as pd diff --git a/src/bioregistry/curation/deprecation_diff.py b/src/bioregistry/curation/deprecation_diff.py index 8206b85ab..49aaf1df7 100644 --- a/src/bioregistry/curation/deprecation_diff.py +++ b/src/bioregistry/curation/deprecation_diff.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Show discrepancies between Bioregistry and OBO Foundry deprecation status.""" import click diff --git a/src/bioregistry/curation/import_pc_semiautomatic.py b/src/bioregistry/curation/import_pc_semiautomatic.py index 5c3750695..1be02d0a8 100644 --- a/src/bioregistry/curation/import_pc_semiautomatic.py +++ b/src/bioregistry/curation/import_pc_semiautomatic.py @@ -97,7 +97,7 @@ def main(): def _works(url: str) -> bool: try: homepage_res = requests.head(url, timeout=3, allow_redirects=True) - except IOError: + except OSError: return False else: return homepage_res.status_code == 200 diff --git a/src/bioregistry/curation/literature.py b/src/bioregistry/curation/literature.py index 3984d8c54..20ba600be 100644 --- a/src/bioregistry/curation/literature.py +++ b/src/bioregistry/curation/literature.py @@ -3,8 +3,8 @@ import enum __all__ = [ - "CurationRelevance", "COLUMNS", + "CurationRelevance", ] COLUMNS = [ diff --git a/src/bioregistry/curation/make_description_curation_sheet.py b/src/bioregistry/curation/make_description_curation_sheet.py index 31be28310..26728bd4c 100644 --- a/src/bioregistry/curation/make_description_curation_sheet.py +++ b/src/bioregistry/curation/make_description_curation_sheet.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- - """Make a curation sheet for the bioregistry.""" + import click import pandas as pd diff --git a/src/bioregistry/data/__init__.py b/src/bioregistry/data/__init__.py index 61d18deae..e4115a1c6 100644 --- a/src/bioregistry/data/__init__.py +++ b/src/bioregistry/data/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Data in the bioregistry.""" diff --git a/src/bioregistry/export/__init__.py b/src/bioregistry/export/__init__.py index 3c66481e5..c4a50e15b 100644 --- a/src/bioregistry/export/__init__.py +++ b/src/bioregistry/export/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Exports for the Bioregistry.""" diff --git a/src/bioregistry/export/__main__.py b/src/bioregistry/export/__main__.py index 13be68887..2a711bb2f 100644 --- a/src/bioregistry/export/__main__.py +++ b/src/bioregistry/export/__main__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Export the Bioregistry.""" from .cli import export diff --git a/src/bioregistry/export/cli.py b/src/bioregistry/export/cli.py index c69b00087..a914c1b22 100644 --- a/src/bioregistry/export/cli.py +++ b/src/bioregistry/export/cli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Export the Bioregistry.""" import click diff --git a/src/bioregistry/export/prefix_maps.py b/src/bioregistry/export/prefix_maps.py index c5ce30904..85d2afe45 100644 --- a/src/bioregistry/export/prefix_maps.py +++ b/src/bioregistry/export/prefix_maps.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Export extended prefix maps (EPMs), JSON-LD contexts, and SHACL RDF documents. .. seealso:: https://github.com/biopragmatics/bioregistry/pull/972 diff --git a/src/bioregistry/export/rdf_export.py b/src/bioregistry/export/rdf_export.py index 1db4a7be4..bb318c70c 100644 --- a/src/bioregistry/export/rdf_export.py +++ b/src/bioregistry/export/rdf_export.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Export the Bioregistry to RDF.""" import logging diff --git a/src/bioregistry/export/sssom_export.py b/src/bioregistry/export/sssom_export.py index 4dd7f0b89..70308a4e2 100644 --- a/src/bioregistry/export/sssom_export.py +++ b/src/bioregistry/export/sssom_export.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Export the Bioregistry to SSSOM.""" import csv diff --git a/src/bioregistry/export/tables_export.py b/src/bioregistry/export/tables_export.py index bd56203f4..b8c8418ae 100644 --- a/src/bioregistry/export/tables_export.py +++ b/src/bioregistry/export/tables_export.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Make tables exports.""" from textwrap import dedent diff --git a/src/bioregistry/export/warnings_export.py b/src/bioregistry/export/warnings_export.py index 3d883d33c..8d2ce6b0f 100644 --- a/src/bioregistry/export/warnings_export.py +++ b/src/bioregistry/export/warnings_export.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Generate the warnings file. This lists any sorts of things that should be fixed upstream, but are instead manually curated in the Bioregistry. diff --git a/src/bioregistry/export/yaml_export.py b/src/bioregistry/export/yaml_export.py index f942dbeea..cca114539 100644 --- a/src/bioregistry/export/yaml_export.py +++ b/src/bioregistry/export/yaml_export.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Export components of the bioregistry to YAML.""" import json diff --git a/src/bioregistry/external/__init__.py b/src/bioregistry/external/__init__.py index fb3649348..b2fb94663 100644 --- a/src/bioregistry/external/__init__.py +++ b/src/bioregistry/external/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Acquisition, processing, and alignment of external registries.""" from typing import Callable, List, Tuple diff --git a/src/bioregistry/external/aberowl/__init__.py b/src/bioregistry/external/aberowl/__init__.py index 1ded84001..bea2e8364 100644 --- a/src/bioregistry/external/aberowl/__init__.py +++ b/src/bioregistry/external/aberowl/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download the AberOWL registry.""" import json @@ -13,8 +11,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_aberowl", "AberOWLAligner", + "get_aberowl", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/align.py b/src/bioregistry/external/align.py index 09d0a5f22..3b2a1bbf4 100644 --- a/src/bioregistry/external/align.py +++ b/src/bioregistry/external/align.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Workflows for aligning external registries.""" from class_resolver import ClassResolver diff --git a/src/bioregistry/external/alignment_utils.py b/src/bioregistry/external/alignment_utils.py index 1b7cbdee9..17a4f6b23 100644 --- a/src/bioregistry/external/alignment_utils.py +++ b/src/bioregistry/external/alignment_utils.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- - """Utilities for registry alignment.""" import csv -from typing import Any, Callable, ClassVar, Dict, Iterable, Mapping, Optional, Sequence +from collections.abc import Iterable, Mapping, Sequence +from typing import Any, Callable, ClassVar, Dict, Optional import click from tabulate import tabulate diff --git a/src/bioregistry/external/bartoc/__init__.py b/src/bioregistry/external/bartoc/__init__.py index 55e334f6b..09d2095e5 100644 --- a/src/bioregistry/external/bartoc/__init__.py +++ b/src/bioregistry/external/bartoc/__init__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Download the BARTOC registry.""" import json +from collections.abc import Mapping from pathlib import Path -from typing import Any, Mapping +from typing import Any import requests from tqdm import tqdm @@ -15,8 +14,8 @@ from ..alignment_utils import Aligner __all__ = [ - "get_bartoc", "BartocAligner", + "get_bartoc", ] HERE = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/biocontext/__init__.py b/src/bioregistry/external/biocontext/__init__.py index 54ab43530..211ad2444 100644 --- a/src/bioregistry/external/biocontext/__init__.py +++ b/src/bioregistry/external/biocontext/__init__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Download BioContext.""" import json +from collections.abc import Mapping, Sequence from pathlib import Path -from typing import Any, Dict, Mapping, Sequence +from typing import Any, Dict from pystow.utils import download @@ -12,8 +11,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_biocontext", "BioContextAligner", + "get_biocontext", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/biolink/__init__.py b/src/bioregistry/external/biolink/__init__.py index 214519f07..718e86de1 100644 --- a/src/bioregistry/external/biolink/__init__.py +++ b/src/bioregistry/external/biolink/__init__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Download Biolink.""" import json +from collections.abc import Mapping, Sequence from pathlib import Path -from typing import Any, Dict, Mapping, Sequence +from typing import Any, Dict import yaml from pystow.utils import download @@ -13,8 +12,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_biolink", "BiolinkAligner", + "get_biolink", ] URL = "https://raw.githubusercontent.com/biolink/biolink-model/master/biolink-model.yaml" diff --git a/src/bioregistry/external/bioportal/__init__.py b/src/bioregistry/external/bioportal/__init__.py index a9b6e558f..055f3bcae 100644 --- a/src/bioregistry/external/bioportal/__init__.py +++ b/src/bioregistry/external/bioportal/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download the NCBO BioPortal registry. Get an API key by logging up, signing in, and navigating to https://bioportal.bioontology.org/account. @@ -21,8 +19,8 @@ from bioregistry.utils import removeprefix __all__ = [ - "get_bioportal", "get_agroportal", + "get_bioportal", "get_ecoportal", ] diff --git a/src/bioregistry/external/bioportal/agroportal.py b/src/bioregistry/external/bioportal/agroportal.py index 3ada69674..ec4dd6562 100644 --- a/src/bioregistry/external/bioportal/agroportal.py +++ b/src/bioregistry/external/bioportal/agroportal.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Align the AgroPortal with the Bioregistry.""" from .bioportal import AgroPortalAligner diff --git a/src/bioregistry/external/bioportal/bioportal.py b/src/bioregistry/external/bioportal/bioportal.py index ce44a4fae..32b00a0cd 100644 --- a/src/bioregistry/external/bioportal/bioportal.py +++ b/src/bioregistry/external/bioportal/bioportal.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Align the BioPortal with the Bioregistry.""" from bioregistry.external.alignment_utils import Aligner diff --git a/src/bioregistry/external/bioportal/ecoportal.py b/src/bioregistry/external/bioportal/ecoportal.py index cce849fd8..096dbae40 100644 --- a/src/bioregistry/external/bioportal/ecoportal.py +++ b/src/bioregistry/external/bioportal/ecoportal.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Align the EcoPortal with the Bioregistry.""" from .bioportal import EcoPortalAligner diff --git a/src/bioregistry/external/cellosaurus/__init__.py b/src/bioregistry/external/cellosaurus/__init__.py index 9da10666a..5f0958340 100644 --- a/src/bioregistry/external/cellosaurus/__init__.py +++ b/src/bioregistry/external/cellosaurus/__init__.py @@ -1,12 +1,11 @@ -# -*- coding: utf-8 -*- - """Download the Cellosaurus registry.""" import itertools as itt import json import logging +from collections.abc import Mapping from pathlib import Path -from typing import Dict, Mapping +from typing import Dict from pystow.utils import download @@ -14,8 +13,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_cellosaurus", "CellosaurusAligner", + "get_cellosaurus", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/cheminf/__init__.py b/src/bioregistry/external/cheminf/__init__.py index eec2dfb6b..651d19c2c 100644 --- a/src/bioregistry/external/cheminf/__init__.py +++ b/src/bioregistry/external/cheminf/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download the Chemical Information Ontology registry (children of ``CHEMINF:000464``). To convert CHEMINF from OWL to OBO Graph JSON, do the following: @@ -12,15 +10,15 @@ """ import json +from collections.abc import Mapping from pathlib import Path -from typing import Mapping from bioregistry.external.alignment_utils import Aligner from bioregistry.utils import get_ols_descendants __all__ = [ - "get_cheminf", "ChemInfAligner", + "get_cheminf", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/cropoct/__init__.py b/src/bioregistry/external/cropoct/__init__.py index 07566a335..c499519ae 100644 --- a/src/bioregistry/external/cropoct/__init__.py +++ b/src/bioregistry/external/cropoct/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download registry information from CROPOCT.""" import io @@ -14,8 +12,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_cropoct", "CropOCTAligner", + "get_cropoct", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/edam/__init__.py b/src/bioregistry/external/edam/__init__.py index 212ea95c0..dff90b56f 100644 --- a/src/bioregistry/external/edam/__init__.py +++ b/src/bioregistry/external/edam/__init__.py @@ -1,17 +1,15 @@ -# -*- coding: utf-8 -*- - """Import accessions from EDAM.""" import json +from collections.abc import Mapping from pathlib import Path -from typing import Mapping from bioregistry.external.alignment_utils import Aligner from bioregistry.utils import get_ols_descendants __all__ = [ - "get_edam", "EDAMAligner", + "get_edam", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/fairsharing/__init__.py b/src/bioregistry/external/fairsharing/__init__.py index e94c476cd..ddd565e10 100644 --- a/src/bioregistry/external/fairsharing/__init__.py +++ b/src/bioregistry/external/fairsharing/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Scraper for FAIRsharing. .. seealso:: https://beta.fairsharing.org/API_doc @@ -8,8 +6,9 @@ import json import logging import re +from collections.abc import MutableMapping from pathlib import Path -from typing import Any, MutableMapping, Optional, Set +from typing import Any, Optional, Set from bioregistry.constants import ORCID_PATTERN from bioregistry.external.alignment_utils import Aligner @@ -17,8 +16,8 @@ from bioregistry.utils import removeprefix, removesuffix __all__ = [ - "get_fairsharing", "FairsharingAligner", + "get_fairsharing", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/go/__init__.py b/src/bioregistry/external/go/__init__.py index f7514f449..2f10ebffc 100644 --- a/src/bioregistry/external/go/__init__.py +++ b/src/bioregistry/external/go/__init__.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- - """Download the Gene Ontology registry.""" import json import logging +from collections.abc import Mapping from pathlib import Path -from typing import Any, Dict, Mapping +from typing import Any, Dict import yaml from pystow.utils import download @@ -14,8 +13,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_go", "GoAligner", + "get_go", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/hl7/__init__.py b/src/bioregistry/external/hl7/__init__.py index d119eb452..deb1ab7ce 100644 --- a/src/bioregistry/external/hl7/__init__.py +++ b/src/bioregistry/external/hl7/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Utilities for getting HL7 OIDs. 1. Navigate to https://www.hl7.org/oid/index.cfm?Comp_OID=2.16.840.1.113883.6.9 @@ -8,12 +6,12 @@ """ import csv +from collections.abc import Mapping from pathlib import Path -from typing import Mapping __all__ = [ - "get_hl7", "HL7Aligner", + "get_hl7", ] from bioregistry.external.alignment_utils import Aligner diff --git a/src/bioregistry/external/integbio/__init__.py b/src/bioregistry/external/integbio/__init__.py index f28e6ae48..be37fd49e 100644 --- a/src/bioregistry/external/integbio/__init__.py +++ b/src/bioregistry/external/integbio/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download the Integbio registry.""" import json @@ -11,8 +9,8 @@ from bs4 import BeautifulSoup __all__ = [ - "get_integbio", "IntegbioAligner", + "get_integbio", ] from bioregistry.external.alignment_utils import Aligner diff --git a/src/bioregistry/external/lov/__init__.py b/src/bioregistry/external/lov/__init__.py index 9415c95dc..80c1b2ee8 100644 --- a/src/bioregistry/external/lov/__init__.py +++ b/src/bioregistry/external/lov/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download the LOV registry.""" import json @@ -13,8 +11,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_lov", "LOVAligner", + "get_lov", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/miriam/__init__.py b/src/bioregistry/external/miriam/__init__.py index a774f46f6..8dbbaf533 100644 --- a/src/bioregistry/external/miriam/__init__.py +++ b/src/bioregistry/external/miriam/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download registry information from Identifiers.org/MIRIAMs.""" import json @@ -12,8 +10,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_miriam", "MiriamAligner", + "get_miriam", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/n2t/__init__.py b/src/bioregistry/external/n2t/__init__.py index e90bbea6e..8446d6de6 100644 --- a/src/bioregistry/external/n2t/__init__.py +++ b/src/bioregistry/external/n2t/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- - """Download registry information from N2T.""" import json +from collections.abc import Mapping from pathlib import Path -from typing import Mapping import yaml from pystow.utils import download @@ -13,8 +11,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_n2t", "N2TAligner", + "get_n2t", ] URL = "https://n2t.net/e/n2t_full_prefixes.yaml" diff --git a/src/bioregistry/external/ncbi/__init__.py b/src/bioregistry/external/ncbi/__init__.py index 9309c99fd..83534cc92 100644 --- a/src/bioregistry/external/ncbi/__init__.py +++ b/src/bioregistry/external/ncbi/__init__.py @@ -1,13 +1,12 @@ -# -*- coding: utf-8 -*- - """Download registry information from NCBI.""" import json import logging import re import textwrap +from collections.abc import Sequence from pathlib import Path -from typing import Dict, Sequence +from typing import Dict from urllib.parse import urlsplit, urlunsplit from bs4 import BeautifulSoup @@ -17,8 +16,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_ncbi", "NcbiAligner", + "get_ncbi", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/obofoundry/__init__.py b/src/bioregistry/external/obofoundry/__init__.py index f2c58f1cd..77727df41 100644 --- a/src/bioregistry/external/obofoundry/__init__.py +++ b/src/bioregistry/external/obofoundry/__init__.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- - """Download registry information from the OBO Foundry.""" import json import logging +from collections.abc import Mapping from pathlib import Path -from typing import Mapping, Optional +from typing import Optional import requests import yaml @@ -15,9 +14,9 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ + "OBOFoundryAligner", "get_obofoundry", "get_obofoundry_example", - "OBOFoundryAligner", ] diff --git a/src/bioregistry/external/ols/__init__.py b/src/bioregistry/external/ols/__init__.py index c2a782322..336a020be 100644 --- a/src/bioregistry/external/ols/__init__.py +++ b/src/bioregistry/external/ols/__init__.py @@ -1,17 +1,16 @@ -# -*- coding: utf-8 -*- - """Download registry information from the OLS.""" import datetime import enum import json import logging +from collections.abc import Mapping from email.utils import parseaddr from functools import lru_cache from operator import itemgetter from pathlib import Path from textwrap import dedent -from typing import Any, Mapping, Optional +from typing import Any, Optional import requests from pydantic import BaseModel @@ -22,8 +21,8 @@ from bioregistry.utils import OLSBroken __all__ = [ - "get_ols", "OLSAligner", + "get_ols", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/ontobee/__init__.py b/src/bioregistry/external/ontobee/__init__.py index 91994ab87..39c178972 100644 --- a/src/bioregistry/external/ontobee/__init__.py +++ b/src/bioregistry/external/ontobee/__init__.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- - """Download registry information from OntoBee.""" import json import textwrap +from collections.abc import Sequence from pathlib import Path -from typing import Sequence from bs4 import BeautifulSoup from pystow.utils import download @@ -14,8 +12,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_ontobee", "OntobeeAligner", + "get_ontobee", ] DIRECTORY = Path(__file__).parent.resolve() diff --git a/src/bioregistry/external/pathguide/__init__.py b/src/bioregistry/external/pathguide/__init__.py index 099c0d36f..1bd7fc667 100644 --- a/src/bioregistry/external/pathguide/__init__.py +++ b/src/bioregistry/external/pathguide/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download registry information from Pathguide.""" import requests @@ -8,8 +6,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_pathguide", "PathguideAligner", + "get_pathguide", ] diff --git a/src/bioregistry/external/prefixcommons/__init__.py b/src/bioregistry/external/prefixcommons/__init__.py index c0a0fa360..3727cc34d 100644 --- a/src/bioregistry/external/prefixcommons/__init__.py +++ b/src/bioregistry/external/prefixcommons/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download registry information from the Life Science Registry (LSR), which powers Prefix Commons. .. seealso:: @@ -10,8 +8,9 @@ import json import logging +from collections.abc import Mapping, Sequence from pathlib import Path -from typing import Any, Dict, List, Mapping, Sequence +from typing import Any, Dict, List from pystow.utils import download @@ -20,8 +19,8 @@ from bioregistry.license_standardizer import standardize_license __all__ = [ - "get_prefixcommons", "PrefixCommonsAligner", + "get_prefixcommons", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/re3data/__init__.py b/src/bioregistry/external/re3data/__init__.py index c9f7d56b3..0ae7a44b0 100644 --- a/src/bioregistry/external/re3data/__init__.py +++ b/src/bioregistry/external/re3data/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Re3data is a registry of research data repositories. Example API endpoint: https://www.re3data.org/api/v1/repository/r3d100010772 @@ -7,8 +5,9 @@ import json import logging +from collections.abc import Mapping from pathlib import Path -from typing import Any, Mapping, Optional, Tuple +from typing import Any, Optional, Tuple from xml.etree import ElementTree import requests @@ -18,8 +17,8 @@ from bioregistry.utils import removeprefix __all__ = [ - "get_re3data", "Re3dataAligner", + "get_re3data", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/rrid/__init__.py b/src/bioregistry/external/rrid/__init__.py index 1ce63f089..5590ce763 100644 --- a/src/bioregistry/external/rrid/__init__.py +++ b/src/bioregistry/external/rrid/__init__.py @@ -8,15 +8,15 @@ """ import csv +from collections.abc import Mapping from pathlib import Path -from typing import Mapping from bioregistry.constants import RAW_DIRECTORY from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_rrid", "RRIDAligner", + "get_rrid", ] diff --git a/src/bioregistry/external/togoid/__init__.py b/src/bioregistry/external/togoid/__init__.py index 3f7f26f53..f8bbe52d5 100644 --- a/src/bioregistry/external/togoid/__init__.py +++ b/src/bioregistry/external/togoid/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Download TogoID.""" import json @@ -13,8 +11,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_togoid", "TogoIDAligner", + "get_togoid", ] diff --git a/src/bioregistry/external/uniprot/__init__.py b/src/bioregistry/external/uniprot/__init__.py index 681114d0e..0bff4319f 100644 --- a/src/bioregistry/external/uniprot/__init__.py +++ b/src/bioregistry/external/uniprot/__init__.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- - """Download and parse the UniProt Cross-ref database.""" import json import logging +from collections.abc import Mapping from pathlib import Path -from typing import Mapping import requests @@ -14,8 +12,8 @@ from bioregistry.utils import removeprefix __all__ = [ - "get_uniprot", "UniProtAligner", + "get_uniprot", ] logger = logging.getLogger(__name__) diff --git a/src/bioregistry/external/wikidata/__init__.py b/src/bioregistry/external/wikidata/__init__.py index 346f82e2e..e39d64e6e 100644 --- a/src/bioregistry/external/wikidata/__init__.py +++ b/src/bioregistry/external/wikidata/__init__.py @@ -1,20 +1,19 @@ -# -*- coding: utf-8 -*- - """Query, download, and format Wikidata as a registry.""" import json import logging +from collections.abc import Mapping from pathlib import Path from textwrap import dedent -from typing import Dict, Mapping +from typing import Dict from bioregistry.constants import BIOREGISTRY_PATH, URI_FORMAT_KEY from bioregistry.external.alignment_utils import Aligner from bioregistry.utils import query_wikidata, removeprefix __all__ = [ - "get_wikidata", "WikidataAligner", + "get_wikidata", ] diff --git a/src/bioregistry/external/zazuko/__init__.py b/src/bioregistry/external/zazuko/__init__.py index 2b0817504..e8685a50c 100644 --- a/src/bioregistry/external/zazuko/__init__.py +++ b/src/bioregistry/external/zazuko/__init__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Download Zazuko.""" import json +from collections.abc import Mapping from pathlib import Path -from typing import Any, Mapping +from typing import Any import requests @@ -12,8 +11,8 @@ from bioregistry.external.alignment_utils import Aligner __all__ = [ - "get_zazuko", "ZazukoAligner", + "get_zazuko", ] diff --git a/src/bioregistry/gh/__init__.py b/src/bioregistry/gh/__init__.py index efea9cec4..3a8d2e3bc 100644 --- a/src/bioregistry/gh/__init__.py +++ b/src/bioregistry/gh/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """GitHub utilities.""" diff --git a/src/bioregistry/gh/github_client.py b/src/bioregistry/gh/github_client.py index 8642ad2cc..ce4b0d3cf 100644 --- a/src/bioregistry/gh/github_client.py +++ b/src/bioregistry/gh/github_client.py @@ -1,12 +1,11 @@ -# -*- coding: utf-8 -*- - """Update the bioregistry from GitHub Issue templates.""" import itertools as itt import logging import os -from subprocess import CalledProcessError, check_output # noqa: S404 -from typing import Any, Dict, Iterable, Mapping, Optional, Set +from collections.abc import Iterable, Mapping +from subprocess import CalledProcessError, check_output +from typing import Any, Dict, Optional, Set import more_itertools import pystow diff --git a/src/bioregistry/gh/new_prefix.py b/src/bioregistry/gh/new_prefix.py index ff9414cdc..41163c656 100644 --- a/src/bioregistry/gh/new_prefix.py +++ b/src/bioregistry/gh/new_prefix.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """A script for creating pull requests for each new prefix issue on the Bioregistry's GitHub page. Run with: ``python -m bioregistry.gh.new_prefix`` @@ -9,7 +7,8 @@ import logging import sys import time -from typing import Any, Dict, Iterable, Mapping, Optional, Sequence +from collections.abc import Iterable, Mapping, Sequence +from typing import Any, Dict, Optional from uuid import uuid4 import click @@ -209,7 +208,7 @@ def make_title(prefixes: Sequence[str]) -> str: elif len(prefixes) == 2: return f"Add prefixes: {prefixes[0]} and {prefixes[1]}" else: - return f'Add prefixes: {", ".join(prefixes[:-1])}, and {prefixes[-1]}' + return f"Add prefixes: {', '.join(prefixes[:-1])}, and {prefixes[-1]}" @click.command() @@ -300,7 +299,7 @@ def main(dry: bool, github: bool, force: bool): body=body, ) if "url" in rv: - click.secho(f'PR at {rv["url"]}') + click.secho(f"PR at {rv['url']}") else: # probably an error click.secho(rv, fg="red") diff --git a/src/bioregistry/health/__init__.py b/src/bioregistry/health/__init__.py index 61d5c90d9..3b856f430 100644 --- a/src/bioregistry/health/__init__.py +++ b/src/bioregistry/health/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """An assortment of tests that can be run to check the health of the bioregistry.""" diff --git a/src/bioregistry/health/__main__.py b/src/bioregistry/health/__main__.py index c09f10e66..b55c66baf 100644 --- a/src/bioregistry/health/__main__.py +++ b/src/bioregistry/health/__main__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """A central CLI for Bioregistry health checks.""" from .cli import main diff --git a/src/bioregistry/health/check_homepages.py b/src/bioregistry/health/check_homepages.py index 269689835..d2ace707f 100644 --- a/src/bioregistry/health/check_homepages.py +++ b/src/bioregistry/health/check_homepages.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """A script to check which homepages in entries in the Bioregistry actually can be accessed.""" import sys @@ -31,7 +29,7 @@ def _process(element: Tuple[str, Set[str]]) -> Tuple[str, Set[str], bool, Option msg = "" try: res = requests.get(homepage, timeout=10) - except IOError as e: + except OSError as e: failed = True msg = e.__class__.__name__ else: @@ -41,7 +39,7 @@ def _process(element: Tuple[str, Set[str]]) -> Tuple[str, Set[str], bool, Option if failed: with tqdm.external_write_mode(): click.echo( - f'[{datetime.now().strftime("%H:%M:%S")}] ' + f"[{datetime.now().strftime('%H:%M:%S')}] " + click.style(", ".join(sorted(prefixes)), fg="green") + " at " + click.style(homepage, fg="red") diff --git a/src/bioregistry/health/check_providers.py b/src/bioregistry/health/check_providers.py index b2dee7212..fb8540bb6 100644 --- a/src/bioregistry/health/check_providers.py +++ b/src/bioregistry/health/check_providers.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """A script to check which providers in entries in the Bioregistry actually can be accessed.""" import datetime @@ -206,7 +204,7 @@ def _process(element: QueueTuple) -> ProviderStatus: try: res = requests.head(url, timeout=10, allow_redirects=True) - except IOError as e: + except OSError as e: status_code = None failed = True exception = e.__class__.__name__ @@ -219,7 +217,7 @@ def _process(element: QueueTuple) -> ProviderStatus: if failed: text = ( - f'[{datetime.datetime.now().strftime("%H:%M:%S")}] ' + f"[{datetime.datetime.now().strftime('%H:%M:%S')}] " + click.style(prefix, fg="green") + " at " + click.style(url, fg="red") diff --git a/src/bioregistry/health/cli.py b/src/bioregistry/health/cli.py index d70d5e691..5c493364f 100644 --- a/src/bioregistry/health/cli.py +++ b/src/bioregistry/health/cli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """A central CLI for Bioregistry health checks.""" import click diff --git a/src/bioregistry/license_standardizer.py b/src/bioregistry/license_standardizer.py index 4669d9baf..69b8d7e8d 100644 --- a/src/bioregistry/license_standardizer.py +++ b/src/bioregistry/license_standardizer.py @@ -1,17 +1,16 @@ -# -*- coding: utf-8 -*- - """Code for standardizing permissive licenses. Could be extended later for non-permissive information as well as using vocabularies like SPDX for storing synonyms. """ -from typing import List, Mapping, Optional +from collections.abc import Mapping +from typing import List, Optional __all__ = [ - "standardize_license", - "REVERSE_LICENSES", "LICENSES", + "REVERSE_LICENSES", + "standardize_license", ] diff --git a/src/bioregistry/metaresource_api.py b/src/bioregistry/metaresource_api.py index 917cfa9a2..58b8b5060 100644 --- a/src/bioregistry/metaresource_api.py +++ b/src/bioregistry/metaresource_api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """API for registries.""" from typing import Optional @@ -9,12 +7,12 @@ __all__ = [ "get_registry", - "get_registry_name", - "get_registry_short_name", - "get_registry_homepage", "get_registry_description", "get_registry_example", + "get_registry_homepage", + "get_registry_name", "get_registry_provider_uri_format", + "get_registry_short_name", "get_registry_uri", ] @@ -43,12 +41,12 @@ def get_registry_homepage(metaprefix: str) -> Optional[str]: :param metaprefix: The metaprefix of the registry :return: The URL for the registry, if available, otherwise ``None``. - >>> get_registry_homepage('biolink') + >>> get_registry_homepage("biolink") 'https://github.com/biolink/biolink-model' ``None`` is returned on missing values. - >>> get_registry_homepage('missing') + >>> get_registry_homepage("missing") None """ return manager.get_registry_homepage(metaprefix) @@ -60,10 +58,10 @@ def get_registry_description(metaprefix: str) -> Optional[str]: :param metaprefix: The metaprefix of the registry :return: The description for the registry, if available, otherwise ``None``. - >>> get_registry_description('biocontext') + >>> get_registry_description("biocontext") 'BioContext contains modular JSON-LD contexts for bioinformatics data.' - >>> get_registry_description('missing') + >>> get_registry_description("missing") None """ return manager.get_registry_description(metaprefix) diff --git a/src/bioregistry/pandas.py b/src/bioregistry/pandas.py index 6162e7aff..bed36e00e 100644 --- a/src/bioregistry/pandas.py +++ b/src/bioregistry/pandas.py @@ -10,7 +10,8 @@ import functools import logging import re -from typing import Callable, Dict, Optional, Pattern, Union, cast +from re import Pattern +from typing import Callable, Dict, Optional, Union, cast import pandas as pd from tabulate import tabulate diff --git a/src/bioregistry/parse_iri.py b/src/bioregistry/parse_iri.py index d63004984..4ea6ddf37 100644 --- a/src/bioregistry/parse_iri.py +++ b/src/bioregistry/parse_iri.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Functionality for parsing IRIs.""" from typing import Optional diff --git a/src/bioregistry/record_accumulator.py b/src/bioregistry/record_accumulator.py index eace91900..92f17640c 100644 --- a/src/bioregistry/record_accumulator.py +++ b/src/bioregistry/record_accumulator.py @@ -3,15 +3,12 @@ import itertools as itt import logging from collections import defaultdict +from collections.abc import Collection, Iterable, Mapping, Sequence from typing import ( - Collection, DefaultDict, Dict, - Iterable, List, - Mapping, Optional, - Sequence, Set, Tuple, cast, diff --git a/src/bioregistry/resolve.py b/src/bioregistry/resolve.py index 68f467396..529b33ab2 100644 --- a/src/bioregistry/resolve.py +++ b/src/bioregistry/resolve.py @@ -1,13 +1,12 @@ -# -*- coding: utf-8 -*- - """Utilities for normalizing prefixes.""" from __future__ import annotations import logging import typing +from collections.abc import Mapping from functools import lru_cache -from typing import Any, Dict, List, Mapping, Optional, Set +from typing import Any, Dict, List, Optional, Set import curies @@ -249,11 +248,11 @@ def get_identifiers_org_prefix(prefix: str) -> Optional[str]: :returns: The Identifiers.org/MIRIAM prefix corresponding to the prefix, if mappable. >>> import bioregistry - >>> bioregistry.get_identifiers_org_prefix('chebi') + >>> bioregistry.get_identifiers_org_prefix("chebi") 'chebi' - >>> bioregistry.get_identifiers_org_prefix('ncbitaxon') + >>> bioregistry.get_identifiers_org_prefix("ncbitaxon") 'taxonomy' - >>> assert bioregistry.get_identifiers_org_prefix('MONDO') is None + >>> assert bioregistry.get_identifiers_org_prefix("MONDO") is None """ entry = manager.get_resource(prefix) if entry is None: @@ -268,11 +267,11 @@ def get_n2t_prefix(prefix: str) -> Optional[str]: :returns: The Name-to-Thing prefix corresponding to the prefix, if mappable. >>> import bioregistry - >>> bioregistry.get_n2t_prefix('chebi') + >>> bioregistry.get_n2t_prefix("chebi") 'chebi' - >>> bioregistry.get_n2t_prefix('ncbitaxon') + >>> bioregistry.get_n2t_prefix("ncbitaxon") 'taxonomy' - >>> assert bioregistry.get_n2t_prefix('MONDO') is None + >>> assert bioregistry.get_n2t_prefix("MONDO") is None """ return manager.get_mapped_prefix(prefix, "n2t") @@ -283,9 +282,9 @@ def get_wikidata_prefix(prefix: str) -> Optional[str]: :param prefix: The prefix to lookup. :returns: The Wikidata prefix (i.e., property identifier) corresponding to the prefix, if mappable. - >>> get_wikidata_prefix('chebi') + >>> get_wikidata_prefix("chebi") 'P683' - >>> get_wikidata_prefix('ncbitaxon') + >>> get_wikidata_prefix("ncbitaxon") 'P685' """ return manager.get_mapped_prefix(prefix, "wikidata") @@ -332,11 +331,11 @@ def get_obofoundry_uri_prefix(prefix: str) -> Optional[str]: :returns: The OBO PURL URI prefix corresponding to the prefix, if mappable. >>> import bioregistry - >>> bioregistry.get_obofoundry_uri_prefix('go') # standard + >>> bioregistry.get_obofoundry_uri_prefix("go") # standard 'http://purl.obolibrary.org/obo/GO_' - >>> bioregistry.get_obofoundry_uri_prefix('ncbitaxon') # mixed case + >>> bioregistry.get_obofoundry_uri_prefix("ncbitaxon") # mixed case 'http://purl.obolibrary.org/obo/NCBITaxon_' - >>> assert bioregistry.get_obofoundry_uri_prefix('sty') is None + >>> assert bioregistry.get_obofoundry_uri_prefix("sty") is None """ entry = get_resource(prefix) if entry is None: @@ -375,18 +374,18 @@ def get_banana(prefix: str) -> Optional[str]: :return: The banana, if the prefix is valid and has an associated banana. Explicitly annotated banana - >>> assert "GO_REF" == get_banana('go.ref') + >>> assert "GO_REF" == get_banana("go.ref") Banana imported through OBO Foundry - >>> assert "GO" == get_banana('go') - >>> assert "VariO" == get_banana('vario') + >>> assert "GO" == get_banana("go") + >>> assert "VariO" == get_banana("vario") Banana inferred for OBO Foundry ontology - >>> get_banana('chebi') + >>> get_banana("chebi") 'CHEBI' No banana, no namespace in LUI - >>> assert get_banana('pdb') is None + >>> assert get_banana("pdb") is None """ entry = get_resource(prefix) if entry is None: @@ -401,11 +400,11 @@ def get_default_format(prefix: str) -> Optional[str]: :returns: The first-party URI prefix string, if available. >>> import bioregistry - >>> bioregistry.get_default_format('ncbitaxon') + >>> bioregistry.get_default_format("ncbitaxon") 'http://purl.obolibrary.org/obo/NCBITaxon_$1' - >>> bioregistry.get_default_format('go') + >>> bioregistry.get_default_format("go") 'http://purl.obolibrary.org/obo/GO_$1' - >>> assert bioregistry.get_default_format('nope') is None + >>> assert bioregistry.get_default_format("nope") is None """ entry = get_resource(prefix) if entry is None: @@ -421,11 +420,11 @@ def get_miriam_uri_prefix(prefix: str, **kwargs: Any) -> Optional[str]: :returns: The Identifiers.org/MIRIAM URI prefix, if available. >>> import bioregistry - >>> bioregistry.get_miriam_uri_prefix('ncbitaxon') + >>> bioregistry.get_miriam_uri_prefix("ncbitaxon") 'https://identifiers.org/taxonomy:' - >>> bioregistry.get_miriam_uri_prefix('go') + >>> bioregistry.get_miriam_uri_prefix("go") 'https://identifiers.org/GO:' - >>> assert bioregistry.get_miriam_uri_prefix('sty') is None + >>> assert bioregistry.get_miriam_uri_prefix("sty") is None """ resource = get_resource(prefix) if resource is None: @@ -441,11 +440,11 @@ def get_miriam_uri_format(prefix: str, **kwargs: Any) -> Optional[str]: :returns: The Identifiers.org/MIRIAM URI format string, if available. >>> import bioregistry - >>> bioregistry.get_miriam_uri_format('ncbitaxon') + >>> bioregistry.get_miriam_uri_format("ncbitaxon") 'https://identifiers.org/taxonomy:$1' - >>> bioregistry.get_miriam_uri_format('go') + >>> bioregistry.get_miriam_uri_format("go") 'https://identifiers.org/GO:$1' - >>> assert bioregistry.get_miriam_uri_format('sty') is None + >>> assert bioregistry.get_miriam_uri_format("sty") is None """ resource = get_resource(prefix) if resource is None: @@ -460,11 +459,11 @@ def get_obofoundry_uri_format(prefix: str) -> Optional[str]: :returns: The OBO PURL format string, if available. >>> import bioregistry - >>> bioregistry.get_obofoundry_uri_format('go') # standard + >>> bioregistry.get_obofoundry_uri_format("go") # standard 'http://purl.obolibrary.org/obo/GO_$1' - >>> bioregistry.get_obofoundry_uri_format('ncbitaxon') # mixed case + >>> bioregistry.get_obofoundry_uri_format("ncbitaxon") # mixed case 'http://purl.obolibrary.org/obo/NCBITaxon_$1' - >>> assert bioregistry.get_obofoundry_uri_format('sty') is None + >>> assert bioregistry.get_obofoundry_uri_format("sty") is None """ resource = get_resource(prefix) if resource is None: @@ -481,11 +480,11 @@ def get_ols_uri_prefix(prefix: str) -> Optional[str]: .. warning:: This doesn't have a normal form, so it only works for OBO Foundry at the moment. >>> import bioregistry - >>> bioregistry.get_ols_uri_prefix('go') # standard + >>> bioregistry.get_ols_uri_prefix("go") # standard 'https://www.ebi.ac.uk/ols/ontologies/go/terms?iri=http://purl.obolibrary.org/obo/GO_' - >>> bioregistry.get_ols_uri_prefix('ncbitaxon') # mixed case + >>> bioregistry.get_ols_uri_prefix("ncbitaxon") # mixed case 'https://www.ebi.ac.uk/ols/ontologies/ncbitaxon/terms?iri=http://purl.obolibrary.org/obo/NCBITaxon_' - >>> assert bioregistry.get_ols_uri_prefix('sty') is None + >>> assert bioregistry.get_ols_uri_prefix("sty") is None """ resource = get_resource(prefix) if resource is None: @@ -502,11 +501,11 @@ def get_ols_uri_format(prefix: str) -> Optional[str]: .. warning:: This doesn't have a normal form, so it only works for OBO Foundry at the moment. >>> import bioregistry - >>> bioregistry.get_ols_uri_format('go') # standard + >>> bioregistry.get_ols_uri_format("go") # standard 'https://www.ebi.ac.uk/ols/ontologies/go/terms?iri=http://purl.obolibrary.org/obo/GO_$1' - >>> bioregistry.get_ols_uri_format('ncbitaxon') # mixed case + >>> bioregistry.get_ols_uri_format("ncbitaxon") # mixed case 'https://www.ebi.ac.uk/ols/ontologies/ncbitaxon/terms?iri=http://purl.obolibrary.org/obo/NCBITaxon_$1' - >>> assert bioregistry.get_ols_uri_format('sty') is None + >>> assert bioregistry.get_ols_uri_format("sty") is None """ resource = get_resource(prefix) if resource is None: @@ -521,7 +520,7 @@ def get_biocontext_uri_format(prefix: str) -> Optional[str]: :returns: The BioContext URI format string, if available. >>> import bioregistry - >>> bioregistry.get_biocontext_uri_format('hgmd') + >>> bioregistry.get_biocontext_uri_format("hgmd") 'http://www.hgmd.cf.ac.uk/ac/gene.php?gene=$1' """ resource = get_resource(prefix) @@ -537,7 +536,7 @@ def get_prefixcommons_uri_format(prefix: str) -> Optional[str]: :returns: The Prefix Commons URI format string, if available. >>> import bioregistry - >>> bioregistry.get_prefixcommons_uri_format('antweb') + >>> bioregistry.get_prefixcommons_uri_format("antweb") 'http://www.antweb.org/specimen.do?name=$1' """ resource = get_resource(prefix) @@ -570,10 +569,10 @@ def is_deprecated(prefix: str) -> bool: assumed not to be deprecated. >>> import bioregistry - >>> assert bioregistry.is_deprecated('imr') # marked by OBO - >>> assert bioregistry.is_deprecated('idomal') # marked by OBO as inactive - >>> assert bioregistry.is_deprecated('iro') # marked by Bioregistry - >>> assert bioregistry.is_deprecated('miriam.collection') # marked by MIRIAM + >>> assert bioregistry.is_deprecated("imr") # marked by OBO + >>> assert bioregistry.is_deprecated("idomal") # marked by OBO as inactive + >>> assert bioregistry.is_deprecated("iro") # marked by Bioregistry + >>> assert bioregistry.is_deprecated("miriam.collection") # marked by MIRIAM """ return manager.is_deprecated(prefix) @@ -597,11 +596,11 @@ def get_contact_email(prefix: str) -> Optional[str]: :returns: The resource's contact email address, if it is available. >>> import bioregistry - >>> bioregistry.get_contact_email('bioregistry') # from bioregistry curation + >>> bioregistry.get_contact_email("bioregistry") # from bioregistry curation 'cthoyt@gmail.com' - >>> bioregistry.get_contact_email('chebi') + >>> bioregistry.get_contact_email("chebi") 'amalik@ebi.ac.uk' - >>> assert bioregistry.get_contact_email('pass2') is None # dead resource + >>> assert bioregistry.get_contact_email("pass2") is None # dead resource """ entry = get_resource(prefix) if entry is None: @@ -640,11 +639,11 @@ def get_contact_name(prefix: str) -> Optional[str]: :returns: The resource's contact name, if it is available. >>> import bioregistry - >>> bioregistry.get_contact_name('bioregistry') # from bioregistry curation + >>> bioregistry.get_contact_name("bioregistry") # from bioregistry curation 'Charles Tapley Hoyt' - >>> bioregistry.get_contact_name('chebi') + >>> bioregistry.get_contact_name("chebi") 'Adnan Malik' - >>> assert bioregistry.get_contact_name('pass2') is None # dead resource + >>> assert bioregistry.get_contact_name("pass2") is None # dead resource """ entry = get_resource(prefix) if entry is None: @@ -704,8 +703,8 @@ def get_provides_for(prefix: str) -> Optional[str]: :returns: The prefix of the resource that the given prefix provides for, if it's a provider. This is the inverse of :func:`get_provided_by`. - >>> assert get_provides_for('pdb') is None - >>> assert 'pdb' == get_provides_for('validatordb') + >>> assert get_provides_for("pdb") is None + >>> assert "pdb" == get_provides_for("validatordb") """ return manager.get_provides_for(prefix) @@ -730,7 +729,7 @@ def get_part_of(prefix: str) -> Optional[str]: :returns: The prefixes of the parent resource for this prefix, if one is annotated. This is the inverse of :func:`get_has_parts`. - >>> assert 'chembl' in get_part_of('chembl.compound') + >>> assert "chembl" in get_part_of("chembl.compound") """ return manager.get_part_of(prefix) @@ -742,7 +741,7 @@ def get_has_parts(prefix: str) -> Optional[List[str]]: :returns: The prefixes of resource for which this prefix is the parent. This is the inverse of :func:`get_has_parts`. - >>> assert 'chembl.compound' in get_has_parts('chembl') + >>> assert "chembl.compound" in get_has_parts("chembl") """ return manager.get_has_parts(prefix) @@ -765,8 +764,8 @@ def is_proprietary(prefix: str) -> Optional[bool]: :param prefix: The prefix to look up :returns: If the prefix corresponds to a proprietary resource. Assume false if not annotated explicitly - >>> assert is_proprietary('eurofir') - >>> assert not is_proprietary('chebi') + >>> assert is_proprietary("eurofir") + >>> assert not is_proprietary("chebi") """ entry = get_resource(prefix) if entry is None: @@ -782,8 +781,8 @@ def is_obo_foundry(prefix: str) -> Optional[bool]: :param prefix: The prefix to look up :returns: If the prefix corresponds to an OBO Foundry resource - >>> assert is_obo_foundry('chebi') - >>> assert not is_proprietary('pdb') + >>> assert is_obo_foundry("chebi") + >>> assert not is_proprietary("pdb") """ entry = get_resource(prefix) if entry is None: @@ -811,33 +810,33 @@ def parse_curie( of the separator (usually a colon ":" unless specified otherwise). The left part is the prefix, and the right part is the identifier. - >>> parse_curie('pdb:1234') + >>> parse_curie("pdb:1234") ('pdb', '1234') Address banana problem - >>> parse_curie('go:GO:1234') + >>> parse_curie("go:GO:1234") ('go', '1234') - >>> parse_curie('go:go:1234') + >>> parse_curie("go:go:1234") ('go', '1234') - >>> parse_curie('go:1234') + >>> parse_curie("go:1234") ('go', '1234') Address banana problem with OBO banana - >>> parse_curie('fbbt:FBbt:1234') + >>> parse_curie("fbbt:FBbt:1234") ('fbbt', '1234') - >>> parse_curie('fbbt:fbbt:1234') + >>> parse_curie("fbbt:fbbt:1234") ('fbbt', '1234') - >>> parse_curie('fbbt:1234') + >>> parse_curie("fbbt:1234") ('fbbt', '1234') Address banana problem with explit banana - >>> parse_curie('go.ref:GO_REF:1234') + >>> parse_curie("go.ref:GO_REF:1234") ('go.ref', '1234') - >>> parse_curie('go.ref:1234') + >>> parse_curie("go.ref:1234") ('go.ref', '1234') Parse OBO PURL curies - >>> parse_curie('GO_1234', sep="_") + >>> parse_curie("GO_1234", sep="_") ('go', '1234') Banana with no peel: @@ -845,11 +844,11 @@ def parse_curie( ('omim.ps', '12345') Use preferred (available) - >>> parse_curie('GO_1234', sep="_", use_preferred=True) + >>> parse_curie("GO_1234", sep="_", use_preferred=True) ('GO', '1234') Use preferred (unavailable) - >>> parse_curie('pdb:1234', use_preferred=True) + >>> parse_curie("pdb:1234", use_preferred=True) ('pdb', '1234') """ return manager.parse_curie(curie, sep=sep, use_preferred=use_preferred) @@ -885,43 +884,43 @@ def normalize_curie(curie: str, *, sep: str = ":", use_preferred: bool = False) of the canonicalized Bioregistry prefix. :return: A normalized CURIE, if possible using the colon as a separator - >>> normalize_curie('pdb:1234') + >>> normalize_curie("pdb:1234") 'pdb:1234' Fix commonly mistaken prefix - >>> normalize_curie('pubchem:1234') + >>> normalize_curie("pubchem:1234") 'pubchem.compound:1234' Address banana problem - >>> normalize_curie('GO:GO:1234') + >>> normalize_curie("GO:GO:1234") 'go:1234' - >>> normalize_curie('go:GO:1234') + >>> normalize_curie("go:GO:1234") 'go:1234' - >>> normalize_curie('go:go:1234') + >>> normalize_curie("go:go:1234") 'go:1234' - >>> normalize_curie('go:1234') + >>> normalize_curie("go:1234") 'go:1234' Address banana problem with OBO banana - >>> normalize_curie('fbbt:FBbt:1234') + >>> normalize_curie("fbbt:FBbt:1234") 'fbbt:1234' - >>> normalize_curie('fbbt:fbbt:1234') + >>> normalize_curie("fbbt:fbbt:1234") 'fbbt:1234' - >>> normalize_curie('fbbt:1234') + >>> normalize_curie("fbbt:1234") 'fbbt:1234' Address banana problem with explit banana - >>> normalize_curie('go.ref:GO_REF:1234') + >>> normalize_curie("go.ref:GO_REF:1234") 'go.ref:1234' - >>> normalize_curie('go.ref:1234') + >>> normalize_curie("go.ref:1234") 'go.ref:1234' Parse OBO PURL curies - >>> normalize_curie('GO_1234', sep="_") + >>> normalize_curie("GO_1234", sep="_") 'go:1234' Use preferred - >>> normalize_curie('GO_1234', sep="_", use_preferred=True) + >>> normalize_curie("GO_1234", sep="_", use_preferred=True) 'GO:1234' """ return manager.normalize_curie(curie, sep=sep, use_preferred=use_preferred) @@ -941,16 +940,16 @@ def normalize_prefix(prefix: str, *, use_preferred: bool = False) -> Optional[st This works for synonym prefixes, like: - >>> assert 'ncbitaxon' == normalize_prefix('taxonomy') + >>> assert "ncbitaxon" == normalize_prefix("taxonomy") This works for common mistaken prefixes, like: - >>> assert 'pubchem.compound' == normalize_prefix('pubchem') + >>> assert "pubchem.compound" == normalize_prefix("pubchem") This works for prefixes that are often written many ways, like: - >>> assert 'eccode' == normalize_prefix('ec-code') - >>> assert 'eccode' == normalize_prefix('EC_CODE') + >>> assert "eccode" == normalize_prefix("ec-code") + >>> assert "eccode" == normalize_prefix("EC_CODE") Get a "preferred" prefix: diff --git a/src/bioregistry/resolve_identifier.py b/src/bioregistry/resolve_identifier.py index 2556b7f6b..c418b572e 100644 --- a/src/bioregistry/resolve_identifier.py +++ b/src/bioregistry/resolve_identifier.py @@ -1,32 +1,31 @@ -# -*- coding: utf-8 -*- - """Resolvers for CURIE (e.g., pairs of prefix and identifier).""" import warnings -from typing import Mapping, Optional, Sequence, Tuple +from collections.abc import Mapping, Sequence +from typing import Optional, Tuple from .resolve import get_resource from .resource_manager import manager __all__ = [ - "is_valid_curie", - "is_standardizable_curie", - "is_valid_identifier", - "is_standardizable_identifier", - "get_providers", - "get_providers_list", - "get_identifiers_org_iri", - "get_identifiers_org_curie", - "get_obofoundry_iri", - "get_ols_iri", "get_bioportal_iri", - "get_n2t_iri", - "get_iri", - "get_link", "get_bioregistry_iri", "get_default_iri", - "standardize_identifier", + "get_identifiers_org_curie", + "get_identifiers_org_iri", + "get_iri", + "get_link", + "get_n2t_iri", + "get_obofoundry_iri", + "get_ols_iri", + "get_providers", + "get_providers_list", + "is_standardizable_curie", + "is_standardizable_identifier", + "is_valid_curie", + "is_valid_identifier", "miriam_standardize_identifier", + "standardize_identifier", ] @@ -196,66 +195,66 @@ def miriam_standardize_identifier(prefix: str, identifier: str) -> Optional[str] Examples with explicitly annotated bananas: >>> import bioregistry as br - >>> assert "VariO" == br.get_banana('vario') - >>> miriam_standardize_identifier('vario', '0376') + >>> assert "VariO" == br.get_banana("vario") + >>> miriam_standardize_identifier("vario", "0376") 'VariO:0376' - >>> miriam_standardize_identifier('vario', 'VariO:0376') + >>> miriam_standardize_identifier("vario", "VariO:0376") 'VariO:0376' Examples with bananas from OBO: >>> import bioregistry as br - >>> assert "GO" == br.get_banana('go') - >>> miriam_standardize_identifier('go', '0000001') + >>> assert "GO" == br.get_banana("go") + >>> miriam_standardize_identifier("go", "0000001") 'GO:0000001' - >>> miriam_standardize_identifier('go', 'GO:0000001') + >>> miriam_standardize_identifier("go", "GO:0000001") 'GO:0000001' - >>> assert "VariO" == br.get_banana('vario') - >>> miriam_standardize_identifier('vario', '0000001') + >>> assert "VariO" == br.get_banana("vario") + >>> miriam_standardize_identifier("vario", "0000001") 'VariO:0000001' - >>> miriam_standardize_identifier('vario', 'VariO:0000001') + >>> miriam_standardize_identifier("vario", "VariO:0000001") 'VariO:0000001' Examples from OBO Foundry: - >>> miriam_standardize_identifier('chebi', '1234') + >>> miriam_standardize_identifier("chebi", "1234") 'CHEBI:1234' - >>> miriam_standardize_identifier('chebi', 'CHEBI:1234') + >>> miriam_standardize_identifier("chebi", "CHEBI:1234") 'CHEBI:1234' Examples outside of OBO: - >>> miriam_standardize_identifier('mgi', '6017782') + >>> miriam_standardize_identifier("mgi", "6017782") 'MGI:6017782' - >>> miriam_standardize_identifier('mgi', 'MGI:6017782') + >>> miriam_standardize_identifier("mgi", "MGI:6017782") 'MGI:6017782' - >>> miriam_standardize_identifier('swisslipid', '000000341') + >>> miriam_standardize_identifier("swisslipid", "000000341") 'SLM:000000341' - >>> miriam_standardize_identifier('swisslipid', 'SLM:000000341') + >>> miriam_standardize_identifier("swisslipid", "SLM:000000341") 'SLM:000000341' Special cases with underscore-delimited bananas - >>> miriam_standardize_identifier('cellosaurus', '0001') + >>> miriam_standardize_identifier("cellosaurus", "0001") 'CVCL_0001' - >>> miriam_standardize_identifier('cellosaurus', 'CVCL_0001') + >>> miriam_standardize_identifier("cellosaurus", "CVCL_0001") 'CVCL_0001' - >>> miriam_standardize_identifier('ro', '0000001') + >>> miriam_standardize_identifier("ro", "0000001") 'RO_0000001' - >>> miriam_standardize_identifier('ro', 'RO_0000001') + >>> miriam_standardize_identifier("ro", "RO_0000001") 'RO_0000001' - >>> miriam_standardize_identifier('geogeo', '000000001') + >>> miriam_standardize_identifier("geogeo", "000000001") 'GEO_000000001' - >>> miriam_standardize_identifier('geogeo', 'GEO_000000001') + >>> miriam_standardize_identifier("geogeo", "GEO_000000001") 'GEO_000000001' - >>> miriam_standardize_identifier('biomodels.kisao', '0000057') + >>> miriam_standardize_identifier("biomodels.kisao", "0000057") 'KISAO_0000057' - >>> miriam_standardize_identifier('biomodels.kisao', 'KISAO_0000057') + >>> miriam_standardize_identifier("biomodels.kisao", "KISAO_0000057") 'KISAO_0000057' Standard: >>> import bioregistry as br - >>> assert br.get_banana('pdb') is None - >>> assert not br.get_namespace_in_lui('pdb') - >>> miriam_standardize_identifier('pdb', '00000020') + >>> assert br.get_banana("pdb") is None + >>> assert not br.get_namespace_in_lui("pdb") + >>> miriam_standardize_identifier("pdb", "00000020") '00000020' """ resource = get_resource(prefix) @@ -271,7 +270,7 @@ def get_default_iri(prefix: str, identifier: str) -> Optional[str]: :param identifier: The identifier in the CURIE :return: A IRI string corresponding to the default provider, if available. - >>> get_default_iri('chebi', '24867') + >>> get_default_iri("chebi", "24867") 'http://purl.obolibrary.org/obo/CHEBI_24867' """ return manager.get_default_iri(prefix, identifier) @@ -295,7 +294,7 @@ def get_identifiers_org_iri(prefix: str, identifier: str) -> Optional[str]: :return: A IRI string corresponding to the Identifiers.org, if the prefix exists and is mapped to MIRIAM. - >>> get_identifiers_org_iri('chebi', '24867') + >>> get_identifiers_org_iri("chebi", "24867") 'https://identifiers.org/CHEBI:24867' >>> get_identifiers_org_iri("interpro", "IPR016380") 'https://identifiers.org/interpro:IPR016380' @@ -315,7 +314,7 @@ def get_n2t_iri(prefix: str, identifier: str) -> Optional[str]: :return: A IRI string corresponding to the N2T resolve, if the prefix exists and is mapped to N2T. - >>> get_n2t_iri('chebi', '24867') + >>> get_n2t_iri("chebi", "24867") 'https://n2t.net/chebi:24867' """ return manager.get_n2t_iri(prefix, identifier) @@ -328,7 +327,7 @@ def get_bioportal_iri(prefix: str, identifier: str) -> Optional[str]: :param identifier: The identifier in the CURIE :return: A link to the Bioportal page - >>> get_bioportal_iri('chebi', '24431') + >>> get_bioportal_iri("chebi", "24431") 'https://bioportal.bioontology.org/ontologies/CHEBI/?p=classes&conceptid=http://purl.obolibrary.org/obo/CHEBI_24431' """ return manager.get_bioportal_iri(prefix, identifier) @@ -346,12 +345,12 @@ def get_obofoundry_iri(prefix: str, identifier: str) -> Optional[str]: :param identifier: The identifier :return: The OBO Foundry URL if the prefix can be mapped to an OBO Foundry entry - >>> get_obofoundry_iri('chebi', '24431') + >>> get_obofoundry_iri("chebi", "24431") 'http://purl.obolibrary.org/obo/CHEBI_24431' For entries where there's a preferred prefix, it is respected. - >>> get_obofoundry_iri('fbbt', '00007294') + >>> get_obofoundry_iri("fbbt", "00007294") 'http://purl.obolibrary.org/obo/FBbt_00007294' """ return manager.get_obofoundry_iri(prefix, identifier) @@ -385,31 +384,31 @@ def get_bioregistry_iri(prefix: str, identifier: str) -> Optional[str]: :param identifier: The identifier in the CURIE :return: A link to the bioregistry resolver - >>> get_bioregistry_iri('pdb', '1234') + >>> get_bioregistry_iri("pdb", "1234") 'https://bioregistry.io/pdb:1234' Redundant prefix (OBO) - >>> get_bioregistry_iri('go', 'GO:0120212') + >>> get_bioregistry_iri("go", "GO:0120212") 'https://bioregistry.io/go:0120212' - >>> get_bioregistry_iri('go', 'go:0120212') + >>> get_bioregistry_iri("go", "go:0120212") 'https://bioregistry.io/go:0120212' - >>> get_bioregistry_iri('go', '0120212') + >>> get_bioregistry_iri("go", "0120212") 'https://bioregistry.io/go:0120212' Redundant prefix (banana; OBO) - >>> get_bioregistry_iri('fbbt', 'fbbt:00007294') + >>> get_bioregistry_iri("fbbt", "fbbt:00007294") 'https://bioregistry.io/fbbt:00007294' - >>> get_bioregistry_iri('fbbt', 'fbbt:00007294') + >>> get_bioregistry_iri("fbbt", "fbbt:00007294") 'https://bioregistry.io/fbbt:00007294' - >>> get_bioregistry_iri('fbbt', '00007294') + >>> get_bioregistry_iri("fbbt", "00007294") 'https://bioregistry.io/fbbt:00007294' Redundant prefix (banana; explicit) - >>> get_bioregistry_iri('go.ref', 'GO_REF:1234') + >>> get_bioregistry_iri("go.ref", "GO_REF:1234") 'https://bioregistry.io/go.ref:1234' - >>> get_bioregistry_iri('go.ref', '1234') + >>> get_bioregistry_iri("go.ref", "1234") 'https://bioregistry.io/go.ref:1234' """ return manager.get_bioregistry_iri(prefix=prefix, identifier=identifier) diff --git a/src/bioregistry/resource_manager.py b/src/bioregistry/resource_manager.py index e2151b0b0..eedad75d3 100644 --- a/src/bioregistry/resource_manager.py +++ b/src/bioregistry/resource_manager.py @@ -1,24 +1,19 @@ -# -*- coding: utf-8 -*- - """A class-based client to a metaregistry.""" from __future__ import annotations import logging import typing -import warnings from collections import Counter, defaultdict -from functools import lru_cache +from collections.abc import Iterable, Mapping, Sequence +from functools import cache from pathlib import Path from typing import ( Any, Callable, Dict, - Iterable, List, - Mapping, Optional, - Sequence, Set, Tuple, Union, @@ -292,7 +287,9 @@ def parse_uri(self, uri: str, *, use_preferred: bool = False) -> MaybeCURIE: IRI from the OLS: - >>> manager.parse_uri("https://www.ebi.ac.uk/ols/ontologies/ecao/terms?iri=http://purl.obolibrary.org/obo/ECAO_0107180") # noqa:E501 + >>> manager.parse_uri( + ... "https://www.ebi.ac.uk/ols/ontologies/ecao/terms?iri=http://purl.obolibrary.org/obo/ECAO_0107180" + ... ) # noqa:E501 ('ecao', '0107180') IRI from native provider @@ -363,7 +360,9 @@ def compress(self, uri: str, *, use_preferred: bool = False) -> Optional[str]: URI from the OLS: - >>> manager.compress("https://www.ebi.ac.uk/ols/ontologies/ecao/terms?iri=http://purl.obolibrary.org/obo/ECAO_1") # noqa:E501 + >>> manager.compress( + ... "https://www.ebi.ac.uk/ols/ontologies/ecao/terms?iri=http://purl.obolibrary.org/obo/ECAO_1" + ... ) # noqa:E501 'ecao:1' URI from native provider @@ -439,12 +438,12 @@ def normalize_parsed_curie( norm_prefix = resource.get_preferred_prefix() or norm_prefix return norm_prefix, norm_identifier - @lru_cache(maxsize=None) # noqa:B019 + @cache # noqa:B019 def get_registry_map(self, metaprefix: str) -> Dict[str, str]: """Get a mapping from the Bioregistry prefixes to prefixes in another registry.""" return dict(self._iter_registry_map(metaprefix)) - @lru_cache(maxsize=None) # noqa:B019 + @cache # noqa:B019 def get_registry_invmap(self, metaprefix: str, normalize: bool = False) -> Dict[str, str]: """Get a mapping from prefixes in another registry to Bioregistry prefixes. @@ -1035,7 +1034,7 @@ def get_default_iri(self, prefix: str, identifier: str) -> Optional[str]: :return: A IRI string corresponding to the default provider, if available. >>> from bioregistry import manager - >>> manager.get_default_iri('chebi', '24867') + >>> manager.get_default_iri("chebi", "24867") 'http://purl.obolibrary.org/obo/CHEBI_24867' """ entry = self.get_resource(prefix) @@ -1051,7 +1050,7 @@ def get_rdf_uri(self, prefix: str, identifier: str) -> Optional[str]: :return: A IRI string corresponding to the canonical RDF provider, if available. >>> from bioregistry import manager - >>> manager.get_rdf_uri('edam', 'data_1153') + >>> manager.get_rdf_uri("edam", "data_1153") 'http://edamontology.org/data_1153' """ entry = self.get_resource(prefix) @@ -1087,7 +1086,7 @@ def get_bioportal_iri(self, prefix: str, identifier: str) -> Optional[str]: :return: A link to the Bioportal page >>> from bioregistry import manager - >>> manager.get_bioportal_iri('chebi', '24431') + >>> manager.get_bioportal_iri("chebi", "24431") 'https://bioportal.bioontology.org/ontologies/CHEBI/?p=classes&conceptid=http://purl.obolibrary.org/obo/CHEBI_24431' """ bioportal_prefix = self.get_mapped_prefix(prefix, "bioportal") @@ -1137,12 +1136,12 @@ def get_obofoundry_iri(self, prefix: str, identifier: str) -> Optional[str]: :return: The OBO Foundry URL if the prefix can be mapped to an OBO Foundry entry >>> from bioregistry import manager - >>> manager.get_obofoundry_iri('chebi', '24431') + >>> manager.get_obofoundry_iri("chebi", "24431") 'http://purl.obolibrary.org/obo/CHEBI_24431' For entries where there's a preferred prefix, it is respected. - >>> manager.get_obofoundry_iri('fbbt', '00007294') + >>> manager.get_obofoundry_iri("fbbt", "00007294") 'http://purl.obolibrary.org/obo/FBbt_00007294' """ return self.get_formatted_iri("obofoundry", prefix, identifier) diff --git a/src/bioregistry/schema/constants.py b/src/bioregistry/schema/constants.py index ccfddedda..1513f28ad 100644 --- a/src/bioregistry/schema/constants.py +++ b/src/bioregistry/schema/constants.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- - """Schema constants.""" +from collections.abc import Mapping from dataclasses import dataclass, field -from typing import TYPE_CHECKING, List, Mapping, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union import rdflib.namespace from rdflib import ( diff --git a/src/bioregistry/schema/struct.py b/src/bioregistry/schema/struct.py index 469234210..a331132ee 100644 --- a/src/bioregistry/schema/struct.py +++ b/src/bioregistry/schema/struct.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Pydantic models for the Bioregistry.""" from __future__ import annotations @@ -11,6 +9,7 @@ import re import textwrap import typing +from collections.abc import Iterable, Mapping, Sequence from functools import lru_cache from operator import attrgetter from typing import ( @@ -19,12 +18,8 @@ Callable, ClassVar, Dict, - Iterable, List, - Mapping, Optional, - Pattern, - Sequence, Set, Tuple, Union, @@ -65,12 +60,12 @@ __all__ = [ "Attributable", "Author", - "Provider", - "Resource", "Collection", - "Registry", "Context", + "Provider", "Publication", + "Registry", + "Resource", "get_json_schema", ] @@ -258,7 +253,7 @@ class Provider(BaseModel): first_party: Optional[bool] = Field( None, description="Annotates whether a provider is from the first-party organization" ) - publications: Optional[List["Publication"]] = Field( + publications: Optional[List[Publication]] = Field( default=None, description="A list of publications about the provider. See the `indra` provider for `hgnc` for an example.", ) @@ -305,7 +300,7 @@ def get_url(self) -> str: return f"https://bioregistry.io/{prefix}:{identifier}" raise ValueError("no fields were full") - def _matches_any_field(self, other: "Publication") -> bool: + def _matches_any_field(self, other: Publication) -> bool: return ( (self.pubmed is not None and self.pubmed == other.pubmed) or (self.doi is not None and self.doi == other.doi) @@ -758,7 +753,7 @@ def get_rdf_uri(self, identifier: str) -> Optional[str]: return None return fmt.replace("$1", identifier) - def __setitem__(self, key: str, value: Any) -> None: # noqa: D105 + def __setitem__(self, key: str, value: Any) -> None: setattr(self, key, value) def get_banana(self) -> Optional[str]: @@ -1030,9 +1025,9 @@ def get_pattern_re_with_banana(self, strict: bool = True) -> typing.Pattern[str] Loose match does not require banana - >>> resource.get_pattern_re_with_banana(strict=False).match('1234') + >>> resource.get_pattern_re_with_banana(strict=False).match("1234") - >>> resource.get_pattern_re_with_banana(strict=False).match('CHEBI:1234') + >>> resource.get_pattern_re_with_banana(strict=False).match("CHEBI:1234") """ p = self.get_pattern_with_banana(strict=strict) @@ -1273,8 +1268,8 @@ def is_deprecated(self) -> bool: >>> from bioregistry import get_resource >>> assert get_resource("imr").is_deprecated() # marked by OBO - >>> assert get_resource("iro").is_deprecated() # marked by Bioregistry - >>> assert get_resource("miriam.collection").is_deprecated() # marked by MIRIAM + >>> assert get_resource("iro").is_deprecated() # marked by Bioregistry + >>> assert get_resource("miriam.collection").is_deprecated() # marked by MIRIAM """ if self.deprecated is not None: return self.deprecated @@ -1498,11 +1493,11 @@ def get_identifiers_org_prefix(self) -> Optional[str]: :returns: The Identifiers.org/MIRIAM prefix corresponding to the prefix, if mappable. >>> from bioregistry import get_resource - >>> get_resource('chebi').get_identifiers_org_prefix() + >>> get_resource("chebi").get_identifiers_org_prefix() 'chebi' - >>> get_resource('ncbitaxon').get_identifiers_org_prefix() + >>> get_resource("ncbitaxon").get_identifiers_org_prefix() 'taxonomy' - >>> assert get_resource('MONDO').get_identifiers_org_prefix() is None + >>> assert get_resource("MONDO").get_identifiers_org_prefix() is None """ return self.get_mapped_prefix("miriam") @@ -1524,19 +1519,19 @@ def get_miriam_uri_prefix( :returns: The Identifiers.org/MIRIAM URI prefix, if available. >>> from bioregistry import get_resource - >>> get_resource('ncbitaxon').get_miriam_uri_prefix() + >>> get_resource("ncbitaxon").get_miriam_uri_prefix() 'https://identifiers.org/taxonomy:' - >>> get_resource('go').get_miriam_uri_prefix() + >>> get_resource("go").get_miriam_uri_prefix() 'https://identifiers.org/GO:' - >>> get_resource('doid').get_miriam_uri_prefix(legacy_banana=True) + >>> get_resource("doid").get_miriam_uri_prefix(legacy_banana=True) 'https://identifiers.org/doid/DOID:' - >>> get_resource('vario').get_miriam_uri_prefix(legacy_banana=True) + >>> get_resource("vario").get_miriam_uri_prefix(legacy_banana=True) 'https://identifiers.org/vario/VariO:' - >>> get_resource('cellosaurus').get_miriam_uri_prefix(legacy_banana=True) + >>> get_resource("cellosaurus").get_miriam_uri_prefix(legacy_banana=True) 'https://identifiers.org/cellosaurus/CVCL_' - >>> get_resource('doid').get_miriam_uri_prefix(legacy_delimiter=True) + >>> get_resource("doid").get_miriam_uri_prefix(legacy_delimiter=True) 'https://identifiers.org/DOID/' - >>> assert get_resource('sty').get_miriam_uri_prefix() is None + >>> assert get_resource("sty").get_miriam_uri_prefix() is None """ miriam_prefix = self.get_identifiers_org_prefix() if miriam_prefix is None: @@ -1565,11 +1560,11 @@ def get_miriam_uri_format( :returns: The Identifiers.org/MIRIAM URL format string, if available. >>> from bioregistry import get_resource - >>> get_resource('ncbitaxon').get_miriam_uri_format() + >>> get_resource("ncbitaxon").get_miriam_uri_format() 'https://identifiers.org/taxonomy:$1' - >>> get_resource('go').get_miriam_uri_format() + >>> get_resource("go").get_miriam_uri_format() 'https://identifiers.org/GO:$1' - >>> assert get_resource('sty').get_miriam_uri_format() is None + >>> assert get_resource("sty").get_miriam_uri_format() is None """ miriam_url_prefix = self.get_miriam_uri_prefix( legacy_delimiter=legacy_delimiter, @@ -1686,7 +1681,7 @@ def get_rdf_uri_prefix(self) -> Optional[str]: rdf_uri_format = self.get_rdf_uri_format() return self._clip_uri_format(rdf_uri_format) - URI_FORMATTERS: ClassVar[Mapping[str, Callable[["Resource"], Optional[str]]]] = { + URI_FORMATTERS: ClassVar[Mapping[str, Callable[[Resource], Optional[str]]]] = { "default": get_default_format, "rdf": get_rdf_uri_format, "bioregistry": get_bioregistry_uri_format, @@ -1788,7 +1783,7 @@ def get_uri_format(self, priority: Optional[Sequence[str]] = None) -> Optional[s ChEBI example above). Do so like: >>> from bioregistry import get_resource - >>> priority = ['obofoundry', 'bioregistry', 'biocontext', 'miriam', 'ols'] + >>> priority = ["obofoundry", "bioregistry", "biocontext", "miriam", "ols"] >>> get_resource("chebi").get_uri_format(priority=priority) 'http://purl.obolibrary.org/obo/CHEBI_$1' """ @@ -1804,7 +1799,7 @@ def get_uri_prefix(self, priority: Optional[Sequence[str]] = None) -> Optional[s it MUST have only one ``$1`` and end with ``$1`` to use the function. >>> import bioregistry - >>> bioregistry.get_uri_prefix('chebi') + >>> bioregistry.get_uri_prefix("chebi") 'http://purl.obolibrary.org/obo/CHEBI_' """ for uri_format in self._iterate_uri_formats(priority): @@ -1925,23 +1920,23 @@ def standardize_identifier(self, identifier: str) -> str: Examples with explicitly annotated bananas: >>> from bioregistry import get_resource - >>> get_resource("vario").standardize_identifier('0376') + >>> get_resource("vario").standardize_identifier("0376") '0376' - >>> get_resource("vario").standardize_identifier('VariO:0376') + >>> get_resource("vario").standardize_identifier("VariO:0376") '0376' - >>> get_resource("swisslipid").standardize_identifier('000000001') + >>> get_resource("swisslipid").standardize_identifier("000000001") '000000001' - >>> get_resource("swisslipid").standardize_identifier('SLM:000000001') + >>> get_resource("swisslipid").standardize_identifier("SLM:000000001") '000000001' Examples with bananas from OBO: - >>> get_resource("fbbt").standardize_identifier('00007294') + >>> get_resource("fbbt").standardize_identifier("00007294") '00007294' - >>> get_resource("chebi").standardize_identifier('1234') + >>> get_resource("chebi").standardize_identifier("1234") '1234' - >>> get_resource("chebi").standardize_identifier('CHEBI:1234') + >>> get_resource("chebi").standardize_identifier("CHEBI:1234") '1234' - >>> get_resource("chebi").standardize_identifier('CHEBI_1234') + >>> get_resource("chebi").standardize_identifier("CHEBI_1234") '1234' Examples from OBO Foundry that should not have a redundant @@ -1952,7 +1947,7 @@ def standardize_identifier(self, identifier: str) -> str: '9606' Standard: - >>> get_resource("pdb").standardize_identifier('00000020') + >>> get_resource("pdb").standardize_identifier("00000020") '00000020' """ icf = identifier.casefold() @@ -2000,21 +1995,21 @@ def miriam_standardize_identifier(self, identifier: str) -> Optional[str]: Examples with explicitly annotated bananas: >>> from bioregistry import get_resource - >>> get_resource("vario").miriam_standardize_identifier('0376') + >>> get_resource("vario").miriam_standardize_identifier("0376") 'VariO:0376' - >>> get_resource("vario").miriam_standardize_identifier('VariO:0376') + >>> get_resource("vario").miriam_standardize_identifier("VariO:0376") 'VariO:0376' Examples with bananas from OBO: - >>> get_resource("go").miriam_standardize_identifier('0000001') + >>> get_resource("go").miriam_standardize_identifier("0000001") 'GO:0000001' - >>> get_resource("go").miriam_standardize_identifier('GO:0000001') + >>> get_resource("go").miriam_standardize_identifier("GO:0000001") 'GO:0000001' Examples from OBO Foundry: - >>> get_resource("chebi").miriam_standardize_identifier('1234') + >>> get_resource("chebi").miriam_standardize_identifier("1234") 'CHEBI:1234' - >>> get_resource("chebi").miriam_standardize_identifier('CHEBI:1234') + >>> get_resource("chebi").miriam_standardize_identifier("CHEBI:1234") 'CHEBI:1234' Examples from OBO Foundry that should not have a redundant @@ -2025,7 +2020,7 @@ def miriam_standardize_identifier(self, identifier: str) -> Optional[str]: '9606' Standard: - >>> get_resource("pdb").miriam_standardize_identifier('00000020') + >>> get_resource("pdb").miriam_standardize_identifier("00000020") '00000020' """ if self.get_miriam_prefix() is None: @@ -2120,7 +2115,9 @@ def get_download_owl(self) -> Optional[str]: used in the doctest): >>> url = get_resource("birnlex").get_download_owl() - >>> assert url is not None and url.startswith("http://aber-owl.net/media/ontologies/BIRNLEX/") + >>> assert url is not None and url.startswith( + ... "http://aber-owl.net/media/ontologies/BIRNLEX/" + ... ) """ if self.download_owl: @@ -2751,7 +2748,7 @@ class Context(BaseModel): prefix maps to serve various communities based on the standard Bioregistry prefix map, custom prefix remapping rules, custom URI prefix remapping rules, custom prefix maps, and other community-specific logic. - """ # noqa:D400,D205 + """ # noqa: D205 name: str = Field( ..., diff --git a/src/bioregistry/schema/utils.py b/src/bioregistry/schema/utils.py index 49248450d..810efb272 100644 --- a/src/bioregistry/schema/utils.py +++ b/src/bioregistry/schema/utils.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- - """Utilities for Bioregistry data structures.""" from __future__ import annotations -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from pydantic import BaseModel @@ -12,8 +11,8 @@ __all__ = [ "sanitize_dict", - "sanitize_model", "sanitize_mapping", + "sanitize_model", ] diff --git a/src/bioregistry/schema_utils.py b/src/bioregistry/schema_utils.py index acff9595e..6158c5cf4 100644 --- a/src/bioregistry/schema_utils.py +++ b/src/bioregistry/schema_utils.py @@ -1,14 +1,13 @@ -# -*- coding: utf-8 -*- - """Utilities for interacting with data and the schema.""" import json import logging from collections import defaultdict +from collections.abc import Mapping from functools import lru_cache from operator import attrgetter from pathlib import Path -from typing import List, Mapping, Optional, Set, Union, cast +from typing import List, Optional, Set, Union, cast from .constants import ( BIOREGISTRY_PATH, diff --git a/src/bioregistry/summary.py b/src/bioregistry/summary.py index 42b539edc..0ef13f77c 100644 --- a/src/bioregistry/summary.py +++ b/src/bioregistry/summary.py @@ -2,10 +2,10 @@ import datetime from collections import defaultdict +from collections.abc import Mapping from dataclasses import dataclass from itertools import combinations from textwrap import dedent -from typing import Mapping import click from more_click import force_option @@ -49,8 +49,8 @@ def get_text(self): The Bioregistry ({get_version()}; {self.datetime_str}) integrates content from and aligns {self.number_registries_aligned:,} external registries and contains {self.number_prefixes:,} individual records. These records extend on each prior registry - (e.g., 838 records in {self.external_sizes['prefixcommons']}, {self.external_sizes['miriam']:,} - in MIRIAM/Identifiers.org, and {self.external_sizes['n2t']:,} in Name-to-Thing (Wimalaratne et al., 2018), + (e.g., 838 records in {self.external_sizes["prefixcommons"]}, {self.external_sizes["miriam"]:,} + in MIRIAM/Identifiers.org, and {self.external_sizes["n2t"]:,} in Name-to-Thing (Wimalaratne et al., 2018), each accessed on {self.datetime_str}), as well as the aligned registries combined: {self.number_prefixes_novel:,} of the Bioregistry’s {self.number_prefixes:,} records are novel, i.e. they do not appear in any existing registry. The Bioregistry also adds novel curated metadata diff --git a/src/bioregistry/upload_ndex.py b/src/bioregistry/upload_ndex.py index 2b94a15f0..c6aaa1b56 100644 --- a/src/bioregistry/upload_ndex.py +++ b/src/bioregistry/upload_ndex.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Generate a small knowledge graph relating entities.""" from typing import TYPE_CHECKING @@ -23,7 +21,7 @@ def main(): """Upload the Bioregistry KG to NDEx.""" try: upload() - except IOError: + except OSError: click.secho("Failed to upload to NDEx", fg="red") else: click.echo(f"Uploaded to NDEx. See: https://bioregistry.io/ndex:{NDEX_UUID}") diff --git a/src/bioregistry/uri_format.py b/src/bioregistry/uri_format.py index 0cd339a47..5a7b91c6d 100644 --- a/src/bioregistry/uri_format.py +++ b/src/bioregistry/uri_format.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tools for getting URI format strings. .. warning:: @@ -8,15 +6,16 @@ the prefix should go, which makes them more general than URI prefix strings. """ -from typing import Collection, Mapping, Optional, Sequence +from collections.abc import Collection, Mapping, Sequence +from typing import Optional from .resource_manager import manager __all__ = [ + "get_pattern_map", + "get_prefix_map", "get_uri_format", "get_uri_prefix", - "get_prefix_map", - "get_pattern_map", ] @@ -39,7 +38,7 @@ def get_uri_format(prefix: str, priority: Optional[Sequence[str]] = None) -> Opt identifier. ``$1`` could potentially appear multiple times. >>> import bioregistry - >>> bioregistry.get_uri_format('chebi') + >>> bioregistry.get_uri_format("chebi") 'http://purl.obolibrary.org/obo/CHEBI_$1' If you want to specify a different priority order, you can do so with the ``priority`` keyword. This @@ -48,7 +47,9 @@ def get_uri_format(prefix: str, priority: Optional[Sequence[str]] = None) -> Opt ChEBI example above). Do so like: >>> import bioregistry - >>> bioregistry.get_uri_format('chebi', priority=['obofoundry', 'bioregistry', 'biocontext', 'miriam', 'ols']) + >>> bioregistry.get_uri_format( + ... "chebi", priority=["obofoundry", "bioregistry", "biocontext", "miriam", "ols"] + ... ) 'http://purl.obolibrary.org/obo/CHEBI_$1' """ return manager.get_uri_format(prefix=prefix, priority=priority) @@ -63,7 +64,7 @@ def get_uri_prefix(prefix: str, priority: Optional[Sequence[str]] = None) -> Opt it MUST have only one ``$1`` and end with ``$1`` to use thie function. >>> import bioregistry - >>> bioregistry.get_uri_prefix('chebi') + >>> bioregistry.get_uri_prefix("chebi") 'http://purl.obolibrary.org/obo/CHEBI_' """ return manager.get_uri_prefix(prefix=prefix, priority=priority) diff --git a/src/bioregistry/utils.py b/src/bioregistry/utils.py index a2abc658b..a57a09336 100644 --- a/src/bioregistry/utils.py +++ b/src/bioregistry/utils.py @@ -47,7 +47,7 @@ class OLSBroken(RuntimeError): def secho(s: str, fg: str = "cyan", bold: bool = True, **kwargs: Any) -> None: """Wrap :func:`click.secho`.""" click.echo( - f'[{datetime.now().strftime("%H:%M:%S")}] ' + click.style(s, fg=fg, bold=bold, **kwargs) + f"[{datetime.now().strftime('%H:%M:%S')}] " + click.style(s, fg=fg, bold=bold, **kwargs) ) diff --git a/tests/__init__.py b/tests/__init__.py index 7facd5940..e8097c36e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Tests for the Bioregistry.""" diff --git a/tests/test_acquisition.py b/tests/test_acquisition.py index d1f518aab..b2c944789 100644 --- a/tests/test_acquisition.py +++ b/tests/test_acquisition.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for downloading external data.""" import unittest diff --git a/tests/test_collections.py b/tests/test_collections.py index d93864415..1b267d5a3 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for collections.""" import logging diff --git a/tests/test_contexts.py b/tests/test_contexts.py index 7104e3d7c..afbb09dcc 100644 --- a/tests/test_contexts.py +++ b/tests/test_contexts.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for checking the integrity of the contexts.""" import json diff --git a/tests/test_data.py b/tests/test_data.py index ad76cd059..2db15babf 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -375,7 +375,7 @@ def test_examples(self): msg = f"{prefix} is missing an example local identifier" if entry.ols: msg += ( - f'\nSee: https://www.ebi.ac.uk/ols/ontologies/{entry.ols["prefix"]}/terms' + f"\nSee: https://www.ebi.ac.uk/ols/ontologies/{entry.ols['prefix']}/terms" ) example = entry.get_example() self.assertIsNotNone(example, msg=msg) diff --git a/tests/test_duplicates.py b/tests/test_duplicates.py index f4cf16bcd..213316f25 100644 --- a/tests/test_duplicates.py +++ b/tests/test_duplicates.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests to make sure there are no duplicates.""" import unittest diff --git a/tests/test_identifiers_org.py b/tests/test_identifiers_org.py index bf7a0061c..5f887bca9 100644 --- a/tests/test_identifiers_org.py +++ b/tests/test_identifiers_org.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- - """Tests for identifiers.org.""" import unittest -from typing import Mapping +from collections.abc import Mapping import requests diff --git a/tests/test_indra.py b/tests/test_indra.py index 12967797d..f336a9fbb 100644 --- a/tests/test_indra.py +++ b/tests/test_indra.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Test the ability of the bioregistry to cover INDRA identifiers.""" import unittest diff --git a/tests/test_manager.py b/tests/test_manager.py index ae259c078..b1f723d86 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for managers.""" import unittest diff --git a/tests/test_metaregistry.py b/tests/test_metaregistry.py index d6900fd96..07e59aacc 100644 --- a/tests/test_metaregistry.py +++ b/tests/test_metaregistry.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for the metaregistry.""" import unittest diff --git a/tests/test_obofoundry.py b/tests/test_obofoundry.py index cb911aec8..a87c14d24 100644 --- a/tests/test_obofoundry.py +++ b/tests/test_obofoundry.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for OBO Foundry data.""" import unittest diff --git a/tests/test_ols.py b/tests/test_ols.py index 02fc38360..abd0a06e1 100644 --- a/tests/test_ols.py +++ b/tests/test_ols.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Tests for the OLS.""" import json diff --git a/tests/test_resolve.py b/tests/test_resolve.py index eac2c4a6c..d679859f6 100644 --- a/tests/test_resolve.py +++ b/tests/test_resolve.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- - """Tests for the bioregistry client.""" import unittest -from typing import Iterable, Tuple +from collections.abc import Iterable +from typing import Tuple import bioregistry from bioregistry import manager diff --git a/tests/test_web/__init__.py b/tests/test_web/__init__.py index 3bd589042..4798896ce 100644 --- a/tests/test_web/__init__.py +++ b/tests/test_web/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Test for the Bioregistry web application.""" diff --git a/tests/test_web/test_api.py b/tests/test_web/test_api.py index c687cae5a..aea058f3c 100644 --- a/tests/test_web/test_api.py +++ b/tests/test_web/test_api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Test for web.""" from __future__ import annotations diff --git a/tests/test_web/test_ui.py b/tests/test_web/test_ui.py index df2545ba9..070f0a870 100644 --- a/tests/test_web/test_ui.py +++ b/tests/test_web/test_ui.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """Test for web.""" from __future__ import annotations