pyobo 0.11.0__py3-none-any.whl → 0.11.1__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/constants.py +1 -0
- pyobo/gilda_utils.py +14 -11
- pyobo/obographs.py +5 -2
- pyobo/resources/so.py +55 -0
- pyobo/resources/so.tsv +2604 -0
- pyobo/sources/complexportal.py +54 -15
- pyobo/sources/dictybase_gene.py +14 -9
- pyobo/sources/drugcentral.py +4 -1
- pyobo/sources/expasy.py +22 -4
- pyobo/sources/flybase.py +3 -2
- pyobo/sources/hgnc.py +24 -19
- pyobo/sources/hgncgenefamily.py +7 -7
- pyobo/sources/kegg/genome.py +18 -6
- pyobo/sources/mirbase.py +9 -3
- pyobo/sources/npass.py +1 -1
- pyobo/sources/pathbank.py +32 -23
- pyobo/sources/pombase.py +6 -3
- pyobo/sources/reactome.py +28 -7
- pyobo/sources/rgd.py +1 -1
- pyobo/sources/slm.py +28 -14
- pyobo/sources/uniprot/uniprot.py +7 -6
- pyobo/sources/zfin.py +18 -6
- pyobo/struct/reference.py +9 -8
- pyobo/struct/struct.py +30 -20
- pyobo/struct/typedef.py +5 -0
- pyobo/version.py +1 -1
- {pyobo-0.11.0.dist-info → pyobo-0.11.1.dist-info}/METADATA +30 -42
- {pyobo-0.11.0.dist-info → pyobo-0.11.1.dist-info}/RECORD +32 -30
- {pyobo-0.11.0.dist-info → pyobo-0.11.1.dist-info}/WHEEL +1 -1
- {pyobo-0.11.0.dist-info → pyobo-0.11.1.dist-info}/LICENSE +0 -0
- {pyobo-0.11.0.dist-info → pyobo-0.11.1.dist-info}/entry_points.txt +0 -0
- {pyobo-0.11.0.dist-info → pyobo-0.11.1.dist-info}/top_level.txt +0 -0
pyobo/constants.py
CHANGED
pyobo/gilda_utils.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"""PyOBO's Gilda utilities."""
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
import logging
|
|
4
6
|
from collections.abc import Iterable
|
|
5
7
|
from subprocess import CalledProcessError
|
|
6
|
-
from typing import Optional, Union
|
|
7
8
|
|
|
8
9
|
import bioregistry
|
|
9
10
|
import gilda.api
|
|
@@ -37,7 +38,7 @@ def iter_gilda_prediction_tuples(
|
|
|
37
38
|
prefix: str,
|
|
38
39
|
relation: str = "skos:exactMatch",
|
|
39
40
|
*,
|
|
40
|
-
grounder:
|
|
41
|
+
grounder: Grounder | None = None,
|
|
41
42
|
identifiers_are_names: bool = False,
|
|
42
43
|
strict: bool = False,
|
|
43
44
|
) -> Iterable[tuple[str, str, str, str, str, str, str, str, float]]:
|
|
@@ -90,11 +91,11 @@ def normalize_identifier(prefix: str, identifier: str) -> str:
|
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
def get_grounder(
|
|
93
|
-
prefixes:
|
|
94
|
+
prefixes: str | Iterable[str],
|
|
94
95
|
*,
|
|
95
|
-
unnamed:
|
|
96
|
-
grounder_cls:
|
|
97
|
-
versions:
|
|
96
|
+
unnamed: Iterable[str] | None = None,
|
|
97
|
+
grounder_cls: type[Grounder] | None = None,
|
|
98
|
+
versions: None | str | Iterable[str | None] | dict[str, str] = None,
|
|
98
99
|
strict: bool = True,
|
|
99
100
|
skip_obsolete: bool = False,
|
|
100
101
|
progress: bool = True,
|
|
@@ -109,6 +110,8 @@ def get_grounder(
|
|
|
109
110
|
versions = [None] * len(prefixes)
|
|
110
111
|
elif isinstance(versions, str):
|
|
111
112
|
versions = [versions]
|
|
113
|
+
elif isinstance(versions, dict):
|
|
114
|
+
versions = [versions.get(prefix) for prefix in prefixes]
|
|
112
115
|
else:
|
|
113
116
|
versions = list(versions)
|
|
114
117
|
if len(prefixes) != len(versions):
|
|
@@ -146,8 +149,8 @@ def _fast_term(
|
|
|
146
149
|
identifier: str,
|
|
147
150
|
name: str,
|
|
148
151
|
status: str,
|
|
149
|
-
organism:
|
|
150
|
-
) ->
|
|
152
|
+
organism: str | None = None,
|
|
153
|
+
) -> gilda.term.Term | None:
|
|
151
154
|
try:
|
|
152
155
|
term = gilda.term.Term(
|
|
153
156
|
norm_text=normalize(text),
|
|
@@ -168,7 +171,7 @@ def get_gilda_terms(
|
|
|
168
171
|
prefix: str,
|
|
169
172
|
*,
|
|
170
173
|
identifiers_are_names: bool = False,
|
|
171
|
-
version:
|
|
174
|
+
version: str | None = None,
|
|
172
175
|
strict: bool = True,
|
|
173
176
|
skip_obsolete: bool = False,
|
|
174
177
|
progress: bool = True,
|
|
@@ -250,7 +253,7 @@ def get_gilda_terms(
|
|
|
250
253
|
|
|
251
254
|
|
|
252
255
|
def get_gilda_term_subset(
|
|
253
|
-
source: str, ancestors:
|
|
256
|
+
source: str, ancestors: str | list[str], **kwargs
|
|
254
257
|
) -> Iterable[gilda.term.Term]:
|
|
255
258
|
"""Get a subset of terms."""
|
|
256
259
|
subset = {
|
|
@@ -263,7 +266,7 @@ def get_gilda_term_subset(
|
|
|
263
266
|
yield term
|
|
264
267
|
|
|
265
268
|
|
|
266
|
-
def _ensure_list(s:
|
|
269
|
+
def _ensure_list(s: str | list[str]) -> list[str]:
|
|
267
270
|
if isinstance(s, str):
|
|
268
271
|
return [s]
|
|
269
272
|
return s
|
pyobo/obographs.py
CHANGED
|
@@ -17,6 +17,7 @@ from bioontologies.obograph import (
|
|
|
17
17
|
Xref,
|
|
18
18
|
)
|
|
19
19
|
from bioontologies.robot import ParseResults
|
|
20
|
+
from tqdm import tqdm
|
|
20
21
|
|
|
21
22
|
from pyobo.struct import Obo, Reference, Term
|
|
22
23
|
from pyobo.struct.typedef import definition_source, is_a
|
|
@@ -33,11 +34,13 @@ def parse_results_from_obo(obo: Obo) -> ParseResults:
|
|
|
33
34
|
return ParseResults(graph_document=GraphDocument(graphs=[graph]))
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
def graph_from_obo(obo: Obo) -> Graph:
|
|
37
|
+
def graph_from_obo(obo: Obo, use_tqdm: bool = True) -> Graph:
|
|
37
38
|
"""Get an OBO Graph object from a PyOBO object."""
|
|
38
39
|
nodes: list[Node] = []
|
|
39
40
|
edges: list[Edge] = []
|
|
40
|
-
for term in
|
|
41
|
+
for term in tqdm(
|
|
42
|
+
obo, disable=not use_tqdm, unit="term", unit_scale=True, desc=f"[{obo.ontology}] to JSON"
|
|
43
|
+
):
|
|
41
44
|
nodes.append(_get_class_node(term))
|
|
42
45
|
edges.extend(_iter_edges(term))
|
|
43
46
|
return Graph(
|
pyobo/resources/so.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Loading of the relations ontology names."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
import os
|
|
7
|
+
from functools import lru_cache
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"get_so_name",
|
|
13
|
+
"load_so",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
HERE = os.path.abspath(os.path.dirname(__file__))
|
|
17
|
+
SO_PATH = os.path.join(HERE, "so.tsv")
|
|
18
|
+
SO_JSON_URL = "https://github.com/The-Sequence-Ontology/SO-Ontologies/raw/refs/heads/master/Ontology_Files/so-simple.json"
|
|
19
|
+
SO_URI_PREFIX = "http://purl.obolibrary.org/obo/SO_"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_so_name(so_id: str) -> str | None:
|
|
23
|
+
"""Get the name from the identifier."""
|
|
24
|
+
return load_so().get(so_id)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@lru_cache(maxsize=1)
|
|
28
|
+
def load_so() -> dict[str, str]:
|
|
29
|
+
"""Load the Sequence Ontology names."""
|
|
30
|
+
if not os.path.exists(SO_PATH):
|
|
31
|
+
download_so()
|
|
32
|
+
with open(SO_PATH) as file:
|
|
33
|
+
return dict(csv.reader(file, delimiter="\t"))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def download_so():
|
|
37
|
+
"""Download the latest version of the Relation Ontology."""
|
|
38
|
+
rows = []
|
|
39
|
+
res_json = requests.get(SO_JSON_URL).json()
|
|
40
|
+
for node in res_json["graphs"][0]["nodes"]:
|
|
41
|
+
uri = node["id"]
|
|
42
|
+
if not uri.startswith(SO_URI_PREFIX):
|
|
43
|
+
continue
|
|
44
|
+
identifier = uri.removeprefix(SO_URI_PREFIX)
|
|
45
|
+
name = node.get("lbl")
|
|
46
|
+
if name:
|
|
47
|
+
rows.append((identifier, name))
|
|
48
|
+
|
|
49
|
+
with open(SO_PATH, "w") as file:
|
|
50
|
+
writer = csv.writer(file, delimiter="\t")
|
|
51
|
+
writer.writerows(sorted(rows, key=lambda x: int(x[0])))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
download_so()
|