pyobo 0.12.10__py3-none-any.whl → 0.12.12__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 (46) hide show
  1. pyobo/__init__.py +6 -0
  2. pyobo/api/__init__.py +11 -1
  3. pyobo/api/alts.py +18 -4
  4. pyobo/api/embedding.py +108 -9
  5. pyobo/api/names.py +28 -6
  6. pyobo/api/xrefs.py +21 -1
  7. pyobo/cli/cli.py +9 -3
  8. pyobo/cli/database.py +63 -22
  9. pyobo/cli/lookup.py +39 -24
  10. pyobo/cli/utils.py +6 -2
  11. pyobo/constants.py +66 -7
  12. pyobo/getters.py +8 -3
  13. pyobo/ner/api.py +17 -10
  14. pyobo/ner/scispacy_utils.py +2 -0
  15. pyobo/plugins.py +3 -1
  16. pyobo/sources/__init__.py +2 -0
  17. pyobo/sources/antibodyregistry.py +3 -3
  18. pyobo/sources/bigg/bigg_compartment.py +1 -1
  19. pyobo/sources/complexportal.py +3 -3
  20. pyobo/sources/conso.py +3 -3
  21. pyobo/sources/famplex.py +3 -3
  22. pyobo/sources/goldbook.py +86 -0
  23. pyobo/sources/hgnc/hgnc.py +157 -96
  24. pyobo/sources/hgnc/hgncgenefamily.py +14 -13
  25. pyobo/sources/msigdb.py +3 -3
  26. pyobo/sources/omim_ps.py +8 -2
  27. pyobo/sources/reactome.py +3 -3
  28. pyobo/sources/rgd.py +7 -11
  29. pyobo/sources/slm.py +3 -3
  30. pyobo/sources/uniprot/uniprot.py +3 -3
  31. pyobo/sources/wikipathways.py +7 -2
  32. pyobo/struct/__init__.py +2 -2
  33. pyobo/struct/functional/macros.py +1 -1
  34. pyobo/struct/functional/obo_to_functional.py +7 -3
  35. pyobo/struct/obo/reader.py +4 -4
  36. pyobo/struct/struct.py +48 -18
  37. pyobo/struct/struct_utils.py +19 -5
  38. pyobo/struct/typedef.py +19 -3
  39. pyobo/struct/vocabulary.py +6 -3
  40. pyobo/utils/path.py +5 -4
  41. pyobo/version.py +1 -1
  42. {pyobo-0.12.10.dist-info → pyobo-0.12.12.dist-info}/METADATA +45 -23
  43. {pyobo-0.12.10.dist-info → pyobo-0.12.12.dist-info}/RECORD +46 -45
  44. {pyobo-0.12.10.dist-info → pyobo-0.12.12.dist-info}/WHEEL +1 -1
  45. {pyobo-0.12.10.dist-info → pyobo-0.12.12.dist-info}/entry_points.txt +0 -0
  46. {pyobo-0.12.10.dist-info → pyobo-0.12.12.dist-info}/licenses/LICENSE +0 -0
pyobo/cli/database.py CHANGED
@@ -5,29 +5,11 @@ import warnings
5
5
  from collections.abc import Iterable
6
6
  from pathlib import Path
7
7
 
8
- import bioregistry
9
- import bioversions
10
8
  import click
11
9
  from more_click import verbose_option
12
10
  from tqdm.contrib.logging import logging_redirect_tqdm
13
11
  from typing_extensions import Unpack
14
- from zenodo_client import update_zenodo
15
-
16
- from .database_utils import (
17
- IterHelperHelperDict,
18
- _iter_alts,
19
- _iter_definitions,
20
- _iter_edges,
21
- _iter_mappings,
22
- _iter_names,
23
- _iter_properties,
24
- _iter_relations,
25
- _iter_species,
26
- _iter_synonyms,
27
- _iter_typedefs,
28
- _iter_xrefs,
29
- iter_helper_helper,
30
- )
12
+
31
13
  from .utils import (
32
14
  Clickable,
33
15
  directory_option,
@@ -48,7 +30,6 @@ from ..constants import (
48
30
  TYPEDEFS_RECORD,
49
31
  DatabaseKwargs,
50
32
  )
51
- from ..getters import db_output_helper, get_ontology
52
33
 
53
34
  __all__ = [
54
35
  "main",
@@ -107,6 +88,8 @@ def build(ctx: click.Context, eager_versions: bool, **kwargs: Unpack[DatabaseKwa
107
88
  # sys.exit(1)
108
89
 
109
90
  if eager_versions:
91
+ import bioversions
92
+
110
93
  bioversions.get_rows(use_tqdm=True)
111
94
 
112
95
  with logging_redirect_tqdm():
@@ -143,6 +126,9 @@ def build(ctx: click.Context, eager_versions: bool, **kwargs: Unpack[DatabaseKwa
143
126
  @database_annotate
144
127
  def cache(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
145
128
  """Cache all things."""
129
+ from .database_utils import iter_helper_helper
130
+ from ..getters import get_ontology
131
+
146
132
  if zenodo:
147
133
  click.echo("no zenodo for caching")
148
134
 
@@ -156,9 +142,13 @@ def cache(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> No
156
142
  @database_annotate
157
143
  def metadata(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
158
144
  """Make the prefix-metadata dump."""
145
+ import bioregistry
146
+
147
+ from .database_utils import IterHelperHelperDict, iter_helper_helper
159
148
  from ..api import get_metadata
149
+ from ..getters import db_output_helper
160
150
 
161
- def _iter_metadata(
151
+ def _iter_metadata_internal(
162
152
  **kwargs: Unpack[IterHelperHelperDict],
163
153
  ) -> Iterable[tuple[str, str, str, bool]]:
164
154
  for prefix, data in iter_helper_helper(get_metadata, **kwargs):
@@ -166,7 +156,7 @@ def metadata(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
166
156
  logger.debug(f"[{prefix}] using version {version}")
167
157
  yield prefix, version, data["date"], bioregistry.is_deprecated(prefix)
168
158
 
169
- it = _iter_metadata(**kwargs)
159
+ it = _iter_metadata_internal(**kwargs)
170
160
  db_output_helper(
171
161
  it,
172
162
  "metadata",
@@ -181,6 +171,9 @@ def metadata(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
181
171
  @database_annotate
182
172
  def names(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
183
173
  """Make the prefix-identifier-name dump."""
174
+ from .database_utils import _iter_names
175
+ from ..getters import db_output_helper
176
+
184
177
  it = _iter_names(**kwargs)
185
178
  with logging_redirect_tqdm():
186
179
  paths = db_output_helper(
@@ -190,6 +183,8 @@ def names(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> No
190
183
  directory=directory,
191
184
  )
192
185
  if zenodo:
186
+ from zenodo_client import update_zenodo
187
+
193
188
  # see https://zenodo.org/record/4020486
194
189
  update_zenodo(OOH_NA_NA_RECORD, paths)
195
190
 
@@ -197,6 +192,9 @@ def names(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> No
197
192
  @database_annotate
198
193
  def species(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
199
194
  """Make the prefix-identifier-species dump."""
195
+ from .database_utils import _iter_species
196
+ from ..getters import db_output_helper
197
+
200
198
  with logging_redirect_tqdm():
201
199
  it = _iter_species(**kwargs)
202
200
  paths = db_output_helper(
@@ -206,6 +204,8 @@ def species(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
206
204
  directory=directory,
207
205
  )
208
206
  if zenodo:
207
+ from zenodo_client import update_zenodo
208
+
209
209
  # see https://zenodo.org/record/5334738
210
210
  update_zenodo(SPECIES_RECORD, paths)
211
211
 
@@ -221,6 +221,9 @@ def _extend_skip_set(kwargs: DatabaseKwargs, skip_set: set[str]) -> None:
221
221
  @database_annotate
222
222
  def definitions(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
223
223
  """Make the prefix-identifier-definition dump."""
224
+ from .database_utils import _iter_definitions
225
+ from ..getters import db_output_helper
226
+
224
227
  with logging_redirect_tqdm():
225
228
  _extend_skip_set(kwargs, {"kegg.pathway", "kegg.genes", "kegg.genome", "umls"})
226
229
  it = _iter_definitions(**kwargs)
@@ -231,6 +234,8 @@ def definitions(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs])
231
234
  directory=directory,
232
235
  )
233
236
  if zenodo:
237
+ from zenodo_client import update_zenodo
238
+
234
239
  # see https://zenodo.org/record/4637061
235
240
  update_zenodo(DEFINITIONS_RECORD, paths)
236
241
 
@@ -238,6 +243,9 @@ def definitions(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs])
238
243
  @database_annotate
239
244
  def typedefs(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
240
245
  """Make the typedef prefix-identifier-name dump."""
246
+ from .database_utils import _iter_typedefs
247
+ from ..getters import db_output_helper
248
+
241
249
  with logging_redirect_tqdm():
242
250
  _extend_skip_set(kwargs, {"ncbigene", "kegg.pathway", "kegg.genes", "kegg.genome"})
243
251
  it = _iter_typedefs(**kwargs)
@@ -249,6 +257,8 @@ def typedefs(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
249
257
  directory=directory,
250
258
  )
251
259
  if zenodo:
260
+ from zenodo_client import update_zenodo
261
+
252
262
  # see https://zenodo.org/record/4644013
253
263
  update_zenodo(TYPEDEFS_RECORD, paths)
254
264
 
@@ -256,6 +266,9 @@ def typedefs(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
256
266
  @database_annotate
257
267
  def alts(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
258
268
  """Make the prefix-alt-id dump."""
269
+ from .database_utils import _iter_alts
270
+ from ..getters import db_output_helper
271
+
259
272
  with logging_redirect_tqdm():
260
273
  _extend_skip_set(kwargs, {"kegg.pathway", "kegg.genes", "kegg.genome", "umls"})
261
274
  it = _iter_alts(**kwargs)
@@ -266,6 +279,8 @@ def alts(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> Non
266
279
  directory=directory,
267
280
  )
268
281
  if zenodo:
282
+ from zenodo_client import update_zenodo
283
+
269
284
  # see https://zenodo.org/record/4021476
270
285
  update_zenodo(ALTS_DATA_RECORD, paths)
271
286
 
@@ -273,6 +288,9 @@ def alts(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> Non
273
288
  @database_annotate
274
289
  def synonyms(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
275
290
  """Make the prefix-identifier-synonym dump."""
291
+ from .database_utils import _iter_synonyms
292
+ from ..getters import db_output_helper
293
+
276
294
  with logging_redirect_tqdm():
277
295
  _extend_skip_set(kwargs, {"kegg.pathway", "kegg.genes", "kegg.genome"})
278
296
  it = _iter_synonyms(**kwargs)
@@ -283,6 +301,8 @@ def synonyms(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
283
301
  directory=directory,
284
302
  )
285
303
  if zenodo:
304
+ from zenodo_client import update_zenodo
305
+
286
306
  # see https://zenodo.org/record/4021482
287
307
  update_zenodo(SYNONYMS_RECORD, paths)
288
308
 
@@ -290,6 +310,9 @@ def synonyms(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) ->
290
310
  @database_annotate
291
311
  def relations(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
292
312
  """Make the relation dump."""
313
+ from .database_utils import _iter_relations
314
+ from ..getters import db_output_helper
315
+
293
316
  with logging_redirect_tqdm():
294
317
  it = _iter_relations(**kwargs)
295
318
  paths = db_output_helper(
@@ -307,6 +330,8 @@ def relations(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -
307
330
  directory=directory,
308
331
  )
309
332
  if zenodo:
333
+ from zenodo_client import update_zenodo
334
+
310
335
  # see https://zenodo.org/record/4625167
311
336
  update_zenodo(RELATIONS_RECORD, paths)
312
337
 
@@ -314,6 +339,9 @@ def relations(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -
314
339
  @database_annotate
315
340
  def edges(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
316
341
  """Make the edges dump."""
342
+ from .database_utils import _iter_edges
343
+ from ..getters import db_output_helper
344
+
317
345
  with logging_redirect_tqdm():
318
346
  it = _iter_edges(**kwargs)
319
347
  db_output_helper(
@@ -334,6 +362,9 @@ def edges(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> No
334
362
  @database_annotate
335
363
  def properties(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
336
364
  """Make the properties dump."""
365
+ from .database_utils import _iter_properties
366
+ from ..getters import db_output_helper
367
+
337
368
  with logging_redirect_tqdm():
338
369
  it = _iter_properties(**kwargs)
339
370
  paths = db_output_helper(
@@ -344,6 +375,8 @@ def properties(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs])
344
375
  directory=directory,
345
376
  )
346
377
  if zenodo:
378
+ from zenodo_client import update_zenodo
379
+
347
380
  # see https://zenodo.org/record/4625172
348
381
  update_zenodo(PROPERTIES_RECORD, paths)
349
382
 
@@ -351,6 +384,9 @@ def properties(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs])
351
384
  @database_annotate
352
385
  def xrefs(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
353
386
  """Make the prefix-identifier-xref dump."""
387
+ from .database_utils import _iter_xrefs
388
+ from ..getters import db_output_helper
389
+
354
390
  warnings.warn("Use pyobo.database.mappings instead", DeprecationWarning, stacklevel=2)
355
391
  with logging_redirect_tqdm():
356
392
  it = _iter_xrefs(**kwargs)
@@ -362,6 +398,8 @@ def xrefs(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> No
362
398
  directory=directory,
363
399
  )
364
400
  if zenodo:
401
+ from zenodo_client import update_zenodo
402
+
365
403
  # see https://zenodo.org/record/4021477
366
404
  update_zenodo(JAVERT_RECORD, paths)
367
405
 
@@ -369,6 +407,9 @@ def xrefs(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> No
369
407
  @database_annotate
370
408
  def mappings(zenodo: bool, directory: Path, **kwargs: Unpack[DatabaseKwargs]) -> None:
371
409
  """Make the SSSOM dump."""
410
+ from .database_utils import _iter_mappings
411
+ from ..getters import db_output_helper
412
+
372
413
  columns = [
373
414
  "subject_id",
374
415
  "object_id",
pyobo/cli/lookup.py CHANGED
@@ -4,7 +4,6 @@ import json
4
4
  import sys
5
5
  from collections.abc import Mapping
6
6
 
7
- import bioregistry
8
7
  import click
9
8
  from more_click import verbose_option
10
9
  from typing_extensions import Unpack
@@ -18,30 +17,7 @@ from .utils import (
18
17
  strict_option,
19
18
  version_option,
20
19
  )
21
- from ..api import (
22
- get_ancestors,
23
- get_descendants,
24
- get_filtered_properties_df,
25
- get_filtered_relations_df,
26
- get_filtered_xrefs,
27
- get_hierarchy,
28
- get_id_definition_mapping,
29
- get_id_name_mapping,
30
- get_id_species_mapping,
31
- get_id_synonyms_mapping,
32
- get_id_to_alts,
33
- get_ids,
34
- get_mappings_df,
35
- get_metadata,
36
- get_name,
37
- get_properties_df,
38
- get_relations_df,
39
- get_typedef_df,
40
- get_xrefs_df,
41
- )
42
20
  from ..constants import LookupKwargs
43
- from ..getters import get_ontology
44
- from ..struct.reference import _parse_str_or_curie_or_uri
45
21
 
46
22
  __all__ = [
47
23
  "lookup",
@@ -75,6 +51,10 @@ identifier_option = click.option("-i", "--identifier")
75
51
  @click.option("-t", "--target")
76
52
  def xrefs(target: str, **kwargs: Unpack[LookupKwargs]) -> None:
77
53
  """Page through xrefs for the given namespace to the second given namespace."""
54
+ import bioregistry
55
+
56
+ from ..api import get_filtered_xrefs, get_xrefs_df
57
+
78
58
  if target:
79
59
  target_norm = bioregistry.normalize_prefix(target)
80
60
  filtered_xrefs = get_filtered_xrefs(xref_prefix=target_norm, **kwargs)
@@ -91,6 +71,10 @@ def xrefs(target: str, **kwargs: Unpack[LookupKwargs]) -> None:
91
71
  @click.option("-t", "--target")
92
72
  def mappings(include_names: bool, target: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
93
73
  """Page through mappings for the given namespace."""
74
+ import bioregistry
75
+
76
+ from ..api import get_mappings_df
77
+
94
78
  mappings_df = get_mappings_df(names=include_names, **kwargs)
95
79
  if target:
96
80
  target_norm = bioregistry.normalize_prefix(target)
@@ -106,6 +90,8 @@ def mappings(include_names: bool, target: str | None, **kwargs: Unpack[LookupKwa
106
90
  @lookup_annotate
107
91
  def metadata(**kwargs: Unpack[LookupKwargs]) -> None:
108
92
  """Print the metadata for the given namespace."""
93
+ from ..api import get_metadata
94
+
109
95
  metadata = get_metadata(**kwargs)
110
96
  click.echo(json.dumps(metadata, indent=2))
111
97
 
@@ -113,6 +99,8 @@ def metadata(**kwargs: Unpack[LookupKwargs]) -> None:
113
99
  @lookup_annotate
114
100
  def ids(**kwargs: Unpack[LookupKwargs]) -> None:
115
101
  """Page through the identifiers of entities in the given namespace."""
102
+ from ..api import get_ids
103
+
116
104
  id_list = get_ids(**kwargs)
117
105
  if not id_list:
118
106
  click.secho("no data", fg="red")
@@ -124,6 +112,8 @@ def ids(**kwargs: Unpack[LookupKwargs]) -> None:
124
112
  @identifier_option
125
113
  def names(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
126
114
  """Page through the identifiers and names of entities in the given namespace."""
115
+ from ..api import get_id_name_mapping
116
+
127
117
  id_to_name = get_id_name_mapping(**kwargs)
128
118
  _help_page_mapping(id_to_name, identifier=identifier)
129
119
 
@@ -132,6 +122,8 @@ def names(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
132
122
  @identifier_option
133
123
  def species(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
134
124
  """Page through the identifiers and species of entities in the given namespace."""
125
+ from ..api import get_id_species_mapping
126
+
135
127
  id_to_species = get_id_species_mapping(**kwargs)
136
128
  _help_page_mapping(id_to_species, identifier=identifier)
137
129
 
@@ -140,6 +132,8 @@ def species(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
140
132
  @identifier_option
141
133
  def definitions(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
142
134
  """Page through the identifiers and definitions of entities in the given namespace."""
135
+ from ..api import get_id_definition_mapping
136
+
143
137
  id_to_definition = get_id_definition_mapping(**kwargs)
144
138
  _help_page_mapping(id_to_definition, identifier=identifier)
145
139
 
@@ -147,6 +141,8 @@ def definitions(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
147
141
  @lookup_annotate
148
142
  def typedefs(**kwargs: Unpack[LookupKwargs]) -> None:
149
143
  """Page through the identifiers and names of typedefs in the given namespace."""
144
+ from ..api import get_typedef_df
145
+
150
146
  df = get_typedef_df(**kwargs)
151
147
  echo_df(df)
152
148
 
@@ -168,6 +164,8 @@ def _help_page_mapping(id_to_name: Mapping[str, str], *, identifier: str | None
168
164
  @identifier_option
169
165
  def synonyms(identifier: str | None, **kwargs: Unpack[LookupKwargs]) -> None:
170
166
  """Page through the synonyms for entities in the given namespace."""
167
+ from ..api import get_id_synonyms_mapping
168
+
171
169
  id_to_synonyms = get_id_synonyms_mapping(**kwargs)
172
170
  if identifier is None:
173
171
  click.echo_via_pager(
@@ -198,6 +196,11 @@ def relations(
198
196
  **kwargs: Unpack[LookupKwargs],
199
197
  ) -> None:
200
198
  """Page through the relations for entities in the given namespace."""
199
+ import bioregistry
200
+
201
+ from ..api import get_filtered_relations_df, get_relations_df
202
+ from ..struct.reference import _parse_str_or_curie_or_uri
203
+
201
204
  if relation is None:
202
205
  relations_df = get_relations_df(**kwargs)
203
206
  if summarize:
@@ -232,6 +235,8 @@ def hierarchy(
232
235
  **kwargs: Unpack[LookupKwargs],
233
236
  ) -> None:
234
237
  """Page through the hierarchy for entities in the namespace."""
238
+ from ..api import get_hierarchy
239
+
235
240
  h = get_hierarchy(
236
241
  include_part_of=include_part_of,
237
242
  include_has_member=include_has_member,
@@ -250,6 +255,8 @@ def ancestors(
250
255
  **kwargs: Unpack[LookupKwargs],
251
256
  ) -> None:
252
257
  """Look up ancestors."""
258
+ from ..api import get_ancestors, get_name
259
+
253
260
  # note, prefix is passed via kwargs
254
261
  ancestors = get_ancestors(identifier=identifier, **kwargs)
255
262
  for ancestor in sorted(ancestors or []):
@@ -263,6 +270,8 @@ def descendants(
263
270
  **kwargs: Unpack[LookupKwargs],
264
271
  ) -> None:
265
272
  """Look up descendants."""
273
+ from ..api import get_descendants, get_name
274
+
266
275
  # note, prefix is passed via kwargs
267
276
  descendants = get_descendants(identifier=identifier, **kwargs)
268
277
  for descendant in sorted(descendants or []):
@@ -276,6 +285,8 @@ def properties(
276
285
  **kwargs: Unpack[LookupKwargs],
277
286
  ) -> None:
278
287
  """Page through the properties for entities in the given namespace."""
288
+ from ..api import get_filtered_properties_df, get_properties_df
289
+
279
290
  if key is None:
280
291
  properties_df = get_properties_df(**kwargs)
281
292
  else:
@@ -290,6 +301,8 @@ def alts(
290
301
  **kwargs: Unpack[LookupKwargs],
291
302
  ) -> None:
292
303
  """Page through alt ids in a namespace."""
304
+ from ..api import get_id_to_alts
305
+
293
306
  id_to_alts = get_id_to_alts(**kwargs)
294
307
  _help_page_mapping(id_to_alts, identifier=identifier)
295
308
 
@@ -297,6 +310,8 @@ def alts(
297
310
  @lookup_annotate
298
311
  def prefixes(**kwargs: Unpack[LookupKwargs]) -> None:
299
312
  """Page through prefixes appearing in an ontology."""
313
+ from ..getters import get_ontology
314
+
300
315
  ontology = get_ontology(**kwargs)
301
316
  for prefix in sorted(ontology._get_prefixes(), key=str.casefold):
302
317
  click.echo(prefix)
pyobo/cli/utils.py CHANGED
@@ -1,15 +1,19 @@
1
1
  """Utilities for the CLI."""
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  import datetime
4
6
  import pathlib
5
7
  from collections.abc import Callable
6
- from typing import TypeVar
8
+ from typing import TYPE_CHECKING, TypeVar
7
9
 
8
10
  import click
9
- import pandas as pd
10
11
 
11
12
  from ..constants import DATABASE_DIRECTORY
12
13
 
14
+ if TYPE_CHECKING:
15
+ import pandas as pd
16
+
13
17
  __all__ = [
14
18
  "Clickable",
15
19
  "directory_option",
pyobo/constants.py CHANGED
@@ -8,14 +8,26 @@ from collections.abc import Callable
8
8
  from pathlib import Path
9
9
  from typing import Literal, NamedTuple, TypeAlias
10
10
 
11
- import bioregistry
12
11
  import pystow
13
12
  from typing_extensions import NotRequired, TypedDict
14
13
 
15
14
  __all__ = [
16
15
  "DATABASE_DIRECTORY",
16
+ "DEFAULT_PREFIX_MAP",
17
+ "ONTOLOGY_GETTERS",
18
+ "PROVENANCE_PREFIXES",
17
19
  "RAW_DIRECTORY",
18
20
  "SPECIES_REMAPPING",
21
+ "DatabaseKwargs",
22
+ "GetOntologyKwargs",
23
+ "IterHelperHelperDict",
24
+ "LookupKwargs",
25
+ "OntologyFormat",
26
+ "OntologyPathPack",
27
+ "SlimGetOntologyKwargs",
28
+ "check_should_cache",
29
+ "check_should_force",
30
+ "check_should_use_tqdm",
19
31
  ]
20
32
 
21
33
  logger = logging.getLogger(__name__)
@@ -96,6 +108,8 @@ SPECIES_FILE = "species.tsv.gz"
96
108
 
97
109
  NCBITAXON_PREFIX = "ncbitaxon"
98
110
  DATE_FORMAT = "%d:%m:%Y %H:%M"
111
+
112
+ #: Prefixes for resources that are considered as provenance
99
113
  PROVENANCE_PREFIXES = {
100
114
  "pubmed",
101
115
  "pmc",
@@ -117,13 +131,21 @@ PROVENANCE_PREFIXES = {
117
131
  class DatabaseKwargs(TypedDict):
118
132
  """Keyword arguments for database CLI functions."""
119
133
 
134
+ #: Should strict identifier parsing be enabled?
120
135
  strict: bool
136
+ #: Should re-download and re-processing be forced?
121
137
  force: bool
138
+ #: Should re-processing be forced?
122
139
  force_process: bool
123
- skip_pyobo: bool
140
+
141
+ #: Should a progress bar be used?
142
+ use_tqdm: bool
143
+ #: Skip all prefixes lexicographically sorted below the given prefix
124
144
  skip_below: str | None
145
+ #: If true, skips prefixes that are ontologized as sources in PyOBO
146
+ skip_pyobo: bool
147
+ #: An enumerated set of prefixes to skip
125
148
  skip_set: set[str] | None
126
- use_tqdm: bool
127
149
 
128
150
 
129
151
  class SlimGetOntologyKwargs(TypedDict):
@@ -134,8 +156,11 @@ class SlimGetOntologyKwargs(TypedDict):
134
156
  only a single ontology is requested.
135
157
  """
136
158
 
159
+ #: Should strict identifier parsing be enabled?
137
160
  strict: NotRequired[bool]
161
+ #: Should re-download and re-processing be forced?
138
162
  force: NotRequired[bool]
163
+ #: Should re-processing be forced?
139
164
  force_process: NotRequired[bool]
140
165
 
141
166
 
@@ -145,8 +170,11 @@ class GetOntologyKwargs(SlimGetOntologyKwargs):
145
170
  This dictionary doesn't contain ``prefix`` since this is always explicitly handled.
146
171
  """
147
172
 
173
+ #: The version of the ontology to get
148
174
  version: NotRequired[str | None]
175
+ #: Should the cache be used?
149
176
  cache: NotRequired[bool]
177
+ #: Should a progress bar be used?
150
178
  use_tqdm: NotRequired[bool]
151
179
 
152
180
 
@@ -186,12 +214,17 @@ class IterHelperHelperDict(SlimGetOntologyKwargs):
186
214
  :func:`pyobo.get_ontology` in each iteration.
187
215
  """
188
216
 
217
+ #: Should a progress bar be used?
189
218
  use_tqdm: bool
219
+ #: Skip all prefixes lexicographically sorted below the given prefix
190
220
  skip_below: str | None
221
+ #: If true, skips prefixes that are ontologized as sources in PyOBO
191
222
  skip_pyobo: bool
223
+ #: An enumerated set of prefixes to skip
192
224
  skip_set: set[str] | None
193
225
 
194
226
 
227
+ #: The ontology format
195
228
  OntologyFormat: TypeAlias = Literal["obo", "owl", "json", "rdf"]
196
229
 
197
230
  #: from table 2 of the Functional OWL syntax definition
@@ -207,15 +240,41 @@ DEFAULT_PREFIX_MAP = {
207
240
  class OntologyPathPack(NamedTuple):
208
241
  """A format and path tuple."""
209
242
 
243
+ #: The ontology format
210
244
  format: OntologyFormat
245
+ #: The path to the ontology file
211
246
  path: Path
212
247
 
213
248
 
249
+ def _get_obo_download(prefix: str) -> str | None:
250
+ import bioregistry
251
+
252
+ return bioregistry.get_obo_download(prefix)
253
+
254
+
255
+ def _get_owl_download(prefix: str) -> str | None:
256
+ import bioregistry
257
+
258
+ return bioregistry.get_owl_download(prefix)
259
+
260
+
261
+ def _get_json_download(prefix: str) -> str | None:
262
+ import bioregistry
263
+
264
+ return bioregistry.get_json_download(prefix)
265
+
266
+
267
+ def _get_rdf_download(prefix: str) -> str | None:
268
+ import bioregistry
269
+
270
+ return bioregistry.get_rdf_download(prefix)
271
+
272
+
214
273
  #: Functions that get ontology files. Order matters in this list,
215
274
  #: since order implicitly defines priority
216
275
  ONTOLOGY_GETTERS: list[tuple[OntologyFormat, Callable[[str], str | None]]] = [
217
- ("obo", bioregistry.get_obo_download),
218
- ("owl", bioregistry.get_owl_download),
219
- ("json", bioregistry.get_json_download),
220
- ("rdf", bioregistry.get_rdf_download),
276
+ ("obo", _get_obo_download),
277
+ ("owl", _get_owl_download),
278
+ ("json", _get_json_download),
279
+ ("rdf", _get_rdf_download),
221
280
  ]
pyobo/getters.py CHANGED
@@ -45,8 +45,14 @@ from .utils.path import ensure_path, prefix_directory_join
45
45
  from .version import get_git_hash, get_version
46
46
 
47
47
  __all__ = [
48
+ "REQUIRES_NO_ROBOT_CHECK",
49
+ "SKIP",
48
50
  "NoBuildError",
51
+ "UnhandledFormatError",
52
+ "db_output_helper",
49
53
  "get_ontology",
54
+ "iter_helper",
55
+ "iter_helper_helper",
50
56
  ]
51
57
 
52
58
  logger = logging.getLogger(__name__)
@@ -112,8 +118,6 @@ def get_ontology(
112
118
 
113
119
  :returns: An OBO object
114
120
 
115
- :raises OnlyOWLError: If the OBO foundry only has an OWL document for this resource.
116
-
117
121
  Alternate usage if you have a custom url
118
122
 
119
123
  .. code-block:: python
@@ -220,7 +224,8 @@ def _ensure_ontology_path(
220
224
  return None
221
225
 
222
226
 
223
- SKIP = {
227
+ #: A dictioanry of prefixes to skip during full build with reasons as values
228
+ SKIP: dict[str, str] = {
224
229
  "ncbigene": "too big, refs acquired from other dbs",
225
230
  "pubchem.compound": "top big, can't deal with this now",
226
231
  "gaz": "Gazetteer is irrelevant for biology",