pyobo 0.12.2__py3-none-any.whl → 0.12.3__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 +12 -4
- pyobo/getters.py +10 -3
- pyobo/identifier_utils/__init__.py +2 -0
- pyobo/identifier_utils/api.py +3 -2
- pyobo/sources/__init__.py +2 -0
- pyobo/sources/drugbank/drugbank.py +1 -1
- pyobo/sources/gwascentral/gwascentral_study.py +1 -1
- pyobo/sources/intact.py +79 -0
- pyobo/struct/__init__.py +2 -1
- pyobo/struct/functional/ontology.py +2 -2
- pyobo/struct/obo/__init__.py +9 -0
- pyobo/{reader.py → struct/obo/reader.py} +21 -18
- pyobo/struct/obograph/__init__.py +16 -0
- pyobo/struct/obograph/export.py +315 -0
- pyobo/struct/obograph/reader.py +242 -0
- pyobo/struct/obograph/utils.py +47 -0
- pyobo/struct/struct.py +13 -23
- pyobo/struct/struct_utils.py +22 -14
- pyobo/struct/typedef.py +4 -0
- pyobo/struct/vocabulary.py +7 -0
- pyobo/version.py +1 -1
- {pyobo-0.12.2.dist-info → pyobo-0.12.3.dist-info}/METADATA +3 -2
- {pyobo-0.12.2.dist-info → pyobo-0.12.3.dist-info}/RECORD +27 -22
- pyobo/obographs.py +0 -152
- /pyobo/{reader_utils.py → struct/obo/reader_utils.py} +0 -0
- {pyobo-0.12.2.dist-info → pyobo-0.12.3.dist-info}/WHEEL +0 -0
- {pyobo-0.12.2.dist-info → pyobo-0.12.3.dist-info}/entry_points.txt +0 -0
- {pyobo-0.12.2.dist-info → pyobo-0.12.3.dist-info}/licenses/LICENSE +0 -0
pyobo/obographs.py
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"""Convert PyOBO into OBO Graph."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import logging
|
|
6
|
-
from collections.abc import Iterable
|
|
7
|
-
from typing import TYPE_CHECKING
|
|
8
|
-
|
|
9
|
-
import bioregistry
|
|
10
|
-
from bioontologies.obograph import (
|
|
11
|
-
Definition,
|
|
12
|
-
Edge,
|
|
13
|
-
Graph,
|
|
14
|
-
GraphDocument,
|
|
15
|
-
Meta,
|
|
16
|
-
Node,
|
|
17
|
-
Synonym,
|
|
18
|
-
Xref,
|
|
19
|
-
)
|
|
20
|
-
from tqdm import tqdm
|
|
21
|
-
|
|
22
|
-
from pyobo.struct import Obo, OBOLiteral, Reference, Term
|
|
23
|
-
from pyobo.struct.typedef import definition_source, is_a
|
|
24
|
-
|
|
25
|
-
if TYPE_CHECKING:
|
|
26
|
-
from bioontologies.robot import ParseResults
|
|
27
|
-
|
|
28
|
-
__all__ = [
|
|
29
|
-
"graph_from_obo",
|
|
30
|
-
"parse_results_from_obo",
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
logger = logging.getLogger(__name__)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def parse_results_from_obo(obo: Obo) -> ParseResults:
|
|
37
|
-
"""Get parse results from an OBO graph."""
|
|
38
|
-
graph = graph_from_obo(obo)
|
|
39
|
-
from bioontologies.robot import ParseResults
|
|
40
|
-
|
|
41
|
-
return ParseResults(graph_document=GraphDocument(graphs=[graph]))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def graph_from_obo(obo: Obo, use_tqdm: bool = True) -> Graph:
|
|
45
|
-
"""Get an OBO Graph object from a PyOBO object."""
|
|
46
|
-
nodes: list[Node] = []
|
|
47
|
-
edges: list[Edge] = []
|
|
48
|
-
for term in tqdm(
|
|
49
|
-
obo,
|
|
50
|
-
disable=not use_tqdm,
|
|
51
|
-
unit="term",
|
|
52
|
-
unit_scale=True,
|
|
53
|
-
desc=f"[{obo._prefix_version}] to OBO Graph JSON",
|
|
54
|
-
):
|
|
55
|
-
nodes.append(_get_class_node(term))
|
|
56
|
-
edges.extend(_iter_edges(term))
|
|
57
|
-
return Graph(
|
|
58
|
-
id=bioregistry.get_bioregistry_iri("bioregistry", obo.ontology),
|
|
59
|
-
prefix=obo.ontology,
|
|
60
|
-
meta=_get_meta(obo),
|
|
61
|
-
nodes=nodes,
|
|
62
|
-
edges=edges,
|
|
63
|
-
standardized=True, # from construction :)
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def _get_meta(obo: Obo) -> Meta:
|
|
68
|
-
return Meta(
|
|
69
|
-
version=obo.data_version,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def _get_class_node(term: Term) -> Node:
|
|
74
|
-
if term.provenance or term.definition:
|
|
75
|
-
definition = Definition.from_parsed(
|
|
76
|
-
value=term.definition, references=_prep_prov(term.provenance)
|
|
77
|
-
)
|
|
78
|
-
else:
|
|
79
|
-
definition = None
|
|
80
|
-
xrefs = [
|
|
81
|
-
Xref.from_parsed(
|
|
82
|
-
predicate=Reference.from_reference(mapping_predicate),
|
|
83
|
-
value=Reference.from_reference(mapping_object),
|
|
84
|
-
)
|
|
85
|
-
for mapping_predicate, mapping_object in term.get_mappings(
|
|
86
|
-
include_xrefs=True, add_context=False
|
|
87
|
-
)
|
|
88
|
-
]
|
|
89
|
-
synonyms = [
|
|
90
|
-
Synonym.from_parsed(
|
|
91
|
-
name=synonym.name,
|
|
92
|
-
predicate=Reference.from_reference(synonym.predicate),
|
|
93
|
-
synonym_type=Reference.from_reference(synonym.type) if synonym.type else None,
|
|
94
|
-
references=_prep_prov(synonym.provenance),
|
|
95
|
-
)
|
|
96
|
-
for synonym in term.synonyms
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
meta = Meta(
|
|
100
|
-
definition=definition,
|
|
101
|
-
xrefs=xrefs,
|
|
102
|
-
synonyms=synonyms,
|
|
103
|
-
basicPropertyValues=None, # TODO properties
|
|
104
|
-
deprecated=term.is_obsolete or False,
|
|
105
|
-
)
|
|
106
|
-
return Node(
|
|
107
|
-
# FIXME do expansion same as for OFN
|
|
108
|
-
id=f"https://bioregistry.io/{term.curie}",
|
|
109
|
-
lbl=term.name,
|
|
110
|
-
meta=meta,
|
|
111
|
-
type="CLASS",
|
|
112
|
-
reference=Reference.from_reference(term.reference),
|
|
113
|
-
standardized=True,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def _prep_prov(provenance):
|
|
118
|
-
rv = []
|
|
119
|
-
for x in provenance:
|
|
120
|
-
match x:
|
|
121
|
-
case Reference():
|
|
122
|
-
rv.append(Reference.from_reference(x))
|
|
123
|
-
case OBOLiteral():
|
|
124
|
-
logger.debug("not implemented to convert literal provenance")
|
|
125
|
-
continue
|
|
126
|
-
return rv
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def _iter_edges(term: Term) -> Iterable[Edge]:
|
|
130
|
-
for parent in term.parents:
|
|
131
|
-
yield Edge.from_parsed(
|
|
132
|
-
Reference.from_reference(term.reference),
|
|
133
|
-
Reference.from_reference(is_a.reference),
|
|
134
|
-
Reference.from_reference(parent),
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
for typedef, targets in term.relationships.items():
|
|
138
|
-
for target in targets:
|
|
139
|
-
yield Edge.from_parsed(
|
|
140
|
-
Reference.from_reference(term.reference),
|
|
141
|
-
Reference.from_reference(typedef),
|
|
142
|
-
Reference.from_reference(target),
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
for provenance_reference in term.provenance:
|
|
146
|
-
if isinstance(provenance_reference, Reference):
|
|
147
|
-
yield Edge.from_parsed(
|
|
148
|
-
Reference.from_reference(term.reference),
|
|
149
|
-
Reference.from_reference(definition_source.reference),
|
|
150
|
-
Reference.from_reference(provenance_reference),
|
|
151
|
-
)
|
|
152
|
-
# TODO also look through xrefs and seealso to get provenance xrefs?
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|