pyobo 0.10.11__py3-none-any.whl → 0.11.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyobo/__init__.py +0 -2
- pyobo/__main__.py +0 -2
- pyobo/api/__init__.py +0 -2
- pyobo/api/alts.py +6 -7
- pyobo/api/hierarchy.py +14 -15
- pyobo/api/metadata.py +3 -4
- pyobo/api/names.py +51 -31
- pyobo/api/properties.py +6 -7
- pyobo/api/relations.py +12 -11
- pyobo/api/species.py +5 -6
- pyobo/api/typedefs.py +1 -3
- pyobo/api/utils.py +63 -2
- pyobo/api/xrefs.py +4 -5
- pyobo/aws.py +3 -5
- pyobo/cli/__init__.py +0 -2
- pyobo/cli/aws.py +0 -2
- pyobo/cli/cli.py +0 -4
- pyobo/cli/database.py +1 -3
- pyobo/cli/lookup.py +2 -4
- pyobo/cli/utils.py +0 -2
- pyobo/constants.py +0 -3
- pyobo/getters.py +19 -26
- pyobo/gilda_utils.py +28 -8
- pyobo/identifier_utils.py +32 -15
- pyobo/mocks.py +5 -6
- pyobo/normalizer.py +24 -24
- pyobo/obographs.py +3 -3
- pyobo/plugins.py +3 -4
- pyobo/py.typed +0 -0
- pyobo/reader.py +19 -21
- pyobo/registries/__init__.py +0 -2
- pyobo/registries/metaregistry.py +6 -8
- pyobo/resource_utils.py +1 -3
- pyobo/resources/__init__.py +0 -2
- pyobo/resources/ncbitaxon.py +2 -3
- pyobo/resources/ro.py +2 -4
- pyobo/sources/README.md +15 -0
- pyobo/sources/__init__.py +2 -2
- pyobo/sources/agrovoc.py +3 -3
- pyobo/sources/antibodyregistry.py +4 -5
- pyobo/sources/biogrid.py +7 -7
- pyobo/sources/ccle.py +3 -4
- pyobo/sources/cgnc.py +1 -3
- pyobo/sources/chebi.py +2 -4
- pyobo/sources/chembl.py +1 -3
- pyobo/sources/civic_gene.py +2 -3
- pyobo/sources/complexportal.py +3 -5
- pyobo/sources/conso.py +2 -4
- pyobo/sources/cpt.py +1 -3
- pyobo/sources/credit.py +68 -0
- pyobo/sources/cvx.py +1 -3
- pyobo/sources/depmap.py +3 -4
- pyobo/sources/dictybase_gene.py +1 -3
- pyobo/sources/drugbank.py +6 -7
- pyobo/sources/drugbank_salt.py +3 -4
- pyobo/sources/drugcentral.py +5 -7
- pyobo/sources/expasy.py +11 -12
- pyobo/sources/famplex.py +3 -5
- pyobo/sources/flybase.py +2 -4
- pyobo/sources/geonames.py +28 -10
- pyobo/sources/gmt_utils.py +5 -6
- pyobo/sources/go.py +4 -6
- pyobo/sources/gwascentral_phenotype.py +1 -3
- pyobo/sources/gwascentral_study.py +2 -3
- pyobo/sources/hgnc.py +8 -9
- pyobo/sources/hgncgenefamily.py +2 -4
- pyobo/sources/icd10.py +3 -4
- pyobo/sources/icd11.py +3 -4
- pyobo/sources/icd_utils.py +6 -7
- pyobo/sources/interpro.py +3 -5
- pyobo/sources/itis.py +1 -3
- pyobo/sources/kegg/__init__.py +0 -2
- pyobo/sources/kegg/api.py +3 -4
- pyobo/sources/kegg/genes.py +3 -4
- pyobo/sources/kegg/genome.py +1 -3
- pyobo/sources/kegg/pathway.py +5 -6
- pyobo/sources/mesh.py +19 -21
- pyobo/sources/mgi.py +1 -3
- pyobo/sources/mirbase.py +4 -6
- pyobo/sources/mirbase_constants.py +0 -2
- pyobo/sources/mirbase_family.py +1 -3
- pyobo/sources/mirbase_mature.py +1 -3
- pyobo/sources/msigdb.py +4 -5
- pyobo/sources/ncbigene.py +3 -5
- pyobo/sources/npass.py +2 -4
- pyobo/sources/omim_ps.py +1 -3
- pyobo/sources/pathbank.py +3 -5
- pyobo/sources/pfam.py +1 -3
- pyobo/sources/pfam_clan.py +1 -3
- pyobo/sources/pid.py +3 -5
- pyobo/sources/pombase.py +1 -3
- pyobo/sources/pubchem.py +5 -6
- pyobo/sources/reactome.py +2 -4
- pyobo/sources/rgd.py +3 -4
- pyobo/sources/rhea.py +9 -10
- pyobo/sources/ror.py +69 -22
- pyobo/sources/selventa/__init__.py +0 -2
- pyobo/sources/selventa/schem.py +1 -3
- pyobo/sources/selventa/scomp.py +1 -3
- pyobo/sources/selventa/sdis.py +1 -3
- pyobo/sources/selventa/sfam.py +1 -3
- pyobo/sources/sgd.py +1 -3
- pyobo/sources/slm.py +1 -3
- pyobo/sources/umls/__init__.py +0 -2
- pyobo/sources/umls/__main__.py +0 -2
- pyobo/sources/umls/get_synonym_types.py +1 -1
- pyobo/sources/umls/umls.py +2 -4
- pyobo/sources/uniprot/__init__.py +0 -2
- pyobo/sources/uniprot/uniprot.py +6 -6
- pyobo/sources/uniprot/uniprot_ptm.py +6 -5
- pyobo/sources/utils.py +3 -5
- pyobo/sources/wikipathways.py +1 -3
- pyobo/sources/zfin.py +2 -3
- pyobo/ssg/__init__.py +3 -2
- pyobo/struct/__init__.py +0 -2
- pyobo/struct/reference.py +13 -15
- pyobo/struct/struct.py +106 -99
- pyobo/struct/typedef.py +19 -10
- pyobo/struct/utils.py +0 -2
- pyobo/utils/__init__.py +0 -2
- pyobo/utils/cache.py +14 -6
- pyobo/utils/io.py +9 -10
- pyobo/utils/iter.py +5 -6
- pyobo/utils/misc.py +1 -3
- pyobo/utils/ndex_utils.py +6 -7
- pyobo/utils/path.py +5 -5
- pyobo/version.py +3 -5
- pyobo/xrefdb/__init__.py +0 -2
- pyobo/xrefdb/canonicalizer.py +27 -18
- pyobo/xrefdb/priority.py +0 -2
- pyobo/xrefdb/sources/__init__.py +9 -7
- pyobo/xrefdb/sources/biomappings.py +0 -2
- pyobo/xrefdb/sources/cbms2019.py +0 -2
- pyobo/xrefdb/sources/chembl.py +5 -7
- pyobo/xrefdb/sources/compath.py +1 -3
- pyobo/xrefdb/sources/famplex.py +3 -5
- pyobo/xrefdb/sources/gilda.py +0 -2
- pyobo/xrefdb/sources/intact.py +5 -5
- pyobo/xrefdb/sources/ncit.py +1 -3
- pyobo/xrefdb/sources/pubchem.py +2 -4
- pyobo/xrefdb/sources/wikidata.py +10 -5
- pyobo/xrefdb/xrefs_pipeline.py +15 -16
- {pyobo-0.10.11.dist-info → pyobo-0.11.0.dist-info}/LICENSE +1 -1
- pyobo-0.11.0.dist-info/METADATA +723 -0
- pyobo-0.11.0.dist-info/RECORD +171 -0
- {pyobo-0.10.11.dist-info → pyobo-0.11.0.dist-info}/WHEEL +1 -1
- pyobo-0.11.0.dist-info/entry_points.txt +2 -0
- pyobo/xrefdb/bengo.py +0 -44
- pyobo-0.10.11.dist-info/METADATA +0 -499
- pyobo-0.10.11.dist-info/RECORD +0 -169
- pyobo-0.10.11.dist-info/entry_points.txt +0 -15
- {pyobo-0.10.11.dist-info → pyobo-0.11.0.dist-info}/top_level.txt +0 -0
pyobo/sources/ror.py
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
"""Convert the Research Organization Registry (ROR) into an ontology."""
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
import json
|
|
4
6
|
import zipfile
|
|
5
|
-
from
|
|
7
|
+
from collections.abc import Iterable
|
|
8
|
+
from typing import Any
|
|
6
9
|
|
|
7
10
|
import bioregistry
|
|
8
11
|
import zenodo_client
|
|
9
12
|
from tqdm.auto import tqdm
|
|
10
13
|
|
|
11
|
-
from pyobo.struct import Obo, Reference, Term
|
|
14
|
+
from pyobo.struct import Obo, Reference, Term
|
|
12
15
|
from pyobo.struct.struct import acronym
|
|
16
|
+
from pyobo.struct.typedef import (
|
|
17
|
+
has_homepage,
|
|
18
|
+
has_part,
|
|
19
|
+
has_predecessor,
|
|
20
|
+
has_successor,
|
|
21
|
+
located_in,
|
|
22
|
+
part_of,
|
|
23
|
+
see_also,
|
|
24
|
+
)
|
|
13
25
|
|
|
14
26
|
PREFIX = "ror"
|
|
15
27
|
ROR_ZENODO_RECORD_ID = "10086202"
|
|
16
28
|
|
|
17
29
|
# Constants
|
|
18
30
|
ORG_CLASS = Reference(prefix="OBI", identifier="0000245")
|
|
19
|
-
LOCATED_IN = Reference(prefix="RO", identifier="0001025")
|
|
20
|
-
PART_OF = Reference(prefix="BFO", identifier="0000050")
|
|
21
|
-
HAS_PART = Reference(prefix="BFO", identifier="0000051")
|
|
22
|
-
SUCCESSOR = Reference(prefix="BFO", identifier="0000063")
|
|
23
|
-
PREDECESSOR = Reference(prefix="BFO", identifier="0000062")
|
|
24
31
|
|
|
25
32
|
RMAP = {
|
|
26
|
-
"Related":
|
|
27
|
-
"Child":
|
|
28
|
-
"Parent":
|
|
29
|
-
"Predecessor":
|
|
30
|
-
"Successor":
|
|
31
|
-
"Located in":
|
|
33
|
+
"Related": see_also,
|
|
34
|
+
"Child": has_part,
|
|
35
|
+
"Parent": part_of,
|
|
36
|
+
"Predecessor": has_predecessor,
|
|
37
|
+
"Successor": has_successor,
|
|
38
|
+
"Located in": located_in,
|
|
32
39
|
}
|
|
33
40
|
NAME_REMAPPING = {
|
|
34
41
|
"'s-Hertogenbosch": "Den Bosch", # SMH Netherlands, why u gotta be like this
|
|
@@ -43,20 +50,20 @@ class RORGetter(Obo):
|
|
|
43
50
|
"""An ontology representation of the ROR."""
|
|
44
51
|
|
|
45
52
|
ontology = bioregistry_key = PREFIX
|
|
46
|
-
typedefs =
|
|
53
|
+
typedefs = [has_homepage, *RMAP.values()]
|
|
47
54
|
synonym_typedefs = [acronym]
|
|
48
55
|
idspaces = {
|
|
49
56
|
"ror": "https://ror.org/",
|
|
50
57
|
"geonames": "https://www.geonames.org/",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
58
|
+
"ENVO": "http://purl.obolibrary.org/obo/ENVO_",
|
|
59
|
+
"BFO": "http://purl.obolibrary.org/obo/BFO_",
|
|
60
|
+
"RO": "http://purl.obolibrary.org/obo/RO_",
|
|
61
|
+
"OBI": "http://purl.obolibrary.org/obo/OBI_",
|
|
62
|
+
"OMO": "http://purl.obolibrary.org/obo/OMO_",
|
|
56
63
|
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
def __post_init__(self):
|
|
66
|
+
def __post_init__(self):
|
|
60
67
|
self.data_version, _url, _path = _get_info()
|
|
61
68
|
super().__post_init__()
|
|
62
69
|
|
|
@@ -65,6 +72,18 @@ class RORGetter(Obo):
|
|
|
65
72
|
return iterate_ror_terms(force=force)
|
|
66
73
|
|
|
67
74
|
|
|
75
|
+
ROR_ORGANIZATION_TYPE_TO_OBI = {
|
|
76
|
+
"Education": ...,
|
|
77
|
+
"Facility": ...,
|
|
78
|
+
"Company": ...,
|
|
79
|
+
"Government": ...,
|
|
80
|
+
"Healthcare": ...,
|
|
81
|
+
"Other": ...,
|
|
82
|
+
"Archive": ...,
|
|
83
|
+
}
|
|
84
|
+
_MISSED_ORG_TYPES: set[str] = set()
|
|
85
|
+
|
|
86
|
+
|
|
68
87
|
def iterate_ror_terms(*, force: bool = False) -> Iterable[Term]:
|
|
69
88
|
"""Iterate over terms in ROR."""
|
|
70
89
|
version, source_uri, records = get_latest(force=force)
|
|
@@ -74,10 +93,23 @@ def iterate_ror_terms(*, force: bool = False) -> Iterable[Term]:
|
|
|
74
93
|
name = record["name"]
|
|
75
94
|
name = NAME_REMAPPING.get(name, name)
|
|
76
95
|
|
|
96
|
+
organization_types = record.get("types", [])
|
|
97
|
+
description = f"{organization_types[0]} in {record['country']['country_name']}"
|
|
98
|
+
if established := record["established"]:
|
|
99
|
+
description += f" established in {established}"
|
|
100
|
+
|
|
77
101
|
term = Term(
|
|
78
|
-
reference=Reference(prefix=PREFIX, identifier=identifier, name=name),
|
|
102
|
+
reference=Reference(prefix=PREFIX, identifier=identifier, name=name),
|
|
103
|
+
type="Instance",
|
|
104
|
+
definition=description,
|
|
79
105
|
)
|
|
80
106
|
term.append_parent(ORG_CLASS)
|
|
107
|
+
# TODO replace term.append_parent(ORG_CLASS) with:
|
|
108
|
+
# for organization_type in organization_types:
|
|
109
|
+
# term.append_parent(ORG_PARENTS[organization_type])
|
|
110
|
+
|
|
111
|
+
for link in record.get("links", []):
|
|
112
|
+
term.append_property(has_homepage, link)
|
|
81
113
|
|
|
82
114
|
if name.startswith("The "):
|
|
83
115
|
term.append_synonym(name.removeprefix("The "))
|
|
@@ -159,5 +191,20 @@ def get_latest(*, force: bool = False):
|
|
|
159
191
|
raise FileNotFoundError
|
|
160
192
|
|
|
161
193
|
|
|
194
|
+
def get_ror_to_country_geonames(**kwargs: Any) -> dict[str, str]:
|
|
195
|
+
"""Get a mapping of ROR ids to GeoNames IDs for countries."""
|
|
196
|
+
from pyobo.sources.geonames import get_city_to_country
|
|
197
|
+
|
|
198
|
+
city_to_country = get_city_to_country()
|
|
199
|
+
rv = {}
|
|
200
|
+
for term in iterate_ror_terms(**kwargs):
|
|
201
|
+
city_geonames_reference = term.get_relationship(located_in)
|
|
202
|
+
if city_geonames_reference is None:
|
|
203
|
+
continue
|
|
204
|
+
if city_geonames_reference.identifier in city_to_country:
|
|
205
|
+
rv[term.identifier] = city_to_country[city_geonames_reference.identifier]
|
|
206
|
+
return rv
|
|
207
|
+
|
|
208
|
+
|
|
162
209
|
if __name__ == "__main__":
|
|
163
|
-
RORGetter().write_default(write_obo=True, force=True)
|
|
210
|
+
RORGetter(force=True).write_default(write_obo=True, force=True)
|
pyobo/sources/selventa/schem.py
CHANGED
pyobo/sources/selventa/scomp.py
CHANGED
pyobo/sources/selventa/sdis.py
CHANGED
pyobo/sources/selventa/sfam.py
CHANGED
pyobo/sources/sgd.py
CHANGED
pyobo/sources/slm.py
CHANGED
pyobo/sources/umls/__init__.py
CHANGED
pyobo/sources/umls/__main__.py
CHANGED
pyobo/sources/umls/umls.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""Converter for UMLS.
|
|
4
2
|
|
|
5
3
|
Run with ``python -m pyobo.sources.umls``
|
|
@@ -8,7 +6,7 @@ Run with ``python -m pyobo.sources.umls``
|
|
|
8
6
|
import itertools as itt
|
|
9
7
|
import operator
|
|
10
8
|
from collections import defaultdict
|
|
11
|
-
from
|
|
9
|
+
from collections.abc import Iterable, Mapping
|
|
12
10
|
|
|
13
11
|
import bioregistry
|
|
14
12
|
import pandas as pd
|
|
@@ -67,7 +65,7 @@ def get_obo() -> Obo:
|
|
|
67
65
|
return UMLSGetter()
|
|
68
66
|
|
|
69
67
|
|
|
70
|
-
def get_semantic_types() -> Mapping[str,
|
|
68
|
+
def get_semantic_types() -> Mapping[str, set[str]]:
|
|
71
69
|
"""Get UMLS semantic types for each term."""
|
|
72
70
|
dd = defaultdict(set)
|
|
73
71
|
with open_umls_semantic_types() as file:
|
pyobo/sources/uniprot/uniprot.py
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""Converter for UniProt."""
|
|
4
2
|
|
|
3
|
+
from collections.abc import Iterable
|
|
5
4
|
from operator import attrgetter
|
|
6
5
|
from pathlib import Path
|
|
7
|
-
from typing import
|
|
6
|
+
from typing import Optional, cast
|
|
8
7
|
|
|
9
|
-
import bioversions
|
|
10
8
|
from tqdm.auto import tqdm
|
|
11
9
|
|
|
12
10
|
from pyobo import Obo, Reference
|
|
11
|
+
from pyobo.api.utils import get_version
|
|
13
12
|
from pyobo.constants import RAW_MODULE
|
|
14
13
|
from pyobo.identifier_utils import standardize_ec
|
|
15
14
|
from pyobo.struct import Term, derives_from, enables, from_species, participates_in
|
|
@@ -57,6 +56,7 @@ class UniProtGetter(Obo):
|
|
|
57
56
|
gene_product_of,
|
|
58
57
|
molecularly_interacts_with,
|
|
59
58
|
derives_from,
|
|
59
|
+
located_in,
|
|
60
60
|
]
|
|
61
61
|
|
|
62
62
|
def iter_terms(self, force: bool = False) -> Iterable[Term]:
|
|
@@ -154,7 +154,7 @@ def iter_terms(version: Optional[str] = None) -> Iterable[Term]:
|
|
|
154
154
|
yield term
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def _parse_go(go_terms) ->
|
|
157
|
+
def _parse_go(go_terms) -> list[Reference]:
|
|
158
158
|
rv = []
|
|
159
159
|
if go_terms:
|
|
160
160
|
for go_term in go_terms.split(";"):
|
|
@@ -166,7 +166,7 @@ def _parse_go(go_terms) -> List[Reference]:
|
|
|
166
166
|
def ensure(version: Optional[str] = None, force: bool = False) -> Path:
|
|
167
167
|
"""Ensure the reviewed uniprot names are available."""
|
|
168
168
|
if version is None:
|
|
169
|
-
version =
|
|
169
|
+
version = get_version("uniprot")
|
|
170
170
|
return RAW_MODULE.ensure(
|
|
171
171
|
PREFIX,
|
|
172
172
|
version,
|
|
@@ -27,7 +27,8 @@ DR Cross-reference to external Optional; once or more
|
|
|
27
27
|
|
|
28
28
|
import itertools as itt
|
|
29
29
|
from collections import defaultdict
|
|
30
|
-
from
|
|
30
|
+
from collections.abc import Iterable, Mapping
|
|
31
|
+
from typing import Optional
|
|
31
32
|
|
|
32
33
|
from tqdm.auto import tqdm
|
|
33
34
|
|
|
@@ -63,18 +64,18 @@ def iter_terms(force: bool = False) -> Iterable[Term]:
|
|
|
63
64
|
path = ensure_path(PREFIX, url=URL, force=force)
|
|
64
65
|
with open(path) as file:
|
|
65
66
|
lines = list(file)
|
|
66
|
-
it: Iterable[
|
|
67
|
+
it: Iterable[tuple[str, str]] = ((line[:2], line[2:].strip()) for line in lines[47:-5])
|
|
67
68
|
for i, (_, term_lines) in enumerate(itt.groupby(it, key=lambda p: p[0] == "//")):
|
|
68
69
|
term = _parse(i, term_lines)
|
|
69
70
|
if term:
|
|
70
71
|
yield term
|
|
71
72
|
|
|
72
73
|
|
|
73
|
-
def _parse(i, lines: Iterable[
|
|
74
|
-
dd_:
|
|
74
|
+
def _parse(i, lines: Iterable[tuple[str, str]]) -> Optional[Term]:
|
|
75
|
+
dd_: defaultdict[str, list[str]] = defaultdict(list)
|
|
75
76
|
for key, value in lines:
|
|
76
77
|
dd_[key].append(value)
|
|
77
|
-
dd: Mapping[str,
|
|
78
|
+
dd: Mapping[str, list[str]] = dict(dd_)
|
|
78
79
|
|
|
79
80
|
if "//" in dd:
|
|
80
81
|
return None
|
pyobo/sources/utils.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""Utilities for converters."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
6
|
-
from
|
|
4
|
+
from collections.abc import Mapping
|
|
7
5
|
|
|
8
6
|
from ..utils.io import multisetdict
|
|
9
7
|
|
|
@@ -15,7 +13,7 @@ __all__ = [
|
|
|
15
13
|
logger = logging.getLogger(__name__)
|
|
16
14
|
|
|
17
15
|
|
|
18
|
-
def get_go_mapping(path: str, prefix: str) -> Mapping[str,
|
|
16
|
+
def get_go_mapping(path: str, prefix: str) -> Mapping[str, set[tuple[str, str]]]:
|
|
19
17
|
"""Get a GO mapping file."""
|
|
20
18
|
with open(path) as file:
|
|
21
19
|
return multisetdict(
|
|
@@ -23,7 +21,7 @@ def get_go_mapping(path: str, prefix: str) -> Mapping[str, Set[Tuple[str, str]]]
|
|
|
23
21
|
)
|
|
24
22
|
|
|
25
23
|
|
|
26
|
-
def process_go_mapping_line(line: str, prefix: str) ->
|
|
24
|
+
def process_go_mapping_line(line: str, prefix: str) -> tuple[str, tuple[str, str]]:
|
|
27
25
|
"""Process a GO mapping line."""
|
|
28
26
|
line1 = line[len(f"{prefix}:") :]
|
|
29
27
|
line2, go_id = line1.rsplit(";", 1)
|
pyobo/sources/wikipathways.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""Converter for WikiPathways."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
6
4
|
import urllib.error
|
|
7
|
-
from
|
|
5
|
+
from collections.abc import Iterable
|
|
8
6
|
|
|
9
7
|
from .gmt_utils import parse_wikipathways_gmt
|
|
10
8
|
from ..constants import SPECIES_REMAPPING
|
pyobo/sources/zfin.py
CHANGED
pyobo/ssg/__init__.py
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import itertools as itt
|
|
4
4
|
from collections import defaultdict
|
|
5
|
+
from collections.abc import Sequence
|
|
5
6
|
from operator import attrgetter
|
|
6
7
|
from pathlib import Path
|
|
7
|
-
from typing import Optional,
|
|
8
|
+
from typing import Optional, Union
|
|
8
9
|
|
|
9
10
|
import bioregistry
|
|
10
11
|
from bioregistry.constants import BIOREGISTRY_DEFAULT_BASE_URL
|
|
@@ -37,7 +38,7 @@ def make_site(
|
|
|
37
38
|
metaregistry_metaprefix: Optional[str] = None,
|
|
38
39
|
metaregistry_name: Optional[str] = None,
|
|
39
40
|
metaregistry_base_url: Optional[str] = None,
|
|
40
|
-
show_properties_in_manifest: Optional[Sequence[
|
|
41
|
+
show_properties_in_manifest: Optional[Sequence[tuple[str, str]]] = None,
|
|
41
42
|
) -> None:
|
|
42
43
|
"""Make a website in the given directory.
|
|
43
44
|
|
pyobo/struct/__init__.py
CHANGED
pyobo/struct/reference.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""Data structures for OBO."""
|
|
4
2
|
|
|
5
|
-
from typing import Optional
|
|
3
|
+
from typing import Optional
|
|
6
4
|
|
|
7
5
|
import bioregistry
|
|
8
6
|
import curies
|
|
9
7
|
from curies.api import ExpansionError
|
|
10
|
-
from pydantic import Field,
|
|
8
|
+
from pydantic import Field, field_validator, model_validator
|
|
11
9
|
|
|
12
10
|
from .utils import obo_escape
|
|
13
11
|
from ..identifier_utils import normalize_curie
|
|
@@ -23,7 +21,7 @@ class Reference(curies.Reference):
|
|
|
23
21
|
|
|
24
22
|
name: Optional[str] = Field(default=None, description="the name of the reference")
|
|
25
23
|
|
|
26
|
-
@
|
|
24
|
+
@field_validator("prefix")
|
|
27
25
|
def validate_prefix(cls, v): # noqa
|
|
28
26
|
"""Validate the prefix for this reference."""
|
|
29
27
|
norm_prefix = bioregistry.normalize_prefix(v)
|
|
@@ -41,7 +39,7 @@ class Reference(curies.Reference):
|
|
|
41
39
|
"""Get the preferred curie for this reference."""
|
|
42
40
|
return f"{self.preferred_prefix}:{self.identifier}"
|
|
43
41
|
|
|
44
|
-
@
|
|
42
|
+
@model_validator(mode="before")
|
|
45
43
|
def validate_identifier(cls, values): # noqa
|
|
46
44
|
"""Validate the identifier."""
|
|
47
45
|
prefix, identifier = values.get("prefix"), values.get("identifier")
|
|
@@ -124,7 +122,7 @@ class Reference(curies.Reference):
|
|
|
124
122
|
def _escaped_identifier(self):
|
|
125
123
|
return obo_escape(self.identifier)
|
|
126
124
|
|
|
127
|
-
def __str__(self):
|
|
125
|
+
def __str__(self):
|
|
128
126
|
identifier_lower = self.identifier.lower()
|
|
129
127
|
if identifier_lower.startswith(f"{self.prefix.lower()}:"):
|
|
130
128
|
rv = identifier_lower
|
|
@@ -134,7 +132,7 @@ class Reference(curies.Reference):
|
|
|
134
132
|
rv = f"{rv} ! {self.name}"
|
|
135
133
|
return rv
|
|
136
134
|
|
|
137
|
-
def __hash__(self):
|
|
135
|
+
def __hash__(self):
|
|
138
136
|
return hash((self.__class__, self.prefix, self.identifier))
|
|
139
137
|
|
|
140
138
|
|
|
@@ -145,32 +143,32 @@ class Referenced:
|
|
|
145
143
|
|
|
146
144
|
@property
|
|
147
145
|
def prefix(self):
|
|
148
|
-
"""The prefix of the typedef."""
|
|
146
|
+
"""The prefix of the typedef."""
|
|
149
147
|
return self.reference.prefix
|
|
150
148
|
|
|
151
149
|
@property
|
|
152
150
|
def name(self):
|
|
153
|
-
"""The name of the typedef."""
|
|
151
|
+
"""The name of the typedef."""
|
|
154
152
|
return self.reference.name
|
|
155
153
|
|
|
156
154
|
@property
|
|
157
155
|
def identifier(self) -> str:
|
|
158
|
-
"""The local unique identifier for this typedef."""
|
|
156
|
+
"""The local unique identifier for this typedef."""
|
|
159
157
|
return self.reference.identifier
|
|
160
158
|
|
|
161
159
|
@property
|
|
162
160
|
def curie(self) -> str:
|
|
163
|
-
"""The CURIE for this typedef."""
|
|
161
|
+
"""The CURIE for this typedef."""
|
|
164
162
|
return self.reference.curie
|
|
165
163
|
|
|
166
164
|
@property
|
|
167
165
|
def preferred_curie(self) -> str:
|
|
168
|
-
"""The preferred CURIE for this typedef."""
|
|
166
|
+
"""The preferred CURIE for this typedef."""
|
|
169
167
|
return self.reference.preferred_curie
|
|
170
168
|
|
|
171
169
|
@property
|
|
172
|
-
def pair(self) ->
|
|
173
|
-
"""The pair of namespace/identifier."""
|
|
170
|
+
def pair(self) -> tuple[str, str]:
|
|
171
|
+
"""The pair of namespace/identifier."""
|
|
174
172
|
return self.reference.pair
|
|
175
173
|
|
|
176
174
|
@property
|