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/__init__.py
CHANGED
pyobo/__main__.py
CHANGED
pyobo/api/__init__.py
CHANGED
pyobo/api/alts.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for alternative identifiers."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
4
|
+
from collections.abc import Mapping
|
|
6
5
|
from functools import lru_cache
|
|
7
|
-
from typing import
|
|
6
|
+
from typing import Optional
|
|
8
7
|
|
|
9
8
|
from .utils import get_version
|
|
10
9
|
from ..getters import get_ontology
|
|
@@ -26,11 +25,11 @@ NO_ALTS = {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
@lru_cache
|
|
28
|
+
@lru_cache
|
|
30
29
|
@wrap_norm_prefix
|
|
31
30
|
def get_id_to_alts(
|
|
32
31
|
prefix: str, *, force: bool = False, version: Optional[str] = None
|
|
33
|
-
) -> Mapping[str,
|
|
32
|
+
) -> Mapping[str, list[str]]:
|
|
34
33
|
"""Get alternate identifiers."""
|
|
35
34
|
if prefix in NO_ALTS:
|
|
36
35
|
return {}
|
|
@@ -41,7 +40,7 @@ def get_id_to_alts(
|
|
|
41
40
|
header = [f"{prefix}_id", "alt_id"]
|
|
42
41
|
|
|
43
42
|
@cached_multidict(path=path, header=header, force=force)
|
|
44
|
-
def _get_mapping() -> Mapping[str,
|
|
43
|
+
def _get_mapping() -> Mapping[str, list[str]]:
|
|
45
44
|
if force:
|
|
46
45
|
logger.info(f"[{prefix}] forcing reload for alts")
|
|
47
46
|
else:
|
|
@@ -52,7 +51,7 @@ def get_id_to_alts(
|
|
|
52
51
|
return _get_mapping()
|
|
53
52
|
|
|
54
53
|
|
|
55
|
-
@lru_cache
|
|
54
|
+
@lru_cache
|
|
56
55
|
@wrap_norm_prefix
|
|
57
56
|
def get_alts_to_id(
|
|
58
57
|
prefix: str, *, force: bool = False, version: Optional[str] = None
|
pyobo/api/hierarchy.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for hierarchies."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
4
|
+
from collections.abc import Iterable
|
|
6
5
|
from functools import lru_cache
|
|
7
|
-
from typing import
|
|
6
|
+
from typing import Optional
|
|
8
7
|
|
|
9
8
|
import networkx as nx
|
|
10
9
|
|
|
@@ -70,13 +69,13 @@ def get_hierarchy(
|
|
|
70
69
|
)
|
|
71
70
|
|
|
72
71
|
|
|
73
|
-
@lru_cache
|
|
72
|
+
@lru_cache
|
|
74
73
|
@wrap_norm_prefix
|
|
75
74
|
def _get_hierarchy_helper(
|
|
76
75
|
prefix: str,
|
|
77
76
|
*,
|
|
78
|
-
extra_relations:
|
|
79
|
-
properties:
|
|
77
|
+
extra_relations: tuple[TypeDef, ...],
|
|
78
|
+
properties: tuple[str, ...],
|
|
80
79
|
include_part_of: bool,
|
|
81
80
|
include_has_member: bool,
|
|
82
81
|
use_tqdm: bool,
|
|
@@ -161,13 +160,13 @@ def is_descendent(
|
|
|
161
160
|
|
|
162
161
|
Check that go:0070246 ! natural killer cell apoptotic process is a
|
|
163
162
|
descendant of go:0006915 ! apoptotic process::
|
|
164
|
-
>>> assert is_descendent(
|
|
163
|
+
>>> assert is_descendent("go", "0070246", "go", "0006915")
|
|
165
164
|
"""
|
|
166
165
|
descendants = get_descendants(ancestor_prefix, ancestor_identifier, version=version)
|
|
167
166
|
return descendants is not None and f"{prefix}:{identifier}" in descendants
|
|
168
167
|
|
|
169
168
|
|
|
170
|
-
@lru_cache
|
|
169
|
+
@lru_cache
|
|
171
170
|
def get_descendants(
|
|
172
171
|
prefix: str,
|
|
173
172
|
identifier: Optional[str] = None,
|
|
@@ -176,7 +175,7 @@ def get_descendants(
|
|
|
176
175
|
use_tqdm: bool = False,
|
|
177
176
|
force: bool = False,
|
|
178
177
|
**kwargs,
|
|
179
|
-
) -> Optional[
|
|
178
|
+
) -> Optional[set[str]]:
|
|
180
179
|
"""Get all the descendants (children) of the term as CURIEs."""
|
|
181
180
|
curie, prefix, identifier = _pic(prefix, identifier)
|
|
182
181
|
hierarchy = get_hierarchy(
|
|
@@ -192,7 +191,7 @@ def get_descendants(
|
|
|
192
191
|
return nx.ancestors(hierarchy, curie) # note this is backwards
|
|
193
192
|
|
|
194
193
|
|
|
195
|
-
def _pic(prefix, identifier=None) ->
|
|
194
|
+
def _pic(prefix, identifier=None) -> tuple[str, str, str]:
|
|
196
195
|
if identifier is None:
|
|
197
196
|
curie = prefix
|
|
198
197
|
prefix, identifier = prefix.split(":")
|
|
@@ -201,7 +200,7 @@ def _pic(prefix, identifier=None) -> Tuple[str, str, str]:
|
|
|
201
200
|
return curie, prefix, identifier
|
|
202
201
|
|
|
203
202
|
|
|
204
|
-
@lru_cache
|
|
203
|
+
@lru_cache
|
|
205
204
|
def get_children(
|
|
206
205
|
prefix: str,
|
|
207
206
|
identifier: Optional[str] = None,
|
|
@@ -210,7 +209,7 @@ def get_children(
|
|
|
210
209
|
use_tqdm: bool = False,
|
|
211
210
|
force: bool = False,
|
|
212
211
|
**kwargs,
|
|
213
|
-
) -> Optional[
|
|
212
|
+
) -> Optional[set[str]]:
|
|
214
213
|
"""Get all the descendants (children) of the term as CURIEs."""
|
|
215
214
|
curie, prefix, identifier = _pic(prefix, identifier)
|
|
216
215
|
hierarchy = get_hierarchy(
|
|
@@ -232,13 +231,13 @@ def has_ancestor(
|
|
|
232
231
|
"""Check that the first identifier has the second as an ancestor.
|
|
233
232
|
|
|
234
233
|
Check that go:0008219 ! cell death is an ancestor of go:0006915 ! apoptotic process::
|
|
235
|
-
>>> assert has_ancestor(
|
|
234
|
+
>>> assert has_ancestor("go", "0006915", "go", "0008219")
|
|
236
235
|
"""
|
|
237
236
|
ancestors = get_ancestors(prefix, identifier, version=version)
|
|
238
237
|
return ancestors is not None and f"{ancestor_prefix}:{ancestor_identifier}" in ancestors
|
|
239
238
|
|
|
240
239
|
|
|
241
|
-
@lru_cache
|
|
240
|
+
@lru_cache
|
|
242
241
|
def get_ancestors(
|
|
243
242
|
prefix: str,
|
|
244
243
|
identifier: Optional[str] = None,
|
|
@@ -247,7 +246,7 @@ def get_ancestors(
|
|
|
247
246
|
use_tqdm: bool = False,
|
|
248
247
|
force: bool = False,
|
|
249
248
|
**kwargs,
|
|
250
|
-
) -> Optional[
|
|
249
|
+
) -> Optional[set[str]]:
|
|
251
250
|
"""Get all the ancestors (parents) of the term as CURIEs."""
|
|
252
251
|
curie, prefix, identifier = _pic(prefix, identifier)
|
|
253
252
|
hierarchy = get_hierarchy(
|
pyobo/api/metadata.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for metadata."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
4
|
+
from collections.abc import Mapping
|
|
6
5
|
from functools import lru_cache
|
|
7
|
-
from typing import
|
|
6
|
+
from typing import Optional
|
|
8
7
|
|
|
9
8
|
from .utils import get_version
|
|
10
9
|
from ..getters import get_ontology
|
|
@@ -19,7 +18,7 @@ __all__ = [
|
|
|
19
18
|
logger = logging.getLogger(__name__)
|
|
20
19
|
|
|
21
20
|
|
|
22
|
-
@lru_cache
|
|
21
|
+
@lru_cache
|
|
23
22
|
@wrap_norm_prefix
|
|
24
23
|
def get_metadata(
|
|
25
24
|
prefix: str, *, force: bool = False, version: Optional[str] = None
|
pyobo/api/names.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for nomenclature."""
|
|
4
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
5
|
import logging
|
|
6
6
|
import subprocess
|
|
7
|
+
from collections.abc import Mapping
|
|
7
8
|
from functools import lru_cache
|
|
8
|
-
from typing import Callable,
|
|
9
|
+
from typing import Callable, TypeVar
|
|
10
|
+
|
|
11
|
+
from curies import Reference, ReferenceTuple
|
|
9
12
|
|
|
10
13
|
from .alts import get_primary_identifier
|
|
11
14
|
from .utils import get_version
|
|
12
|
-
from ..getters import
|
|
15
|
+
from ..getters import NoBuildError, get_ontology
|
|
13
16
|
from ..identifier_utils import normalize_curie, wrap_norm_prefix
|
|
14
17
|
from ..utils.cache import cached_collection, cached_mapping, cached_multidict
|
|
15
18
|
from ..utils.path import prefix_cache_join
|
|
@@ -30,8 +33,10 @@ __all__ = [
|
|
|
30
33
|
logger = logging.getLogger(__name__)
|
|
31
34
|
|
|
32
35
|
|
|
33
|
-
def get_name_by_curie(curie: str, *, version:
|
|
36
|
+
def get_name_by_curie(curie: str, *, version: str | None = None) -> str | None:
|
|
34
37
|
"""Get the name for a CURIE, if possible."""
|
|
38
|
+
if version is None:
|
|
39
|
+
version = get_version(curie.split(":")[0])
|
|
35
40
|
prefix, identifier = normalize_curie(curie)
|
|
36
41
|
if prefix and identifier:
|
|
37
42
|
return get_name(prefix, identifier, version=version)
|
|
@@ -40,7 +45,8 @@ def get_name_by_curie(curie: str, *, version: Optional[str] = None) -> Optional[
|
|
|
40
45
|
|
|
41
46
|
X = TypeVar("X")
|
|
42
47
|
|
|
43
|
-
NO_BUILD_PREFIXES = set()
|
|
48
|
+
NO_BUILD_PREFIXES: set[str] = set()
|
|
49
|
+
NO_BUILD_LOGGED: set = set()
|
|
44
50
|
|
|
45
51
|
|
|
46
52
|
def _help_get(
|
|
@@ -49,18 +55,20 @@ def _help_get(
|
|
|
49
55
|
identifier: str,
|
|
50
56
|
force: bool = False,
|
|
51
57
|
strict: bool = False,
|
|
52
|
-
version:
|
|
53
|
-
) ->
|
|
58
|
+
version: str | None = None,
|
|
59
|
+
) -> X | None:
|
|
54
60
|
"""Get the result for an entity based on a mapping maker function ``f``."""
|
|
55
61
|
try:
|
|
56
62
|
mapping = f(prefix, force=force, strict=strict, version=version) # type:ignore
|
|
57
|
-
except
|
|
63
|
+
except NoBuildError:
|
|
58
64
|
if prefix not in NO_BUILD_PREFIXES:
|
|
59
65
|
logger.warning("[%s] unable to look up results with %s", prefix, f)
|
|
60
66
|
NO_BUILD_PREFIXES.add(prefix)
|
|
61
67
|
return None
|
|
62
|
-
except ValueError:
|
|
63
|
-
|
|
68
|
+
except ValueError as e:
|
|
69
|
+
if prefix not in NO_BUILD_PREFIXES:
|
|
70
|
+
logger.warning("[%s] value error while looking up results with %s: %s", prefix, f, e)
|
|
71
|
+
NO_BUILD_PREFIXES.add(prefix)
|
|
64
72
|
return None
|
|
65
73
|
|
|
66
74
|
if not mapping:
|
|
@@ -74,16 +82,24 @@ def _help_get(
|
|
|
74
82
|
|
|
75
83
|
|
|
76
84
|
@wrap_norm_prefix
|
|
77
|
-
def get_name(
|
|
85
|
+
def get_name(
|
|
86
|
+
prefix: str | Reference | ReferenceTuple,
|
|
87
|
+
identifier: str | None = None,
|
|
88
|
+
/,
|
|
89
|
+
*,
|
|
90
|
+
version: str | None = None,
|
|
91
|
+
) -> str | None:
|
|
78
92
|
"""Get the name for an entity."""
|
|
79
|
-
|
|
93
|
+
if isinstance(prefix, (ReferenceTuple, Reference)):
|
|
94
|
+
prefix, identifier = prefix.prefix, prefix.identifier
|
|
95
|
+
return _help_get(get_id_name_mapping, prefix, identifier, version=version) # type:ignore
|
|
80
96
|
|
|
81
97
|
|
|
82
|
-
@lru_cache
|
|
98
|
+
@lru_cache
|
|
83
99
|
@wrap_norm_prefix
|
|
84
100
|
def get_ids(
|
|
85
|
-
prefix: str, *, force: bool = False, strict: bool = False, version:
|
|
86
|
-
) ->
|
|
101
|
+
prefix: str, *, force: bool = False, strict: bool = False, version: str | None = None
|
|
102
|
+
) -> set[str]:
|
|
87
103
|
"""Get the set of identifiers for this prefix."""
|
|
88
104
|
if prefix == "ncbigene":
|
|
89
105
|
from ..sources.ncbigene import get_ncbigene_ids
|
|
@@ -98,7 +114,7 @@ def get_ids(
|
|
|
98
114
|
path = prefix_cache_join(prefix, name="ids.tsv", version=version)
|
|
99
115
|
|
|
100
116
|
@cached_collection(path=path, force=force)
|
|
101
|
-
def _get_ids() ->
|
|
117
|
+
def _get_ids() -> set[str]:
|
|
102
118
|
if force:
|
|
103
119
|
logger.info("[%s v%s] forcing reload for names", prefix, version)
|
|
104
120
|
else:
|
|
@@ -111,10 +127,10 @@ def get_ids(
|
|
|
111
127
|
return set(_get_ids())
|
|
112
128
|
|
|
113
129
|
|
|
114
|
-
@lru_cache
|
|
130
|
+
@lru_cache
|
|
115
131
|
@wrap_norm_prefix
|
|
116
132
|
def get_id_name_mapping(
|
|
117
|
-
prefix: str, *, force: bool = False, strict: bool = False, version:
|
|
133
|
+
prefix: str, *, force: bool = False, strict: bool = False, version: str | None = None
|
|
118
134
|
) -> Mapping[str, str]:
|
|
119
135
|
"""Get an identifier to name mapping for the OBO file."""
|
|
120
136
|
if prefix == "ncbigene":
|
|
@@ -140,7 +156,7 @@ def get_id_name_mapping(
|
|
|
140
156
|
|
|
141
157
|
try:
|
|
142
158
|
return _get_id_name_mapping()
|
|
143
|
-
except
|
|
159
|
+
except NoBuildError:
|
|
144
160
|
logger.debug("[%s] no build", prefix)
|
|
145
161
|
return {}
|
|
146
162
|
except (Exception, subprocess.CalledProcessError) as e:
|
|
@@ -148,10 +164,10 @@ def get_id_name_mapping(
|
|
|
148
164
|
return {}
|
|
149
165
|
|
|
150
166
|
|
|
151
|
-
@lru_cache
|
|
167
|
+
@lru_cache
|
|
152
168
|
@wrap_norm_prefix
|
|
153
169
|
def get_name_id_mapping(
|
|
154
|
-
prefix: str, *, force: bool = False, version:
|
|
170
|
+
prefix: str, *, force: bool = False, version: str | None = None
|
|
155
171
|
) -> Mapping[str, str]:
|
|
156
172
|
"""Get a name to identifier mapping for the OBO file."""
|
|
157
173
|
id_name = get_id_name_mapping(prefix=prefix, force=force, version=version)
|
|
@@ -159,8 +175,12 @@ def get_name_id_mapping(
|
|
|
159
175
|
|
|
160
176
|
|
|
161
177
|
@wrap_norm_prefix
|
|
162
|
-
def get_definition(
|
|
178
|
+
def get_definition(
|
|
179
|
+
prefix: str, identifier: str | None = None, *, version: str | None = None
|
|
180
|
+
) -> str | None:
|
|
163
181
|
"""Get the definition for an entity."""
|
|
182
|
+
if identifier is None:
|
|
183
|
+
prefix, _, identifier = prefix.rpartition(":")
|
|
164
184
|
return _help_get(get_id_definition_mapping, prefix, identifier, version=version)
|
|
165
185
|
|
|
166
186
|
|
|
@@ -169,7 +189,7 @@ def get_id_definition_mapping(
|
|
|
169
189
|
*,
|
|
170
190
|
force: bool = False,
|
|
171
191
|
strict: bool = False,
|
|
172
|
-
version:
|
|
192
|
+
version: str | None = None,
|
|
173
193
|
) -> Mapping[str, str]:
|
|
174
194
|
"""Get a mapping of descriptions."""
|
|
175
195
|
if version is None:
|
|
@@ -192,15 +212,15 @@ def get_obsolete(
|
|
|
192
212
|
*,
|
|
193
213
|
force: bool = False,
|
|
194
214
|
strict: bool = False,
|
|
195
|
-
version:
|
|
196
|
-
) ->
|
|
215
|
+
version: str | None = None,
|
|
216
|
+
) -> set[str]:
|
|
197
217
|
"""Get the set of obsolete local unique identifiers."""
|
|
198
218
|
if version is None:
|
|
199
219
|
version = get_version(prefix)
|
|
200
220
|
path = prefix_cache_join(prefix, name="obsolete.tsv", version=version)
|
|
201
221
|
|
|
202
222
|
@cached_collection(path=path, force=force)
|
|
203
|
-
def _get_obsolete() ->
|
|
223
|
+
def _get_obsolete() -> set[str]:
|
|
204
224
|
ontology = get_ontology(prefix, force=force, strict=strict, version=version)
|
|
205
225
|
return ontology.get_obsolete()
|
|
206
226
|
|
|
@@ -208,7 +228,7 @@ def get_obsolete(
|
|
|
208
228
|
|
|
209
229
|
|
|
210
230
|
@wrap_norm_prefix
|
|
211
|
-
def get_synonyms(prefix: str, identifier: str) ->
|
|
231
|
+
def get_synonyms(prefix: str, identifier: str) -> list[str] | None:
|
|
212
232
|
"""Get the synonyms for an entity."""
|
|
213
233
|
return _help_get(get_id_synonyms_mapping, prefix, identifier)
|
|
214
234
|
|
|
@@ -219,15 +239,15 @@ def get_id_synonyms_mapping(
|
|
|
219
239
|
*,
|
|
220
240
|
force: bool = False,
|
|
221
241
|
strict: bool = False,
|
|
222
|
-
version:
|
|
223
|
-
) -> Mapping[str,
|
|
242
|
+
version: str | None = None,
|
|
243
|
+
) -> Mapping[str, list[str]]:
|
|
224
244
|
"""Get the OBO file and output a synonym dictionary."""
|
|
225
245
|
if version is None:
|
|
226
246
|
version = get_version(prefix)
|
|
227
247
|
path = prefix_cache_join(prefix, name="synonyms.tsv", version=version)
|
|
228
248
|
|
|
229
249
|
@cached_multidict(path=path, header=[f"{prefix}_id", "synonym"], force=force)
|
|
230
|
-
def _get_multidict() -> Mapping[str,
|
|
250
|
+
def _get_multidict() -> Mapping[str, list[str]]:
|
|
231
251
|
logger.info("[%s v%s] no cached synonyms found. getting from OBO loader", prefix, version)
|
|
232
252
|
ontology = get_ontology(prefix, force=force, strict=strict, version=version)
|
|
233
253
|
return ontology.get_id_synonyms_mapping()
|
pyobo/api/properties.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for properties."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
6
4
|
import os
|
|
7
|
-
from
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import Optional
|
|
8
7
|
|
|
9
8
|
import pandas as pd
|
|
10
9
|
|
|
@@ -105,7 +104,7 @@ def get_filtered_properties_multimapping(
|
|
|
105
104
|
use_tqdm: bool = False,
|
|
106
105
|
force: bool = False,
|
|
107
106
|
version: Optional[str] = None,
|
|
108
|
-
) -> Mapping[str,
|
|
107
|
+
) -> Mapping[str, list[str]]:
|
|
109
108
|
"""Extract multiple properties for each term as a dictionary.
|
|
110
109
|
|
|
111
110
|
:param prefix: the resource to load
|
|
@@ -120,7 +119,7 @@ def get_filtered_properties_multimapping(
|
|
|
120
119
|
all_properties_path = prefix_cache_join(prefix, name="properties.tsv", version=version)
|
|
121
120
|
|
|
122
121
|
@cached_multidict(path=path, header=[f"{prefix}_id", prop], force=force)
|
|
123
|
-
def _mapping_getter() -> Mapping[str,
|
|
122
|
+
def _mapping_getter() -> Mapping[str, list[str]]:
|
|
124
123
|
if os.path.exists(all_properties_path):
|
|
125
124
|
logger.info("[%s] loading pre-cached properties", prefix)
|
|
126
125
|
df = pd.read_csv(all_properties_path, sep="\t")
|
|
@@ -144,7 +143,7 @@ def get_property(prefix: str, identifier: str, prop: str, **kwargs) -> Optional[
|
|
|
144
143
|
:returns: The single value for the property. If multiple are expected, use :func:`get_properties`
|
|
145
144
|
|
|
146
145
|
>>> import pyobo
|
|
147
|
-
>>> pyobo.get_property(
|
|
146
|
+
>>> pyobo.get_property("chebi", "132964", "http://purl.obolibrary.org/obo/chebi/smiles")
|
|
148
147
|
"C1(=CC=C(N=C1)OC2=CC=C(C=C2)O[C@@H](C(OCCCC)=O)C)C(F)(F)F"
|
|
149
148
|
"""
|
|
150
149
|
filtered_properties_mapping = get_filtered_properties_mapping(
|
|
@@ -153,7 +152,7 @@ def get_property(prefix: str, identifier: str, prop: str, **kwargs) -> Optional[
|
|
|
153
152
|
return filtered_properties_mapping.get(identifier)
|
|
154
153
|
|
|
155
154
|
|
|
156
|
-
def get_properties(prefix: str, identifier: str, prop: str, **kwargs) -> Optional[
|
|
155
|
+
def get_properties(prefix: str, identifier: str, prop: str, **kwargs) -> Optional[list[str]]:
|
|
157
156
|
"""Extract a set of properties for the given entity.
|
|
158
157
|
|
|
159
158
|
:param prefix: the resource to load
|
pyobo/api/relations.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for relations."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
6
4
|
import os
|
|
5
|
+
from collections.abc import Mapping
|
|
7
6
|
from functools import lru_cache
|
|
8
|
-
from typing import
|
|
7
|
+
from typing import Optional
|
|
9
8
|
|
|
10
9
|
import networkx as nx
|
|
11
10
|
import pandas as pd
|
|
@@ -121,7 +120,7 @@ def get_id_multirelations_mapping(
|
|
|
121
120
|
use_tqdm: bool = False,
|
|
122
121
|
force: bool = False,
|
|
123
122
|
version: Optional[str] = None,
|
|
124
|
-
) -> Mapping[str,
|
|
123
|
+
) -> Mapping[str, list[Reference]]:
|
|
125
124
|
"""Get the OBO file and output a synonym dictionary."""
|
|
126
125
|
if version is None:
|
|
127
126
|
version = get_version(prefix)
|
|
@@ -129,7 +128,7 @@ def get_id_multirelations_mapping(
|
|
|
129
128
|
return ontology.get_id_multirelations_mapping(typedef=typedef, use_tqdm=use_tqdm)
|
|
130
129
|
|
|
131
130
|
|
|
132
|
-
@lru_cache
|
|
131
|
+
@lru_cache
|
|
133
132
|
@wrap_norm_prefix
|
|
134
133
|
def get_relation_mapping(
|
|
135
134
|
prefix: str,
|
|
@@ -147,9 +146,9 @@ def get_relation_mapping(
|
|
|
147
146
|
Example usage: get homology between HGNC and MGI:
|
|
148
147
|
|
|
149
148
|
>>> import pyobo
|
|
150
|
-
>>> human_mapt_hgnc_id =
|
|
151
|
-
>>> mouse_mapt_mgi_id =
|
|
152
|
-
>>> hgnc_mgi_orthology_mapping = pyobo.get_relation_mapping(
|
|
149
|
+
>>> human_mapt_hgnc_id = "6893"
|
|
150
|
+
>>> mouse_mapt_mgi_id = "97180"
|
|
151
|
+
>>> hgnc_mgi_orthology_mapping = pyobo.get_relation_mapping("hgnc", "ro:HOM0000017", "mgi")
|
|
153
152
|
>>> assert mouse_mapt_mgi_id == hgnc_mgi_orthology_mapping[human_mapt_hgnc_id]
|
|
154
153
|
"""
|
|
155
154
|
if version is None:
|
|
@@ -178,9 +177,11 @@ def get_relation(
|
|
|
178
177
|
Example usage: get homology between MAPT in HGNC and MGI:
|
|
179
178
|
|
|
180
179
|
>>> import pyobo
|
|
181
|
-
>>> human_mapt_hgnc_id =
|
|
182
|
-
>>> mouse_mapt_mgi_id =
|
|
183
|
-
>>> assert mouse_mapt_mgi_id == pyobo.get_relation(
|
|
180
|
+
>>> human_mapt_hgnc_id = "6893"
|
|
181
|
+
>>> mouse_mapt_mgi_id = "97180"
|
|
182
|
+
>>> assert mouse_mapt_mgi_id == pyobo.get_relation(
|
|
183
|
+
... "hgnc", human_mapt_hgnc_id, "ro:HOM0000017", "mgi"
|
|
184
|
+
... )
|
|
184
185
|
"""
|
|
185
186
|
relation_mapping = get_relation_mapping(
|
|
186
187
|
prefix=prefix,
|
pyobo/api/species.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for species."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
4
|
+
from collections.abc import Mapping
|
|
6
5
|
from functools import lru_cache
|
|
7
|
-
from typing import
|
|
6
|
+
from typing import Optional
|
|
8
7
|
|
|
9
8
|
from .alts import get_primary_identifier
|
|
10
9
|
from .utils import get_version
|
|
11
|
-
from ..getters import
|
|
10
|
+
from ..getters import NoBuildError, get_ontology
|
|
12
11
|
from ..identifier_utils import wrap_norm_prefix
|
|
13
12
|
from ..utils.cache import cached_mapping
|
|
14
13
|
from ..utils.path import prefix_cache_join
|
|
@@ -29,7 +28,7 @@ def get_species(prefix: str, identifier: str, *, version: Optional[str] = None)
|
|
|
29
28
|
|
|
30
29
|
try:
|
|
31
30
|
id_species = get_id_species_mapping(prefix, version=version)
|
|
32
|
-
except
|
|
31
|
+
except NoBuildError:
|
|
33
32
|
logger.warning("unable to look up species for prefix %s", prefix)
|
|
34
33
|
return None
|
|
35
34
|
|
|
@@ -41,7 +40,7 @@ def get_species(prefix: str, identifier: str, *, version: Optional[str] = None)
|
|
|
41
40
|
return id_species.get(primary_id)
|
|
42
41
|
|
|
43
42
|
|
|
44
|
-
@lru_cache
|
|
43
|
+
@lru_cache
|
|
45
44
|
@wrap_norm_prefix
|
|
46
45
|
def get_id_species_mapping(
|
|
47
46
|
prefix: str,
|
pyobo/api/typedefs.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""High-level API for typedefs."""
|
|
4
2
|
|
|
5
3
|
import logging
|
|
@@ -21,7 +19,7 @@ __all__ = [
|
|
|
21
19
|
logger = logging.getLogger(__name__)
|
|
22
20
|
|
|
23
21
|
|
|
24
|
-
@lru_cache
|
|
22
|
+
@lru_cache
|
|
25
23
|
@wrap_norm_prefix
|
|
26
24
|
def get_typedef_df(
|
|
27
25
|
prefix: str, *, force: bool = False, version: Optional[str] = None
|
pyobo/api/utils.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
"""Utilities for high-level API."""
|
|
4
2
|
|
|
5
3
|
import json
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
from functools import lru_cache
|
|
6
7
|
from typing import Optional
|
|
7
8
|
|
|
8
9
|
import bioversions
|
|
@@ -10,10 +11,14 @@ import bioversions
|
|
|
10
11
|
from ..utils.path import prefix_directory_join
|
|
11
12
|
|
|
12
13
|
__all__ = [
|
|
14
|
+
"safe_get_version",
|
|
13
15
|
"get_version",
|
|
16
|
+
"get_version_pins",
|
|
14
17
|
"VersionError",
|
|
15
18
|
]
|
|
16
19
|
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
17
22
|
|
|
18
23
|
class VersionError(ValueError):
|
|
19
24
|
"""A catch-all for version getting failure."""
|
|
@@ -25,6 +30,10 @@ def get_version(prefix: str) -> Optional[str]:
|
|
|
25
30
|
:param prefix: the resource name
|
|
26
31
|
:return: The version if available else None
|
|
27
32
|
"""
|
|
33
|
+
# Prioritize loaded environment variable PYOBO_VERSION_PINS dictionary
|
|
34
|
+
version = get_version_pins().get(prefix)
|
|
35
|
+
if version:
|
|
36
|
+
return version
|
|
28
37
|
try:
|
|
29
38
|
version = bioversions.get_version(prefix)
|
|
30
39
|
except KeyError:
|
|
@@ -41,3 +50,55 @@ def get_version(prefix: str) -> Optional[str]:
|
|
|
41
50
|
return data["version"]
|
|
42
51
|
|
|
43
52
|
return None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def safe_get_version(prefix: str) -> str:
|
|
56
|
+
"""Get the version."""
|
|
57
|
+
v = get_version(prefix)
|
|
58
|
+
if v is None:
|
|
59
|
+
raise ValueError
|
|
60
|
+
return v
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@lru_cache(1)
|
|
64
|
+
def get_version_pins() -> dict[str, str]:
|
|
65
|
+
"""Retrieve user-defined resource version pins.
|
|
66
|
+
|
|
67
|
+
To set your own resource pins, set your machine's environmental variable
|
|
68
|
+
"PYOBO_VERSION_PINS" to a JSON string containing string resource prefixes
|
|
69
|
+
as keys and string versions of their respective resource as values.
|
|
70
|
+
Constraining version pins will make PyOBO rely on cached versions of a resource.
|
|
71
|
+
A user might want to pin resource versions that are used by PyOBO due to
|
|
72
|
+
the fact that PyOBO will download the latest version of a resource if it is
|
|
73
|
+
not pinned. This downloading process can lead to a slow-down in downstream
|
|
74
|
+
applications that rely on PyOBO.
|
|
75
|
+
"""
|
|
76
|
+
version_pins_str = os.getenv("PYOBO_VERSION_PINS")
|
|
77
|
+
if not version_pins_str:
|
|
78
|
+
return {}
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
version_pins = json.loads(version_pins_str)
|
|
82
|
+
except ValueError as e:
|
|
83
|
+
logger.error(
|
|
84
|
+
"The value for the environment variable PYOBO_VERSION_PINS "
|
|
85
|
+
"must be a valid JSON string: %s",
|
|
86
|
+
e,
|
|
87
|
+
)
|
|
88
|
+
return {}
|
|
89
|
+
|
|
90
|
+
for prefix, version in list(version_pins.items()):
|
|
91
|
+
if not isinstance(prefix, str) or not isinstance(version, str):
|
|
92
|
+
logger.error(f"The prefix:{prefix} and version:{version} name must both be strings")
|
|
93
|
+
del version_pins[prefix]
|
|
94
|
+
|
|
95
|
+
logger.debug(
|
|
96
|
+
f"These are the resource versions that are pinned.\n"
|
|
97
|
+
f"{version_pins}. "
|
|
98
|
+
f"\nPyobo will download the latest version of a resource if it's "
|
|
99
|
+
f"not pinned.\nIf you want to use a specific version of a "
|
|
100
|
+
f"resource, edit your PYOBO_VERSION_PINS environmental "
|
|
101
|
+
f"variable which is a JSON string to include a prefix and version "
|
|
102
|
+
f"name."
|
|
103
|
+
)
|
|
104
|
+
return version_pins
|