pyobo 0.11.2__py3-none-any.whl → 0.12.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.
Files changed (228) hide show
  1. pyobo/.DS_Store +0 -0
  2. pyobo/__init__.py +95 -20
  3. pyobo/__main__.py +0 -0
  4. pyobo/api/__init__.py +81 -10
  5. pyobo/api/alts.py +52 -42
  6. pyobo/api/combine.py +39 -0
  7. pyobo/api/edges.py +68 -0
  8. pyobo/api/hierarchy.py +231 -203
  9. pyobo/api/metadata.py +14 -19
  10. pyobo/api/names.py +207 -127
  11. pyobo/api/properties.py +117 -117
  12. pyobo/api/relations.py +68 -94
  13. pyobo/api/species.py +24 -21
  14. pyobo/api/typedefs.py +11 -11
  15. pyobo/api/utils.py +66 -13
  16. pyobo/api/xrefs.py +107 -114
  17. pyobo/cli/__init__.py +0 -0
  18. pyobo/cli/cli.py +35 -50
  19. pyobo/cli/database.py +210 -160
  20. pyobo/cli/database_utils.py +155 -0
  21. pyobo/cli/lookup.py +163 -195
  22. pyobo/cli/utils.py +19 -6
  23. pyobo/constants.py +102 -3
  24. pyobo/getters.py +209 -191
  25. pyobo/gilda_utils.py +52 -250
  26. pyobo/identifier_utils/__init__.py +33 -0
  27. pyobo/identifier_utils/api.py +305 -0
  28. pyobo/identifier_utils/preprocessing.json +873 -0
  29. pyobo/identifier_utils/preprocessing.py +27 -0
  30. pyobo/identifier_utils/relations/__init__.py +8 -0
  31. pyobo/identifier_utils/relations/api.py +162 -0
  32. pyobo/identifier_utils/relations/data.json +5824 -0
  33. pyobo/identifier_utils/relations/data_owl.json +57 -0
  34. pyobo/identifier_utils/relations/data_rdf.json +1 -0
  35. pyobo/identifier_utils/relations/data_rdfs.json +7 -0
  36. pyobo/mocks.py +9 -6
  37. pyobo/ner/__init__.py +9 -0
  38. pyobo/ner/api.py +72 -0
  39. pyobo/ner/normalizer.py +33 -0
  40. pyobo/obographs.py +48 -40
  41. pyobo/plugins.py +5 -4
  42. pyobo/py.typed +0 -0
  43. pyobo/reader.py +1354 -395
  44. pyobo/reader_utils.py +155 -0
  45. pyobo/resource_utils.py +42 -22
  46. pyobo/resources/__init__.py +0 -0
  47. pyobo/resources/goc.py +75 -0
  48. pyobo/resources/goc.tsv +188 -0
  49. pyobo/resources/ncbitaxon.py +4 -5
  50. pyobo/resources/ncbitaxon.tsv.gz +0 -0
  51. pyobo/resources/ro.py +3 -2
  52. pyobo/resources/ro.tsv +0 -0
  53. pyobo/resources/so.py +0 -0
  54. pyobo/resources/so.tsv +0 -0
  55. pyobo/sources/README.md +12 -8
  56. pyobo/sources/__init__.py +52 -29
  57. pyobo/sources/agrovoc.py +0 -0
  58. pyobo/sources/antibodyregistry.py +11 -12
  59. pyobo/sources/bigg/__init__.py +13 -0
  60. pyobo/sources/bigg/bigg_compartment.py +81 -0
  61. pyobo/sources/bigg/bigg_metabolite.py +229 -0
  62. pyobo/sources/bigg/bigg_model.py +46 -0
  63. pyobo/sources/bigg/bigg_reaction.py +77 -0
  64. pyobo/sources/biogrid.py +1 -2
  65. pyobo/sources/ccle.py +7 -12
  66. pyobo/sources/cgnc.py +9 -6
  67. pyobo/sources/chebi.py +1 -1
  68. pyobo/sources/chembl/__init__.py +9 -0
  69. pyobo/sources/{chembl.py → chembl/chembl_compound.py} +13 -25
  70. pyobo/sources/chembl/chembl_target.py +160 -0
  71. pyobo/sources/civic_gene.py +55 -15
  72. pyobo/sources/clinicaltrials.py +160 -0
  73. pyobo/sources/complexportal.py +24 -24
  74. pyobo/sources/conso.py +14 -22
  75. pyobo/sources/cpt.py +0 -0
  76. pyobo/sources/credit.py +1 -9
  77. pyobo/sources/cvx.py +27 -5
  78. pyobo/sources/depmap.py +9 -12
  79. pyobo/sources/dictybase_gene.py +2 -7
  80. pyobo/sources/drugbank/__init__.py +9 -0
  81. pyobo/sources/{drugbank.py → drugbank/drugbank.py} +11 -16
  82. pyobo/sources/{drugbank_salt.py → drugbank/drugbank_salt.py} +3 -8
  83. pyobo/sources/drugcentral.py +17 -13
  84. pyobo/sources/expasy.py +31 -34
  85. pyobo/sources/famplex.py +13 -18
  86. pyobo/sources/flybase.py +8 -13
  87. pyobo/sources/gard.py +62 -0
  88. pyobo/sources/geonames/__init__.py +9 -0
  89. pyobo/sources/geonames/features.py +28 -0
  90. pyobo/sources/{geonames.py → geonames/geonames.py} +87 -26
  91. pyobo/sources/geonames/utils.py +115 -0
  92. pyobo/sources/gmt_utils.py +6 -7
  93. pyobo/sources/go.py +20 -13
  94. pyobo/sources/gtdb.py +154 -0
  95. pyobo/sources/gwascentral/__init__.py +9 -0
  96. pyobo/sources/{gwascentral_phenotype.py → gwascentral/gwascentral_phenotype.py} +5 -7
  97. pyobo/sources/{gwascentral_study.py → gwascentral/gwascentral_study.py} +1 -7
  98. pyobo/sources/hgnc/__init__.py +9 -0
  99. pyobo/sources/{hgnc.py → hgnc/hgnc.py} +56 -70
  100. pyobo/sources/{hgncgenefamily.py → hgnc/hgncgenefamily.py} +8 -18
  101. pyobo/sources/icd/__init__.py +9 -0
  102. pyobo/sources/{icd10.py → icd/icd10.py} +35 -37
  103. pyobo/sources/icd/icd11.py +148 -0
  104. pyobo/sources/{icd_utils.py → icd/icd_utils.py} +66 -20
  105. pyobo/sources/interpro.py +4 -9
  106. pyobo/sources/itis.py +0 -5
  107. pyobo/sources/kegg/__init__.py +0 -0
  108. pyobo/sources/kegg/api.py +16 -38
  109. pyobo/sources/kegg/genes.py +9 -20
  110. pyobo/sources/kegg/genome.py +1 -7
  111. pyobo/sources/kegg/pathway.py +9 -21
  112. pyobo/sources/mesh.py +58 -24
  113. pyobo/sources/mgi.py +3 -10
  114. pyobo/sources/mirbase/__init__.py +11 -0
  115. pyobo/sources/{mirbase.py → mirbase/mirbase.py} +8 -11
  116. pyobo/sources/{mirbase_constants.py → mirbase/mirbase_constants.py} +0 -0
  117. pyobo/sources/{mirbase_family.py → mirbase/mirbase_family.py} +4 -8
  118. pyobo/sources/{mirbase_mature.py → mirbase/mirbase_mature.py} +3 -7
  119. pyobo/sources/msigdb.py +74 -39
  120. pyobo/sources/ncbi/__init__.py +9 -0
  121. pyobo/sources/ncbi/ncbi_gc.py +162 -0
  122. pyobo/sources/{ncbigene.py → ncbi/ncbigene.py} +18 -19
  123. pyobo/sources/nih_reporter.py +60 -0
  124. pyobo/sources/nlm/__init__.py +9 -0
  125. pyobo/sources/nlm/nlm_catalog.py +48 -0
  126. pyobo/sources/nlm/nlm_publisher.py +36 -0
  127. pyobo/sources/nlm/utils.py +116 -0
  128. pyobo/sources/npass.py +6 -8
  129. pyobo/sources/omim_ps.py +11 -4
  130. pyobo/sources/pathbank.py +4 -8
  131. pyobo/sources/pfam/__init__.py +9 -0
  132. pyobo/sources/{pfam.py → pfam/pfam.py} +3 -8
  133. pyobo/sources/{pfam_clan.py → pfam/pfam_clan.py} +2 -7
  134. pyobo/sources/pharmgkb/__init__.py +15 -0
  135. pyobo/sources/pharmgkb/pharmgkb_chemical.py +89 -0
  136. pyobo/sources/pharmgkb/pharmgkb_disease.py +77 -0
  137. pyobo/sources/pharmgkb/pharmgkb_gene.py +108 -0
  138. pyobo/sources/pharmgkb/pharmgkb_pathway.py +63 -0
  139. pyobo/sources/pharmgkb/pharmgkb_variant.py +84 -0
  140. pyobo/sources/pharmgkb/utils.py +86 -0
  141. pyobo/sources/pid.py +1 -6
  142. pyobo/sources/pombase.py +6 -10
  143. pyobo/sources/pubchem.py +4 -9
  144. pyobo/sources/reactome.py +5 -11
  145. pyobo/sources/rgd.py +11 -16
  146. pyobo/sources/rhea.py +37 -36
  147. pyobo/sources/ror.py +69 -42
  148. pyobo/sources/selventa/__init__.py +0 -0
  149. pyobo/sources/selventa/schem.py +4 -7
  150. pyobo/sources/selventa/scomp.py +1 -6
  151. pyobo/sources/selventa/sdis.py +4 -7
  152. pyobo/sources/selventa/sfam.py +1 -6
  153. pyobo/sources/sgd.py +6 -11
  154. pyobo/sources/signor/__init__.py +7 -0
  155. pyobo/sources/signor/download.py +41 -0
  156. pyobo/sources/signor/signor_complexes.py +105 -0
  157. pyobo/sources/slm.py +12 -15
  158. pyobo/sources/umls/__init__.py +7 -1
  159. pyobo/sources/umls/__main__.py +0 -0
  160. pyobo/sources/umls/get_synonym_types.py +20 -4
  161. pyobo/sources/umls/sty.py +57 -0
  162. pyobo/sources/umls/synonym_types.tsv +1 -1
  163. pyobo/sources/umls/umls.py +18 -22
  164. pyobo/sources/unimod.py +46 -0
  165. pyobo/sources/uniprot/__init__.py +1 -1
  166. pyobo/sources/uniprot/uniprot.py +40 -32
  167. pyobo/sources/uniprot/uniprot_ptm.py +4 -34
  168. pyobo/sources/utils.py +3 -2
  169. pyobo/sources/wikipathways.py +7 -10
  170. pyobo/sources/zfin.py +5 -10
  171. pyobo/ssg/__init__.py +12 -16
  172. pyobo/ssg/base.html +0 -0
  173. pyobo/ssg/index.html +26 -13
  174. pyobo/ssg/term.html +12 -2
  175. pyobo/ssg/typedef.html +0 -0
  176. pyobo/struct/__init__.py +54 -8
  177. pyobo/struct/functional/__init__.py +1 -0
  178. pyobo/struct/functional/dsl.py +2572 -0
  179. pyobo/struct/functional/macros.py +423 -0
  180. pyobo/struct/functional/obo_to_functional.py +385 -0
  181. pyobo/struct/functional/ontology.py +272 -0
  182. pyobo/struct/functional/utils.py +112 -0
  183. pyobo/struct/reference.py +331 -136
  184. pyobo/struct/struct.py +1484 -657
  185. pyobo/struct/struct_utils.py +1078 -0
  186. pyobo/struct/typedef.py +162 -210
  187. pyobo/struct/utils.py +12 -5
  188. pyobo/struct/vocabulary.py +138 -0
  189. pyobo/utils/__init__.py +0 -0
  190. pyobo/utils/cache.py +16 -15
  191. pyobo/utils/io.py +51 -41
  192. pyobo/utils/iter.py +5 -5
  193. pyobo/utils/misc.py +41 -53
  194. pyobo/utils/ndex_utils.py +0 -0
  195. pyobo/utils/path.py +73 -70
  196. pyobo/version.py +3 -3
  197. pyobo-0.12.1.dist-info/METADATA +671 -0
  198. pyobo-0.12.1.dist-info/RECORD +201 -0
  199. pyobo-0.12.1.dist-info/WHEEL +4 -0
  200. {pyobo-0.11.2.dist-info → pyobo-0.12.1.dist-info}/entry_points.txt +1 -0
  201. pyobo-0.12.1.dist-info/licenses/LICENSE +21 -0
  202. pyobo/aws.py +0 -162
  203. pyobo/cli/aws.py +0 -47
  204. pyobo/identifier_utils.py +0 -142
  205. pyobo/normalizer.py +0 -232
  206. pyobo/registries/__init__.py +0 -16
  207. pyobo/registries/metaregistry.json +0 -507
  208. pyobo/registries/metaregistry.py +0 -135
  209. pyobo/sources/icd11.py +0 -105
  210. pyobo/xrefdb/__init__.py +0 -1
  211. pyobo/xrefdb/canonicalizer.py +0 -214
  212. pyobo/xrefdb/priority.py +0 -59
  213. pyobo/xrefdb/sources/__init__.py +0 -60
  214. pyobo/xrefdb/sources/biomappings.py +0 -36
  215. pyobo/xrefdb/sources/cbms2019.py +0 -91
  216. pyobo/xrefdb/sources/chembl.py +0 -83
  217. pyobo/xrefdb/sources/compath.py +0 -82
  218. pyobo/xrefdb/sources/famplex.py +0 -64
  219. pyobo/xrefdb/sources/gilda.py +0 -50
  220. pyobo/xrefdb/sources/intact.py +0 -113
  221. pyobo/xrefdb/sources/ncit.py +0 -133
  222. pyobo/xrefdb/sources/pubchem.py +0 -27
  223. pyobo/xrefdb/sources/wikidata.py +0 -116
  224. pyobo/xrefdb/xrefs_pipeline.py +0 -180
  225. pyobo-0.11.2.dist-info/METADATA +0 -711
  226. pyobo-0.11.2.dist-info/RECORD +0 -157
  227. pyobo-0.11.2.dist-info/WHEEL +0 -5
  228. pyobo-0.11.2.dist-info/top_level.txt +0 -1
pyobo/.DS_Store ADDED
Binary file
pyobo/__init__.py CHANGED
@@ -1,11 +1,13 @@
1
1
  """A python package for handling and generating OBO."""
2
2
 
3
- from .api import ( # noqa: F401
3
+ from .api import (
4
4
  get_alts_to_id,
5
5
  get_ancestors,
6
6
  get_children,
7
7
  get_definition,
8
8
  get_descendants,
9
+ get_edges,
10
+ get_edges_df,
9
11
  get_filtered_properties_df,
10
12
  get_filtered_properties_mapping,
11
13
  get_filtered_properties_multimapping,
@@ -20,15 +22,25 @@ from .api import ( # noqa: F401
20
22
  get_id_synonyms_mapping,
21
23
  get_id_to_alts,
22
24
  get_ids,
25
+ get_literal_mappings,
26
+ get_literal_mappings_df,
27
+ get_literal_mappings_subset,
28
+ get_literal_properties,
29
+ get_literal_properties_df,
30
+ get_mappings_df,
31
+ get_metadata,
23
32
  get_name,
24
33
  get_name_by_curie,
25
34
  get_name_id_mapping,
35
+ get_object_properties,
36
+ get_object_properties_df,
26
37
  get_obsolete,
27
38
  get_primary_curie,
28
39
  get_primary_identifier,
29
40
  get_properties,
30
41
  get_properties_df,
31
42
  get_property,
43
+ get_references,
32
44
  get_relation,
33
45
  get_relation_mapping,
34
46
  get_relations_df,
@@ -43,26 +55,89 @@ from .api import ( # noqa: F401
43
55
  has_ancestor,
44
56
  is_descendent,
45
57
  )
46
- from .getters import get_ontology # noqa: F401
47
- from .identifier_utils import normalize_curie # noqa: F401
48
- from .normalizer import OboNormalizer, ground # noqa: F401
49
- from .obographs import parse_results_from_obo # noqa: F401
50
- from .plugins import ( # noqa: F401
58
+ from .getters import get_ontology
59
+ from .ner import get_grounder, ground
60
+ from .obographs import parse_results_from_obo
61
+ from .plugins import (
51
62
  has_nomenclature_plugin,
52
63
  iter_nomenclature_plugins,
53
64
  run_nomenclature_plugin,
54
65
  )
55
- from .reader import from_obo_path, from_obonet # noqa: F401
56
- from .struct import Obo, Reference, Synonym, SynonymTypeDef, Term, TypeDef # noqa: F401
57
- from .utils.path import ensure_path # noqa: F401
58
- from .version import get_version # noqa: F401
59
- from .xrefdb.canonicalizer import ( # noqa: F401
60
- Canonicalizer,
61
- get_equivalent,
62
- get_priority_curie,
63
- )
64
- from .xrefdb.sources import ( # noqa: F401
65
- has_xref_plugin,
66
- iter_xref_plugins,
67
- run_xref_plugin,
68
- )
66
+ from .reader import from_obo_path, from_obonet
67
+ from .struct import Obo, Reference, Synonym, SynonymTypeDef, Term, TypeDef, default_reference
68
+ from .utils.path import ensure_path
69
+ from .version import get_version
70
+
71
+ __all__ = [
72
+ "Obo",
73
+ "Reference",
74
+ "Synonym",
75
+ "SynonymTypeDef",
76
+ "Term",
77
+ "TypeDef",
78
+ "default_reference",
79
+ "ensure_path",
80
+ "from_obo_path",
81
+ "from_obonet",
82
+ "get_alts_to_id",
83
+ "get_ancestors",
84
+ "get_children",
85
+ "get_definition",
86
+ "get_descendants",
87
+ "get_edges",
88
+ "get_edges_df",
89
+ "get_filtered_properties_df",
90
+ "get_filtered_properties_mapping",
91
+ "get_filtered_properties_multimapping",
92
+ "get_filtered_relations_df",
93
+ "get_filtered_xrefs",
94
+ "get_graph",
95
+ "get_grounder",
96
+ "get_hierarchy",
97
+ "get_id_definition_mapping",
98
+ "get_id_multirelations_mapping",
99
+ "get_id_name_mapping",
100
+ "get_id_species_mapping",
101
+ "get_id_synonyms_mapping",
102
+ "get_id_to_alts",
103
+ "get_ids",
104
+ "get_literal_mappings",
105
+ "get_literal_mappings_df",
106
+ "get_literal_mappings_subset",
107
+ "get_literal_properties",
108
+ "get_literal_properties_df",
109
+ "get_mappings_df",
110
+ "get_metadata",
111
+ "get_name",
112
+ "get_name_by_curie",
113
+ "get_name_id_mapping",
114
+ "get_object_properties",
115
+ "get_object_properties_df",
116
+ "get_obsolete",
117
+ "get_ontology",
118
+ "get_primary_curie",
119
+ "get_primary_identifier",
120
+ "get_properties",
121
+ "get_properties_df",
122
+ "get_property",
123
+ "get_references",
124
+ "get_relation",
125
+ "get_relation_mapping",
126
+ "get_relations_df",
127
+ "get_species",
128
+ "get_sssom_df",
129
+ "get_subhierarchy",
130
+ "get_synonyms",
131
+ "get_typedef_df",
132
+ "get_version",
133
+ "get_xref",
134
+ "get_xrefs",
135
+ "get_xrefs_df",
136
+ "ground",
137
+ "has_ancestor",
138
+ "has_nomenclature_plugin",
139
+ "is_descendent",
140
+ "iter_nomenclature_plugins",
141
+ "parse_results_from_obo",
142
+ "run_nomenclature_plugin",
143
+ ]
pyobo/__main__.py CHANGED
File without changes
pyobo/api/__init__.py CHANGED
@@ -1,12 +1,14 @@
1
1
  """High-level API for accessing content."""
2
2
 
3
- from .alts import ( # noqa: F401
3
+ from .alts import (
4
4
  get_alts_to_id,
5
5
  get_id_to_alts,
6
6
  get_primary_curie,
7
7
  get_primary_identifier,
8
8
  )
9
- from .hierarchy import ( # noqa: F401
9
+ from .combine import get_literal_mappings_subset
10
+ from .edges import get_edges, get_edges_df, get_graph
11
+ from .hierarchy import (
10
12
  get_ancestors,
11
13
  get_children,
12
14
  get_descendants,
@@ -15,41 +17,110 @@ from .hierarchy import ( # noqa: F401
15
17
  has_ancestor,
16
18
  is_descendent,
17
19
  )
18
- from .metadata import get_metadata # noqa: F401
19
- from .names import ( # noqa: F401
20
+ from .metadata import get_metadata
21
+ from .names import (
20
22
  get_definition,
21
23
  get_id_definition_mapping,
22
24
  get_id_name_mapping,
23
25
  get_id_synonyms_mapping,
24
26
  get_ids,
27
+ get_literal_mappings,
28
+ get_literal_mappings_df,
25
29
  get_name,
26
30
  get_name_by_curie,
27
31
  get_name_id_mapping,
28
32
  get_obsolete,
33
+ get_obsolete_references,
34
+ get_references,
29
35
  get_synonyms,
30
36
  )
31
- from .properties import ( # noqa: F401
37
+ from .properties import (
32
38
  get_filtered_properties_df,
33
39
  get_filtered_properties_mapping,
34
40
  get_filtered_properties_multimapping,
41
+ get_literal_properties,
42
+ get_literal_properties_df,
43
+ get_object_properties,
44
+ get_object_properties_df,
35
45
  get_properties,
36
46
  get_properties_df,
37
47
  get_property,
38
48
  )
39
- from .relations import ( # noqa: F401
49
+ from .relations import (
40
50
  get_filtered_relations_df,
41
- get_graph,
42
51
  get_id_multirelations_mapping,
43
52
  get_relation,
44
53
  get_relation_mapping,
45
54
  get_relations_df,
46
55
  )
47
- from .species import get_id_species_mapping, get_species # noqa: F401
48
- from .typedefs import get_typedef_df # noqa: F401
49
- from .xrefs import ( # noqa: F401
56
+ from .species import get_id_species_mapping, get_species
57
+ from .typedefs import get_typedef_df
58
+ from .xrefs import (
50
59
  get_filtered_xrefs,
60
+ get_mappings_df,
51
61
  get_sssom_df,
52
62
  get_xref,
53
63
  get_xrefs,
54
64
  get_xrefs_df,
55
65
  )
66
+
67
+ __all__ = [
68
+ "get_alts_to_id",
69
+ "get_ancestors",
70
+ "get_children",
71
+ "get_definition",
72
+ "get_descendants",
73
+ "get_edges",
74
+ "get_edges_df",
75
+ "get_equivalent",
76
+ "get_filtered_properties_df",
77
+ "get_filtered_properties_mapping",
78
+ "get_filtered_properties_multimapping",
79
+ "get_filtered_relations_df",
80
+ "get_filtered_xrefs",
81
+ "get_graph",
82
+ "get_hierarchy",
83
+ "get_id_definition_mapping",
84
+ "get_id_multirelations_mapping",
85
+ "get_id_name_mapping",
86
+ "get_id_species_mapping",
87
+ "get_id_synonyms_mapping",
88
+ "get_id_to_alts",
89
+ "get_ids",
90
+ "get_literal_mappings",
91
+ "get_literal_mappings_df",
92
+ "get_literal_mappings_subset",
93
+ "get_literal_properties",
94
+ "get_literal_properties_df",
95
+ "get_mappings_df",
96
+ "get_metadata",
97
+ "get_name",
98
+ "get_name_by_curie",
99
+ "get_name_id_mapping",
100
+ "get_object_properties",
101
+ "get_object_properties_df",
102
+ "get_obsolete",
103
+ "get_obsolete_references",
104
+ "get_ontology",
105
+ "get_primary_curie",
106
+ "get_primary_identifier",
107
+ "get_priority_curie",
108
+ "get_properties",
109
+ "get_properties_df",
110
+ "get_property",
111
+ "get_references",
112
+ "get_relation",
113
+ "get_relation_mapping",
114
+ "get_relations_df",
115
+ "get_species",
116
+ "get_sssom_df",
117
+ "get_subhierarchy",
118
+ "get_synonyms",
119
+ "get_typedef_df",
120
+ "get_version",
121
+ "get_xref",
122
+ "get_xrefs",
123
+ "get_xrefs_df",
124
+ "has_ancestor",
125
+ "is_descendent",
126
+ ]
pyobo/api/alts.py CHANGED
@@ -3,17 +3,21 @@
3
3
  import logging
4
4
  from collections.abc import Mapping
5
5
  from functools import lru_cache
6
- from typing import Optional
7
6
 
8
- from .utils import get_version
7
+ import curies
8
+ from pydantic import ValidationError
9
+ from typing_extensions import Unpack
10
+
11
+ from .utils import _get_pi, get_version_from_kwargs
12
+ from ..constants import GetOntologyKwargs, check_should_cache, check_should_force
9
13
  from ..getters import get_ontology
10
- from ..identifier_utils import normalize_curie, wrap_norm_prefix
14
+ from ..identifier_utils import wrap_norm_prefix
11
15
  from ..utils.cache import cached_multidict
12
- from ..utils.path import prefix_cache_join
16
+ from ..utils.path import CacheArtifact, get_cache_path
13
17
 
14
18
  __all__ = [
15
- "get_id_to_alts",
16
19
  "get_alts_to_id",
20
+ "get_id_to_alts",
17
21
  "get_primary_curie",
18
22
  "get_primary_identifier",
19
23
  ]
@@ -27,25 +31,22 @@ NO_ALTS = {
27
31
 
28
32
  @lru_cache
29
33
  @wrap_norm_prefix
30
- def get_id_to_alts(
31
- prefix: str, *, force: bool = False, version: Optional[str] = None
32
- ) -> Mapping[str, list[str]]:
34
+ def get_id_to_alts(prefix: str, **kwargs: Unpack[GetOntologyKwargs]) -> Mapping[str, list[str]]:
33
35
  """Get alternate identifiers."""
34
36
  if prefix in NO_ALTS:
35
37
  return {}
36
38
 
37
- if version is None:
38
- version = get_version(prefix)
39
- path = prefix_cache_join(prefix, name="alt_ids.tsv", version=version)
40
- header = [f"{prefix}_id", "alt_id"]
39
+ version = get_version_from_kwargs(prefix, kwargs)
40
+ path = get_cache_path(prefix, CacheArtifact.alts, version=version)
41
41
 
42
- @cached_multidict(path=path, header=header, force=force)
42
+ @cached_multidict(
43
+ path=path,
44
+ header=[f"{prefix}_id", "alt_id"],
45
+ cache=check_should_cache(kwargs),
46
+ force=check_should_force(kwargs),
47
+ )
43
48
  def _get_mapping() -> Mapping[str, list[str]]:
44
- if force:
45
- logger.info(f"[{prefix}] forcing reload for alts")
46
- else:
47
- logger.info("[%s] no cached alts found. getting from OBO loader", prefix)
48
- ontology = get_ontology(prefix, force=force, version=version)
49
+ ontology = get_ontology(prefix, **kwargs)
49
50
  return ontology.get_id_alts_mapping()
50
51
 
51
52
  return _get_mapping()
@@ -53,40 +54,49 @@ def get_id_to_alts(
53
54
 
54
55
  @lru_cache
55
56
  @wrap_norm_prefix
56
- def get_alts_to_id(
57
- prefix: str, *, force: bool = False, version: Optional[str] = None
58
- ) -> Mapping[str, str]:
57
+ def get_alts_to_id(prefix: str, **kwargs: Unpack[GetOntologyKwargs]) -> Mapping[str, str]:
59
58
  """Get alternative id to primary id mapping."""
60
59
  return {
61
- alt: primary
62
- for primary, alts in get_id_to_alts(prefix, force=force, version=version).items()
63
- for alt in alts
60
+ alt: primary for primary, alts in get_id_to_alts(prefix, **kwargs).items() for alt in alts
64
61
  }
65
62
 
66
63
 
67
- def get_primary_curie(curie: str, *, version: Optional[str] = None) -> Optional[str]:
64
+ def get_primary_curie(
65
+ prefix: str | curies.Reference | curies.ReferenceTuple,
66
+ identifier: str | None = None,
67
+ /,
68
+ **kwargs: Unpack[GetOntologyKwargs],
69
+ ) -> str | None:
68
70
  """Get the primary curie for an entity."""
69
- prefix, identifier = normalize_curie(curie)
70
- primary_identifier = get_primary_identifier(prefix, identifier, version=version)
71
- if primary_identifier is not None:
72
- return f"{prefix}:{primary_identifier}"
73
- return None
74
-
75
-
76
- @wrap_norm_prefix
77
- def get_primary_identifier(prefix: str, identifier: str, *, version: Optional[str] = None) -> str:
71
+ reference = _get_pi(prefix, identifier)
72
+ try:
73
+ primary_identifier = get_primary_identifier(reference, **kwargs)
74
+ except (ValueError, ValidationError):
75
+ if kwargs.get("strict"):
76
+ raise
77
+ # this happens on invalid prefix. maybe revise?
78
+ return None
79
+ return f"{reference.prefix}:{primary_identifier}"
80
+
81
+
82
+ def get_primary_identifier(
83
+ prefix: str | curies.Reference | curies.ReferenceTuple,
84
+ identifier: str | None = None,
85
+ /,
86
+ **kwargs: Unpack[GetOntologyKwargs],
87
+ ) -> str:
78
88
  """Get the primary identifier for an entity.
79
89
 
80
90
  :param prefix: The name of the resource
81
91
  :param identifier: The identifier to look up
92
+
82
93
  :returns: the canonical identifier based on alt id lookup
83
94
 
84
- Returns the original identifier if there are no alts available or if there's no mapping.
95
+ Returns the original identifier if there are no alts available or if there's no
96
+ mapping.
85
97
  """
86
- if prefix in NO_ALTS: # TODO later expand list to other namespaces with no alts
87
- return identifier
88
-
89
- alts_to_id = get_alts_to_id(prefix, version=version)
90
- if alts_to_id and identifier in alts_to_id:
91
- return alts_to_id[identifier]
92
- return identifier
98
+ t = _get_pi(prefix, identifier)
99
+ if t.prefix in NO_ALTS: # TODO later expand list to other namespaces with no alts
100
+ return t.identifier
101
+ alts_to_id = get_alts_to_id(t.prefix, **kwargs)
102
+ return alts_to_id.get(t.identifier, t.identifier)
pyobo/api/combine.py ADDED
@@ -0,0 +1,39 @@
1
+ """Functions that combine other API aspects."""
2
+
3
+ from collections.abc import Sequence
4
+
5
+ import curies
6
+ import ssslm
7
+ from typing_extensions import Unpack
8
+
9
+ from pyobo.api.hierarchy import get_descendants
10
+ from pyobo.api.names import get_literal_mappings
11
+ from pyobo.constants import GetOntologyKwargs
12
+ from pyobo.struct import Reference
13
+
14
+ __all__ = [
15
+ "get_literal_mappings_subset",
16
+ ]
17
+
18
+
19
+ def get_literal_mappings_subset(
20
+ prefix: str,
21
+ ancestors: curies.Reference | Sequence[curies.Reference],
22
+ *,
23
+ skip_obsolete: bool = False,
24
+ **kwargs: Unpack[GetOntologyKwargs],
25
+ ) -> list[ssslm.LiteralMapping]:
26
+ """Get a subset of literal mappings under the given ancestors."""
27
+ if isinstance(ancestors, curies.Reference):
28
+ ancestors = [ancestors]
29
+
30
+ subset: set[Reference] = {
31
+ descendant
32
+ for ancestor in ancestors
33
+ for descendant in get_descendants(ancestor, **kwargs) or []
34
+ }
35
+ return [
36
+ literal_mapping
37
+ for literal_mapping in get_literal_mappings(prefix, skip_obsolete=skip_obsolete, **kwargs)
38
+ if literal_mapping.reference in subset
39
+ ]
pyobo/api/edges.py ADDED
@@ -0,0 +1,68 @@
1
+ """High-level API for edges."""
2
+
3
+ import networkx as nx
4
+ import pandas as pd
5
+ from tqdm import tqdm
6
+ from typing_extensions import Unpack
7
+
8
+ from pyobo.api.names import get_ids
9
+ from pyobo.api.utils import get_version_from_kwargs
10
+ from pyobo.constants import (
11
+ GetOntologyKwargs,
12
+ check_should_cache,
13
+ check_should_force,
14
+ check_should_use_tqdm,
15
+ )
16
+ from pyobo.getters import get_ontology
17
+
18
+ from ..struct import Reference
19
+ from ..utils.cache import cached_df
20
+ from ..utils.path import CacheArtifact, get_cache_path
21
+
22
+ __all__ = [
23
+ "get_edges",
24
+ "get_edges_df",
25
+ "get_graph",
26
+ ]
27
+
28
+
29
+ def get_graph(prefix: str, **kwargs: Unpack[GetOntologyKwargs]) -> nx.DiGraph:
30
+ """Get the relation graph."""
31
+ rv = nx.MultiDiGraph()
32
+ for s in get_ids(prefix, **kwargs):
33
+ rv.add_node(f"{prefix}:{s}")
34
+ df = get_edges_df(prefix=prefix, **kwargs)
35
+ for s, p, o in df.values:
36
+ rv.add_edge(s, p, key=o)
37
+ return rv
38
+
39
+
40
+ def get_edges_df(prefix, **kwargs: Unpack[GetOntologyKwargs]) -> pd.DataFrame:
41
+ """Get a dataframe of edges triples."""
42
+ version = get_version_from_kwargs(prefix, kwargs)
43
+ path = get_cache_path(prefix, CacheArtifact.edges, version=version)
44
+
45
+ @cached_df(
46
+ path=path, dtype=str, force=check_should_force(kwargs), cache=check_should_cache(kwargs)
47
+ )
48
+ def _df_getter() -> pd.DataFrame:
49
+ return get_ontology(prefix, **kwargs).get_edges_df(use_tqdm=check_should_use_tqdm(kwargs))
50
+
51
+ return _df_getter()
52
+
53
+
54
+ def get_edges(
55
+ prefix, **kwargs: Unpack[GetOntologyKwargs]
56
+ ) -> list[tuple[Reference, Reference, Reference]]:
57
+ """Get a list of edge triples."""
58
+ df = get_edges_df(prefix, **kwargs)
59
+ return [
60
+ (Reference.from_curie(s), Reference.from_curie(p), Reference.from_curie(o))
61
+ for s, p, o in tqdm(
62
+ df.values,
63
+ desc=f"[{prefix}] parsing edges",
64
+ unit="edge",
65
+ unit_scale=True,
66
+ disable=not check_should_use_tqdm(kwargs),
67
+ )
68
+ ]