pyobo 0.11.2__py3-none-any.whl → 0.12.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/.DS_Store +0 -0
- pyobo/__init__.py +95 -20
- pyobo/__main__.py +0 -0
- pyobo/api/__init__.py +81 -10
- pyobo/api/alts.py +52 -42
- pyobo/api/combine.py +39 -0
- pyobo/api/edges.py +68 -0
- pyobo/api/hierarchy.py +231 -203
- pyobo/api/metadata.py +14 -19
- pyobo/api/names.py +207 -127
- pyobo/api/properties.py +117 -113
- pyobo/api/relations.py +68 -94
- pyobo/api/species.py +24 -21
- pyobo/api/typedefs.py +11 -11
- pyobo/api/utils.py +66 -13
- pyobo/api/xrefs.py +108 -114
- pyobo/cli/__init__.py +0 -0
- pyobo/cli/cli.py +35 -50
- pyobo/cli/database.py +183 -161
- pyobo/{xrefdb/xrefs_pipeline.py → cli/database_utils.py} +54 -73
- pyobo/cli/lookup.py +163 -195
- pyobo/cli/utils.py +19 -6
- pyobo/constants.py +102 -3
- pyobo/getters.py +196 -118
- pyobo/gilda_utils.py +79 -200
- pyobo/identifier_utils/__init__.py +41 -0
- pyobo/identifier_utils/api.py +296 -0
- pyobo/identifier_utils/model.py +130 -0
- pyobo/identifier_utils/preprocessing.json +812 -0
- pyobo/identifier_utils/preprocessing.py +61 -0
- pyobo/identifier_utils/relations/__init__.py +8 -0
- pyobo/identifier_utils/relations/api.py +162 -0
- pyobo/identifier_utils/relations/data.json +5824 -0
- pyobo/identifier_utils/relations/data_owl.json +57 -0
- pyobo/identifier_utils/relations/data_rdf.json +1 -0
- pyobo/identifier_utils/relations/data_rdfs.json +7 -0
- pyobo/mocks.py +9 -6
- pyobo/ner/__init__.py +9 -0
- pyobo/ner/api.py +72 -0
- pyobo/ner/normalizer.py +33 -0
- pyobo/obographs.py +43 -39
- pyobo/plugins.py +5 -4
- pyobo/py.typed +0 -0
- pyobo/reader.py +1358 -395
- pyobo/reader_utils.py +155 -0
- pyobo/resource_utils.py +42 -22
- pyobo/resources/__init__.py +0 -0
- pyobo/resources/goc.py +75 -0
- pyobo/resources/goc.tsv +188 -0
- pyobo/resources/ncbitaxon.py +4 -5
- pyobo/resources/ncbitaxon.tsv.gz +0 -0
- pyobo/resources/ro.py +3 -2
- pyobo/resources/ro.tsv +0 -0
- pyobo/resources/so.py +0 -0
- pyobo/resources/so.tsv +0 -0
- pyobo/sources/README.md +12 -8
- pyobo/sources/__init__.py +52 -29
- pyobo/sources/agrovoc.py +0 -0
- pyobo/sources/antibodyregistry.py +11 -12
- pyobo/sources/bigg/__init__.py +13 -0
- pyobo/sources/bigg/bigg_compartment.py +81 -0
- pyobo/sources/bigg/bigg_metabolite.py +229 -0
- pyobo/sources/bigg/bigg_model.py +46 -0
- pyobo/sources/bigg/bigg_reaction.py +77 -0
- pyobo/sources/biogrid.py +1 -2
- pyobo/sources/ccle.py +7 -12
- pyobo/sources/cgnc.py +0 -5
- pyobo/sources/chebi.py +1 -1
- pyobo/sources/chembl/__init__.py +9 -0
- pyobo/sources/{chembl.py → chembl/chembl_compound.py} +13 -25
- pyobo/sources/chembl/chembl_target.py +160 -0
- pyobo/sources/civic_gene.py +55 -15
- pyobo/sources/clinicaltrials.py +160 -0
- pyobo/sources/complexportal.py +24 -24
- pyobo/sources/conso.py +14 -22
- pyobo/sources/cpt.py +0 -0
- pyobo/sources/credit.py +1 -9
- pyobo/sources/cvx.py +27 -5
- pyobo/sources/depmap.py +9 -12
- pyobo/sources/dictybase_gene.py +2 -7
- pyobo/sources/drugbank/__init__.py +9 -0
- pyobo/sources/{drugbank.py → drugbank/drugbank.py} +11 -16
- pyobo/sources/{drugbank_salt.py → drugbank/drugbank_salt.py} +3 -8
- pyobo/sources/drugcentral.py +17 -13
- pyobo/sources/expasy.py +31 -34
- pyobo/sources/famplex.py +13 -18
- pyobo/sources/flybase.py +3 -8
- pyobo/sources/gard.py +62 -0
- pyobo/sources/geonames/__init__.py +9 -0
- pyobo/sources/geonames/features.py +28 -0
- pyobo/sources/{geonames.py → geonames/geonames.py} +87 -26
- pyobo/sources/geonames/utils.py +115 -0
- pyobo/sources/gmt_utils.py +6 -7
- pyobo/sources/go.py +20 -13
- pyobo/sources/gtdb.py +154 -0
- pyobo/sources/gwascentral/__init__.py +9 -0
- pyobo/sources/{gwascentral_phenotype.py → gwascentral/gwascentral_phenotype.py} +5 -7
- pyobo/sources/{gwascentral_study.py → gwascentral/gwascentral_study.py} +1 -7
- pyobo/sources/hgnc/__init__.py +9 -0
- pyobo/sources/{hgnc.py → hgnc/hgnc.py} +56 -70
- pyobo/sources/{hgncgenefamily.py → hgnc/hgncgenefamily.py} +8 -18
- pyobo/sources/icd/__init__.py +9 -0
- pyobo/sources/{icd10.py → icd/icd10.py} +35 -37
- pyobo/sources/icd/icd11.py +148 -0
- pyobo/sources/{icd_utils.py → icd/icd_utils.py} +66 -20
- pyobo/sources/interpro.py +4 -9
- pyobo/sources/itis.py +0 -5
- pyobo/sources/kegg/__init__.py +0 -0
- pyobo/sources/kegg/api.py +16 -38
- pyobo/sources/kegg/genes.py +9 -20
- pyobo/sources/kegg/genome.py +1 -7
- pyobo/sources/kegg/pathway.py +9 -21
- pyobo/sources/mesh.py +58 -24
- pyobo/sources/mgi.py +3 -10
- pyobo/sources/mirbase/__init__.py +11 -0
- pyobo/sources/{mirbase.py → mirbase/mirbase.py} +8 -11
- pyobo/sources/{mirbase_constants.py → mirbase/mirbase_constants.py} +0 -0
- pyobo/sources/{mirbase_family.py → mirbase/mirbase_family.py} +4 -8
- pyobo/sources/{mirbase_mature.py → mirbase/mirbase_mature.py} +3 -7
- pyobo/sources/msigdb.py +74 -39
- pyobo/sources/ncbi/__init__.py +9 -0
- pyobo/sources/ncbi/ncbi_gc.py +162 -0
- pyobo/sources/{ncbigene.py → ncbi/ncbigene.py} +18 -19
- pyobo/sources/nih_reporter.py +60 -0
- pyobo/sources/nlm/__init__.py +9 -0
- pyobo/sources/nlm/nlm_catalog.py +48 -0
- pyobo/sources/nlm/nlm_publisher.py +36 -0
- pyobo/sources/nlm/utils.py +116 -0
- pyobo/sources/npass.py +6 -8
- pyobo/sources/omim_ps.py +10 -3
- pyobo/sources/pathbank.py +4 -8
- pyobo/sources/pfam/__init__.py +9 -0
- pyobo/sources/{pfam.py → pfam/pfam.py} +3 -8
- pyobo/sources/{pfam_clan.py → pfam/pfam_clan.py} +2 -7
- pyobo/sources/pharmgkb/__init__.py +15 -0
- pyobo/sources/pharmgkb/pharmgkb_chemical.py +89 -0
- pyobo/sources/pharmgkb/pharmgkb_disease.py +77 -0
- pyobo/sources/pharmgkb/pharmgkb_gene.py +108 -0
- pyobo/sources/pharmgkb/pharmgkb_pathway.py +63 -0
- pyobo/sources/pharmgkb/pharmgkb_variant.py +84 -0
- pyobo/sources/pharmgkb/utils.py +86 -0
- pyobo/sources/pid.py +1 -6
- pyobo/sources/pombase.py +6 -10
- pyobo/sources/pubchem.py +4 -9
- pyobo/sources/reactome.py +5 -11
- pyobo/sources/rgd.py +11 -16
- pyobo/sources/rhea.py +37 -36
- pyobo/sources/ror.py +69 -42
- pyobo/sources/selventa/__init__.py +0 -0
- pyobo/sources/selventa/schem.py +4 -7
- pyobo/sources/selventa/scomp.py +1 -6
- pyobo/sources/selventa/sdis.py +4 -7
- pyobo/sources/selventa/sfam.py +1 -6
- pyobo/sources/sgd.py +6 -11
- pyobo/sources/signor/__init__.py +7 -0
- pyobo/sources/signor/download.py +41 -0
- pyobo/sources/signor/signor_complexes.py +105 -0
- pyobo/sources/slm.py +12 -15
- pyobo/sources/umls/__init__.py +7 -1
- pyobo/sources/umls/__main__.py +0 -0
- pyobo/sources/umls/get_synonym_types.py +20 -4
- pyobo/sources/umls/sty.py +57 -0
- pyobo/sources/umls/synonym_types.tsv +1 -1
- pyobo/sources/umls/umls.py +18 -22
- pyobo/sources/unimod.py +46 -0
- pyobo/sources/uniprot/__init__.py +1 -1
- pyobo/sources/uniprot/uniprot.py +40 -32
- pyobo/sources/uniprot/uniprot_ptm.py +4 -34
- pyobo/sources/utils.py +3 -2
- pyobo/sources/wikipathways.py +7 -10
- pyobo/sources/zfin.py +5 -10
- pyobo/ssg/__init__.py +12 -16
- pyobo/ssg/base.html +0 -0
- pyobo/ssg/index.html +26 -13
- pyobo/ssg/term.html +12 -2
- pyobo/ssg/typedef.html +0 -0
- pyobo/struct/__init__.py +54 -8
- pyobo/struct/functional/__init__.py +1 -0
- pyobo/struct/functional/dsl.py +2572 -0
- pyobo/struct/functional/macros.py +423 -0
- pyobo/struct/functional/obo_to_functional.py +385 -0
- pyobo/struct/functional/ontology.py +270 -0
- pyobo/struct/functional/utils.py +112 -0
- pyobo/struct/reference.py +331 -136
- pyobo/struct/struct.py +1413 -643
- pyobo/struct/struct_utils.py +1078 -0
- pyobo/struct/typedef.py +162 -210
- pyobo/struct/utils.py +12 -5
- pyobo/struct/vocabulary.py +138 -0
- pyobo/utils/__init__.py +0 -0
- pyobo/utils/cache.py +13 -11
- pyobo/utils/io.py +17 -31
- pyobo/utils/iter.py +5 -5
- pyobo/utils/misc.py +41 -53
- pyobo/utils/ndex_utils.py +0 -0
- pyobo/utils/path.py +76 -70
- pyobo/version.py +3 -3
- {pyobo-0.11.2.dist-info → pyobo-0.12.0.dist-info}/METADATA +228 -229
- pyobo-0.12.0.dist-info/RECORD +202 -0
- pyobo-0.12.0.dist-info/WHEEL +4 -0
- {pyobo-0.11.2.dist-info → pyobo-0.12.0.dist-info}/entry_points.txt +1 -0
- pyobo-0.12.0.dist-info/licenses/LICENSE +21 -0
- pyobo/aws.py +0 -162
- pyobo/cli/aws.py +0 -47
- pyobo/identifier_utils.py +0 -142
- pyobo/normalizer.py +0 -232
- pyobo/registries/__init__.py +0 -16
- pyobo/registries/metaregistry.json +0 -507
- pyobo/registries/metaregistry.py +0 -135
- pyobo/sources/icd11.py +0 -105
- pyobo/xrefdb/__init__.py +0 -1
- pyobo/xrefdb/canonicalizer.py +0 -214
- pyobo/xrefdb/priority.py +0 -59
- pyobo/xrefdb/sources/__init__.py +0 -60
- pyobo/xrefdb/sources/biomappings.py +0 -36
- pyobo/xrefdb/sources/cbms2019.py +0 -91
- pyobo/xrefdb/sources/chembl.py +0 -83
- pyobo/xrefdb/sources/compath.py +0 -82
- pyobo/xrefdb/sources/famplex.py +0 -64
- pyobo/xrefdb/sources/gilda.py +0 -50
- pyobo/xrefdb/sources/intact.py +0 -113
- pyobo/xrefdb/sources/ncit.py +0 -133
- pyobo/xrefdb/sources/pubchem.py +0 -27
- pyobo/xrefdb/sources/wikidata.py +0 -116
- pyobo-0.11.2.dist-info/RECORD +0 -157
- pyobo-0.11.2.dist-info/WHEEL +0 -5
- pyobo-0.11.2.dist-info/top_level.txt +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"identifier": "backwardCompatibleWith",
|
|
4
|
+
"label": "backwardCompatibleWith",
|
|
5
|
+
"prefix": "owl"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"identifier": "bottomDataProperty",
|
|
9
|
+
"label": "bottomDataProperty",
|
|
10
|
+
"prefix": "owl"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"identifier": "bottomObjectProperty",
|
|
14
|
+
"label": "bottomObjectProperty",
|
|
15
|
+
"prefix": "owl"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"identifier": "deprecated",
|
|
19
|
+
"label": "deprecated",
|
|
20
|
+
"prefix": "owl"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"identifier": "imports",
|
|
24
|
+
"label": "imports",
|
|
25
|
+
"prefix": "owl"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"identifier": "incompatibleWith",
|
|
29
|
+
"label": "incompatibleWith",
|
|
30
|
+
"prefix": "owl"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"identifier": "priorVersion",
|
|
34
|
+
"label": "priorVersion",
|
|
35
|
+
"prefix": "owl"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"identifier": "topDataProperty",
|
|
39
|
+
"label": "topDataProperty",
|
|
40
|
+
"prefix": "owl"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"identifier": "topObjectProperty",
|
|
44
|
+
"label": "topObjectProperty",
|
|
45
|
+
"prefix": "owl"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"identifier": "versionIRI",
|
|
49
|
+
"label": "versionIRI",
|
|
50
|
+
"prefix": "owl"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"identifier": "versionInfo",
|
|
54
|
+
"label": "versionInfo",
|
|
55
|
+
"prefix": "owl"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
pyobo/mocks.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"""Mocks for PyOBO."""
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
from collections.abc import Mapping
|
|
4
|
-
from typing import
|
|
6
|
+
from typing import TypeVar
|
|
5
7
|
from unittest import mock
|
|
6
8
|
|
|
7
9
|
import pandas as pd
|
|
@@ -9,10 +11,10 @@ import pandas as pd
|
|
|
9
11
|
from pyobo.constants import XREF_COLUMNS
|
|
10
12
|
|
|
11
13
|
__all__ = [
|
|
12
|
-
"get_mock_id_name_mapping",
|
|
13
|
-
"get_mock_id_synonyms_mapping",
|
|
14
14
|
"get_mock_get_xrefs_df",
|
|
15
15
|
"get_mock_id_alts_mapping",
|
|
16
|
+
"get_mock_id_name_mapping",
|
|
17
|
+
"get_mock_id_synonyms_mapping",
|
|
16
18
|
]
|
|
17
19
|
|
|
18
20
|
|
|
@@ -35,7 +37,8 @@ def get_mock_id_synonyms_mapping(data: Mapping[str, Mapping[str, list[str]]]) ->
|
|
|
35
37
|
def get_mock_id_alts_mapping(data: Mapping[str, Mapping[str, list[str]]]) -> mock._patch:
|
|
36
38
|
"""Mock the :func:`pyobo.extract.get_id_to_alts` function.
|
|
37
39
|
|
|
38
|
-
:param data: A mapping from prefix to mappings of identifier to lists of alternative
|
|
40
|
+
:param data: A mapping from prefix to mappings of identifier to lists of alternative
|
|
41
|
+
identifiers.
|
|
39
42
|
"""
|
|
40
43
|
return _replace_mapping_getter("pyobo.api.alts.get_id_to_alts", data)
|
|
41
44
|
|
|
@@ -51,7 +54,7 @@ def _replace_mapping_getter(name: str, data: Mapping[str, Mapping[str, X]]) -> m
|
|
|
51
54
|
|
|
52
55
|
|
|
53
56
|
def get_mock_get_xrefs_df(
|
|
54
|
-
df:
|
|
57
|
+
df: list[tuple[str, str, str, str, str]] | pd.DataFrame,
|
|
55
58
|
) -> mock._patch:
|
|
56
59
|
"""Mock the :func:`pyobo.xrefsdb.xrefs_pipeline.get_xref_df` function.
|
|
57
60
|
|
|
@@ -69,7 +72,7 @@ def get_mock_get_xrefs_df(
|
|
|
69
72
|
|
|
70
73
|
|
|
71
74
|
def _make_mock_get_name(name: str, data: Mapping[str, Mapping[str, X]]) -> mock._patch:
|
|
72
|
-
def _get_name(prefix: str, identifier: str) ->
|
|
75
|
+
def _get_name(prefix: str, identifier: str) -> X | None:
|
|
73
76
|
return data.get(prefix, {}).get(identifier)
|
|
74
77
|
|
|
75
78
|
return mock.patch(name, side_effect=_get_name)
|
pyobo/ner/__init__.py
ADDED
pyobo/ner/api.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""NER functionality."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from subprocess import CalledProcessError
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
import ssslm
|
|
10
|
+
from ssslm import LiteralMapping
|
|
11
|
+
from tqdm import tqdm
|
|
12
|
+
from typing_extensions import Unpack
|
|
13
|
+
|
|
14
|
+
from pyobo.api import get_literal_mappings
|
|
15
|
+
from pyobo.constants import GetOntologyKwargs, check_should_use_tqdm
|
|
16
|
+
from pyobo.getters import NoBuildError
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
import gilda
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"get_grounder",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_grounder(
|
|
27
|
+
prefixes: str | Iterable[str],
|
|
28
|
+
*,
|
|
29
|
+
grounder_cls: type[gilda.Grounder] | None = None,
|
|
30
|
+
versions: None | str | Iterable[str | None] | dict[str, str] = None,
|
|
31
|
+
skip_obsolete: bool = False,
|
|
32
|
+
**kwargs: Unpack[GetOntologyKwargs],
|
|
33
|
+
) -> ssslm.Grounder:
|
|
34
|
+
"""Get a grounder for the given prefix(es)."""
|
|
35
|
+
literal_mappings: list[LiteralMapping] = []
|
|
36
|
+
it = _clean_prefix_versions(prefixes, versions=versions)
|
|
37
|
+
disable = len(it) == 1 or not check_should_use_tqdm(kwargs)
|
|
38
|
+
for prefix, kwargs["version"] in tqdm(it, leave=False, disable=disable):
|
|
39
|
+
try:
|
|
40
|
+
literal_mappings.extend(
|
|
41
|
+
get_literal_mappings(
|
|
42
|
+
prefix,
|
|
43
|
+
skip_obsolete=skip_obsolete,
|
|
44
|
+
**kwargs,
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
except (NoBuildError, CalledProcessError):
|
|
48
|
+
continue
|
|
49
|
+
|
|
50
|
+
return ssslm.make_grounder(literal_mappings, implementation="gilda", grounder_cls=grounder_cls)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _clean_prefix_versions(
|
|
54
|
+
prefixes: str | Iterable[str],
|
|
55
|
+
versions: None | str | Iterable[str | None] | dict[str, str] = None,
|
|
56
|
+
) -> list[tuple[str, str | None]]:
|
|
57
|
+
if isinstance(prefixes, str):
|
|
58
|
+
prefixes = [prefixes]
|
|
59
|
+
else:
|
|
60
|
+
prefixes = list(prefixes)
|
|
61
|
+
if versions is None:
|
|
62
|
+
versions = [None] * len(prefixes)
|
|
63
|
+
elif isinstance(versions, str):
|
|
64
|
+
versions = [versions]
|
|
65
|
+
elif isinstance(versions, dict):
|
|
66
|
+
versions = [versions.get(prefix) for prefix in prefixes]
|
|
67
|
+
else:
|
|
68
|
+
versions = list(versions)
|
|
69
|
+
if len(prefixes) != len(versions):
|
|
70
|
+
raise ValueError
|
|
71
|
+
|
|
72
|
+
return list(zip(prefixes, versions, strict=True))
|
pyobo/ner/normalizer.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Use synonyms from OBO to normalize names."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
|
|
7
|
+
from typing_extensions import Unpack
|
|
8
|
+
|
|
9
|
+
from .api import get_grounder
|
|
10
|
+
from ..constants import GetOntologyKwargs
|
|
11
|
+
from ..struct import Reference
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"ground",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def ground(
|
|
19
|
+
prefix: str | Iterable[str], query: str, **kwargs: Unpack[GetOntologyKwargs]
|
|
20
|
+
) -> Reference | None:
|
|
21
|
+
"""Normalize a string given the prefix's labels and synonyms.
|
|
22
|
+
|
|
23
|
+
:param prefix: If a string, only grounds against that namespace. If a list, will try grounding
|
|
24
|
+
against all in that order
|
|
25
|
+
:param query: The string to try grounding
|
|
26
|
+
"""
|
|
27
|
+
grounder = get_grounder(prefix, **kwargs)
|
|
28
|
+
match = grounder.get_best_match(query)
|
|
29
|
+
if match:
|
|
30
|
+
# TODO when generics are working, the grounder
|
|
31
|
+
# can be type annotated with the right reference
|
|
32
|
+
return Reference.from_reference(match.reference)
|
|
33
|
+
return None
|
pyobo/obographs.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"""Convert PyOBO into OBO Graph."""
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
3
6
|
from collections.abc import Iterable
|
|
4
7
|
|
|
5
8
|
import bioregistry
|
|
6
|
-
import curies
|
|
7
9
|
from bioontologies.obograph import (
|
|
8
|
-
OBO_SYNONYM_TO_OIO,
|
|
9
|
-
OIO_TO_REFERENCE,
|
|
10
10
|
Definition,
|
|
11
11
|
Edge,
|
|
12
12
|
Graph,
|
|
@@ -19,7 +19,7 @@ from bioontologies.obograph import (
|
|
|
19
19
|
from bioontologies.robot import ParseResults
|
|
20
20
|
from tqdm import tqdm
|
|
21
21
|
|
|
22
|
-
from pyobo.struct import Obo, Reference, Term
|
|
22
|
+
from pyobo.struct import Obo, OBOLiteral, Reference, Term
|
|
23
23
|
from pyobo.struct.typedef import definition_source, is_a
|
|
24
24
|
|
|
25
25
|
__all__ = [
|
|
@@ -27,6 +27,8 @@ __all__ = [
|
|
|
27
27
|
"parse_results_from_obo",
|
|
28
28
|
]
|
|
29
29
|
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
30
32
|
|
|
31
33
|
def parse_results_from_obo(obo: Obo) -> ParseResults:
|
|
32
34
|
"""Get parse results from an OBO graph."""
|
|
@@ -59,40 +61,28 @@ def _get_meta(obo: Obo) -> Meta:
|
|
|
59
61
|
)
|
|
60
62
|
|
|
61
63
|
|
|
62
|
-
def _rewire(r: Reference) -> curies.Reference:
|
|
63
|
-
return curies.Reference(prefix=r.prefix, identifier=r.identifier)
|
|
64
|
-
|
|
65
|
-
|
|
66
64
|
def _get_class_node(term: Term) -> Node:
|
|
67
|
-
if term.
|
|
65
|
+
if term.provenance or term.definition:
|
|
68
66
|
definition = Definition.from_parsed(
|
|
69
|
-
value=term.definition, references=
|
|
67
|
+
value=term.definition, references=_prep_prov(term.provenance)
|
|
70
68
|
)
|
|
71
69
|
else:
|
|
72
70
|
definition = None
|
|
73
|
-
|
|
74
|
-
if term.xrefs:
|
|
75
|
-
if not term.xref_types:
|
|
76
|
-
term.xref_types = [
|
|
77
|
-
Reference(prefix="oboInOwl", identifier="hasDbXref") for _ in term.xrefs
|
|
78
|
-
]
|
|
79
|
-
elif len(term.xrefs) != len(term.xref_types):
|
|
80
|
-
raise ValueError
|
|
81
|
-
|
|
82
71
|
xrefs = [
|
|
83
72
|
Xref.from_parsed(
|
|
84
|
-
predicate=
|
|
85
|
-
value=
|
|
73
|
+
predicate=Reference.from_reference(mapping_predicate),
|
|
74
|
+
value=Reference.from_reference(mapping_object),
|
|
75
|
+
)
|
|
76
|
+
for mapping_predicate, mapping_object in term.get_mappings(
|
|
77
|
+
include_xrefs=True, add_context=False
|
|
86
78
|
)
|
|
87
|
-
for xref, xref_type in zip(term.xrefs, term.xref_types)
|
|
88
79
|
]
|
|
89
|
-
default_st = Reference(prefix="oboInOwl", identifier="SynonymType")
|
|
90
80
|
synonyms = [
|
|
91
81
|
Synonym.from_parsed(
|
|
92
82
|
name=synonym.name,
|
|
93
|
-
predicate=
|
|
94
|
-
synonym_type=
|
|
95
|
-
references=
|
|
83
|
+
predicate=Reference.from_reference(synonym.predicate),
|
|
84
|
+
synonym_type=Reference.from_reference(synonym.type) if synonym.type else None,
|
|
85
|
+
references=_prep_prov(synonym.provenance),
|
|
96
86
|
)
|
|
97
87
|
for synonym in term.synonyms
|
|
98
88
|
]
|
|
@@ -105,35 +95,49 @@ def _get_class_node(term: Term) -> Node:
|
|
|
105
95
|
deprecated=term.is_obsolete or False,
|
|
106
96
|
)
|
|
107
97
|
return Node(
|
|
108
|
-
|
|
98
|
+
# FIXME do expansion same as for OFN
|
|
99
|
+
id=f"https://bioregistry.io/{term.curie}",
|
|
109
100
|
lbl=term.name,
|
|
110
101
|
meta=meta,
|
|
111
102
|
type="CLASS",
|
|
112
|
-
reference=
|
|
103
|
+
reference=Reference.from_reference(term.reference),
|
|
113
104
|
standardized=True,
|
|
114
105
|
)
|
|
115
106
|
|
|
116
107
|
|
|
108
|
+
def _prep_prov(provenance):
|
|
109
|
+
rv = []
|
|
110
|
+
for x in provenance:
|
|
111
|
+
match x:
|
|
112
|
+
case Reference():
|
|
113
|
+
rv.append(Reference.from_reference(x))
|
|
114
|
+
case OBOLiteral():
|
|
115
|
+
logger.debug("not implemented to convert literal provenance")
|
|
116
|
+
continue
|
|
117
|
+
return rv
|
|
118
|
+
|
|
119
|
+
|
|
117
120
|
def _iter_edges(term: Term) -> Iterable[Edge]:
|
|
118
121
|
for parent in term.parents:
|
|
119
122
|
yield Edge.from_parsed(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
Reference.from_reference(term.reference),
|
|
124
|
+
Reference.from_reference(is_a.reference),
|
|
125
|
+
Reference.from_reference(parent),
|
|
123
126
|
)
|
|
124
127
|
|
|
125
128
|
for typedef, targets in term.relationships.items():
|
|
126
129
|
for target in targets:
|
|
127
130
|
yield Edge.from_parsed(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
Reference.from_reference(term.reference),
|
|
132
|
+
Reference.from_reference(typedef),
|
|
133
|
+
Reference.from_reference(target),
|
|
131
134
|
)
|
|
132
135
|
|
|
133
136
|
for provenance_reference in term.provenance:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
if isinstance(provenance_reference, Reference):
|
|
138
|
+
yield Edge.from_parsed(
|
|
139
|
+
Reference.from_reference(term.reference),
|
|
140
|
+
Reference.from_reference(definition_source.reference),
|
|
141
|
+
Reference.from_reference(provenance_reference),
|
|
142
|
+
)
|
|
139
143
|
# TODO also look through xrefs and seealso to get provenance xrefs?
|
pyobo/plugins.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"""Tools for loading entry points."""
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Iterable, Mapping
|
|
4
6
|
from functools import lru_cache
|
|
5
|
-
from typing import Callable, Optional
|
|
6
7
|
|
|
7
8
|
from .struct import Obo
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
10
11
|
"has_nomenclature_plugin",
|
|
11
|
-
"run_nomenclature_plugin",
|
|
12
12
|
"iter_nomenclature_plugins",
|
|
13
|
+
"run_nomenclature_plugin",
|
|
13
14
|
]
|
|
14
15
|
|
|
15
16
|
|
|
@@ -32,7 +33,7 @@ def has_nomenclature_plugin(prefix: str) -> bool:
|
|
|
32
33
|
return True
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
def run_nomenclature_plugin(prefix: str, version:
|
|
36
|
+
def run_nomenclature_plugin(prefix: str, version: str | None = None) -> Obo:
|
|
36
37
|
"""Get a converted PyOBO source."""
|
|
37
38
|
from .sources import ontology_resolver
|
|
38
39
|
|
pyobo/py.typed
CHANGED
|
File without changes
|