obographs 0.0.8__tar.gz → 0.0.9__tar.gz
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.
- {obographs-0.0.8 → obographs-0.0.9}/PKG-INFO +1 -1
- {obographs-0.0.8 → obographs-0.0.9}/pyproject.toml +2 -2
- {obographs-0.0.8 → obographs-0.0.9}/src/obographs/model.py +18 -5
- {obographs-0.0.8 → obographs-0.0.9}/src/obographs/standardized.py +20 -12
- {obographs-0.0.8 → obographs-0.0.9}/src/obographs/version.py +1 -1
- {obographs-0.0.8 → obographs-0.0.9}/LICENSE +0 -0
- {obographs-0.0.8 → obographs-0.0.9}/README.md +0 -0
- {obographs-0.0.8 → obographs-0.0.9}/src/obographs/__init__.py +0 -0
- {obographs-0.0.8 → obographs-0.0.9}/src/obographs/contrib.py +0 -0
- {obographs-0.0.8 → obographs-0.0.9}/src/obographs/py.typed +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "obographs"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.9"
|
|
8
8
|
description = "A python data model for OBO Graphs"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -232,7 +232,7 @@ known-first-party = [
|
|
|
232
232
|
docstring-code-format = true
|
|
233
233
|
|
|
234
234
|
[tool.bumpversion]
|
|
235
|
-
current_version = "0.0.
|
|
235
|
+
current_version = "0.0.9"
|
|
236
236
|
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(?:-(?P<release>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+(?P<build>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?"
|
|
237
237
|
serialize = [
|
|
238
238
|
"{major}.{minor}.{patch}-{release}+{build}",
|
|
@@ -239,19 +239,31 @@ def get_id_to_edges(graph: Graph) -> dict[str, list[tuple[str, str]]]:
|
|
|
239
239
|
# docstr-coverage:excused `overload`
|
|
240
240
|
@overload
|
|
241
241
|
def read(
|
|
242
|
-
source: str | Path,
|
|
242
|
+
source: str | Path,
|
|
243
|
+
*,
|
|
244
|
+
timeout: TimeoutHint = ...,
|
|
245
|
+
squeeze: Literal[False] = ...,
|
|
246
|
+
encoding: str = ...,
|
|
243
247
|
) -> GraphDocument: ...
|
|
244
248
|
|
|
245
249
|
|
|
246
250
|
# docstr-coverage:excused `overload`
|
|
247
251
|
@overload
|
|
248
252
|
def read(
|
|
249
|
-
source: str | Path,
|
|
253
|
+
source: str | Path,
|
|
254
|
+
*,
|
|
255
|
+
timeout: TimeoutHint = ...,
|
|
256
|
+
squeeze: Literal[True] = ...,
|
|
257
|
+
encoding: str = ...,
|
|
250
258
|
) -> Graph: ...
|
|
251
259
|
|
|
252
260
|
|
|
253
261
|
def read(
|
|
254
|
-
source: str | Path,
|
|
262
|
+
source: str | Path,
|
|
263
|
+
*,
|
|
264
|
+
timeout: TimeoutHint = None,
|
|
265
|
+
squeeze: bool = True,
|
|
266
|
+
encoding: str = "utf-8",
|
|
255
267
|
) -> Graph | GraphDocument:
|
|
256
268
|
"""Read an OBO Graph document.
|
|
257
269
|
|
|
@@ -261,6 +273,7 @@ def read(
|
|
|
261
273
|
only has a single graph and return a :class:`Graph` object. If `true` and
|
|
262
274
|
multiple graphs are received, will raise an error. Set this to `false` to return
|
|
263
275
|
a GraphDocument containing all graphs.
|
|
276
|
+
:param encoding: The encoding to use for reading the graph
|
|
264
277
|
|
|
265
278
|
:returns: A graph or graph document
|
|
266
279
|
|
|
@@ -281,10 +294,10 @@ def read(
|
|
|
281
294
|
if not path.is_file():
|
|
282
295
|
raise FileNotFoundError
|
|
283
296
|
if path.suffix.endswith(".gz"):
|
|
284
|
-
with gzip.open(path, mode="rt") as file:
|
|
297
|
+
with gzip.open(path, mode="rt", encoding=encoding) as file:
|
|
285
298
|
graph_document = GraphDocument.model_validate(json.load(file))
|
|
286
299
|
else:
|
|
287
|
-
with path.open() as file:
|
|
300
|
+
with path.open(mode="rt", encoding=encoding) as file:
|
|
288
301
|
graph_document = GraphDocument.model_validate(json.load(file))
|
|
289
302
|
else:
|
|
290
303
|
raise TypeError(f"Unhandled source: {source}")
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
6
|
from abc import ABC, abstractmethod
|
|
7
|
+
from collections.abc import Iterable
|
|
7
8
|
from typing import Generic, TypeVar, cast
|
|
8
9
|
|
|
9
10
|
import curies.preprocessing
|
|
@@ -411,8 +412,11 @@ class StandardizedDomainRangeAxiom(StandardizedBaseModel[DomainRangeAxiom]):
|
|
|
411
412
|
cls, obj: DomainRangeAxiom, converter: Converter, *, strict: bool = False
|
|
412
413
|
) -> Self | None:
|
|
413
414
|
"""Parse a raw object."""
|
|
415
|
+
predicate = _curie_or_uri_to_ref(obj.predicateId, converter, strict=strict)
|
|
416
|
+
if predicate is None:
|
|
417
|
+
return None
|
|
414
418
|
return cls(
|
|
415
|
-
predicate=
|
|
419
|
+
predicate=predicate,
|
|
416
420
|
domains=_parse_list(obj.domainClassIds, converter, strict=strict) or [],
|
|
417
421
|
ranges=_parse_list(obj.rangeClassIds, converter, strict=strict) or [],
|
|
418
422
|
all_values_from_edges=[
|
|
@@ -528,11 +532,11 @@ class StandardizedLogicalDefinition(StandardizedBaseModel[LogicalDefinition]):
|
|
|
528
532
|
"""Parse a raw object."""
|
|
529
533
|
return cls(
|
|
530
534
|
node=_curie_or_uri_to_ref(obj.definedClassId, converter, strict=strict),
|
|
531
|
-
geni=_parse_list(obj.genusIds, converter, strict=strict),
|
|
532
|
-
restrictions=
|
|
535
|
+
geni=_parse_list(obj.genusIds, converter, strict=strict) or [],
|
|
536
|
+
restrictions=_schwoop(
|
|
533
537
|
StandardizedExistentialRestriction.from_obograph_raw(r, converter, strict=strict)
|
|
534
538
|
for r in obj.restrictions or []
|
|
535
|
-
|
|
539
|
+
),
|
|
536
540
|
meta=StandardizedMeta.from_obograph_raw(obj.meta, converter, strict=strict),
|
|
537
541
|
)
|
|
538
542
|
|
|
@@ -577,22 +581,22 @@ class StandardizedGraph(StandardizedBaseModel[Graph]):
|
|
|
577
581
|
for edge in graph.edges
|
|
578
582
|
if (s_edge := StandardizedEdge.from_obograph_raw(edge, converter, strict=strict))
|
|
579
583
|
],
|
|
580
|
-
equivalent_node_sets=
|
|
584
|
+
equivalent_node_sets=_schwoop(
|
|
581
585
|
StandardizedEquivalentNodeSet.from_obograph_raw(e, converter, strict=strict)
|
|
582
586
|
for e in graph.equivalentNodesSets or []
|
|
583
|
-
|
|
584
|
-
logical_definition_axioms=
|
|
587
|
+
),
|
|
588
|
+
logical_definition_axioms=_schwoop(
|
|
585
589
|
StandardizedLogicalDefinition.from_obograph_raw(e, converter, strict=strict)
|
|
586
590
|
for e in graph.logicalDefinitionAxioms or []
|
|
587
|
-
|
|
588
|
-
property_chain_axioms=
|
|
591
|
+
),
|
|
592
|
+
property_chain_axioms=_schwoop(
|
|
589
593
|
StandardizedPropertyChainAxiom.from_obograph_raw(e, converter, strict=strict)
|
|
590
594
|
for e in graph.propertyChainAxioms or []
|
|
591
|
-
|
|
592
|
-
domain_range_axioms=
|
|
595
|
+
),
|
|
596
|
+
domain_range_axioms=_schwoop(
|
|
593
597
|
StandardizedDomainRangeAxiom.from_obograph_raw(e, converter, strict=strict)
|
|
594
598
|
for e in graph.domainRangeAxioms or []
|
|
595
|
-
|
|
599
|
+
),
|
|
596
600
|
)
|
|
597
601
|
|
|
598
602
|
def to_raw(self, converter: Converter) -> Graph:
|
|
@@ -637,6 +641,10 @@ class StandardizedGraph(StandardizedBaseModel[Graph]):
|
|
|
637
641
|
return r
|
|
638
642
|
|
|
639
643
|
|
|
644
|
+
def _schwoop(x: Iterable[X | None]) -> list[X]:
|
|
645
|
+
return [y for y in x if y is not None]
|
|
646
|
+
|
|
647
|
+
|
|
640
648
|
class StandardizedGraphDocument(StandardizedBaseModel[GraphDocument]):
|
|
641
649
|
"""A standardized graph document."""
|
|
642
650
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|