pyobo 0.11.0__py3-none-any.whl → 0.11.2__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.
Files changed (47) hide show
  1. pyobo/constants.py +1 -0
  2. pyobo/gilda_utils.py +14 -11
  3. pyobo/obographs.py +5 -2
  4. pyobo/resources/so.py +55 -0
  5. pyobo/resources/so.tsv +2604 -0
  6. pyobo/sources/complexportal.py +54 -15
  7. pyobo/sources/dictybase_gene.py +14 -9
  8. pyobo/sources/drugcentral.py +4 -1
  9. pyobo/sources/expasy.py +22 -4
  10. pyobo/sources/flybase.py +3 -2
  11. pyobo/sources/hgnc.py +24 -19
  12. pyobo/sources/hgncgenefamily.py +7 -7
  13. pyobo/sources/kegg/genome.py +18 -6
  14. pyobo/sources/mirbase.py +9 -3
  15. pyobo/sources/npass.py +1 -1
  16. pyobo/sources/pathbank.py +32 -23
  17. pyobo/sources/pombase.py +6 -3
  18. pyobo/sources/reactome.py +28 -7
  19. pyobo/sources/rgd.py +1 -1
  20. pyobo/sources/slm.py +28 -14
  21. pyobo/sources/uniprot/uniprot.py +7 -6
  22. pyobo/sources/zfin.py +18 -6
  23. pyobo/struct/reference.py +9 -8
  24. pyobo/struct/struct.py +30 -20
  25. pyobo/struct/typedef.py +5 -0
  26. pyobo/version.py +1 -1
  27. {pyobo-0.11.0.dist-info → pyobo-0.11.2.dist-info}/METADATA +50 -62
  28. {pyobo-0.11.0.dist-info → pyobo-0.11.2.dist-info}/RECORD +31 -45
  29. {pyobo-0.11.0.dist-info → pyobo-0.11.2.dist-info}/WHEEL +1 -1
  30. pyobo/apps/__init__.py +0 -3
  31. pyobo/apps/cli.py +0 -24
  32. pyobo/apps/gilda/__init__.py +0 -3
  33. pyobo/apps/gilda/__main__.py +0 -8
  34. pyobo/apps/gilda/app.py +0 -48
  35. pyobo/apps/gilda/cli.py +0 -36
  36. pyobo/apps/gilda/templates/base.html +0 -33
  37. pyobo/apps/gilda/templates/home.html +0 -11
  38. pyobo/apps/gilda/templates/matches.html +0 -32
  39. pyobo/apps/mapper/__init__.py +0 -3
  40. pyobo/apps/mapper/__main__.py +0 -11
  41. pyobo/apps/mapper/cli.py +0 -37
  42. pyobo/apps/mapper/mapper.py +0 -187
  43. pyobo/apps/mapper/templates/base.html +0 -35
  44. pyobo/apps/mapper/templates/mapper_home.html +0 -64
  45. pyobo-0.11.0.dist-info/LICENSE +0 -21
  46. {pyobo-0.11.0.dist-info → pyobo-0.11.2.dist-info}/entry_points.txt +0 -0
  47. {pyobo-0.11.0.dist-info → pyobo-0.11.2.dist-info}/top_level.txt +0 -0
pyobo/constants.py CHANGED
@@ -29,6 +29,7 @@ GLOBAL_SKIP = {
29
29
  "resid", # deprecated
30
30
  "adw", # deprecated
31
31
  }
32
+ GLOBAL_CHECK_IDS = False
32
33
 
33
34
  #: Default prefix
34
35
  DEFAULT_PREFIX = "debio"
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: Optional[Grounder] = None,
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: Union[str, Iterable[str]],
94
+ prefixes: str | Iterable[str],
94
95
  *,
95
- unnamed: Optional[Iterable[str]] = None,
96
- grounder_cls: Optional[type[Grounder]] = None,
97
- versions: Union[None, str, Iterable[Union[str, None]]] = None,
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: Optional[str] = None,
150
- ) -> Optional[gilda.term.Term]:
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: Optional[str] = None,
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: Union[str, list[str]], **kwargs
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: Union[str, list[str]]) -> list[str]:
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 obo:
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()