obographs 0.0.6__tar.gz → 0.0.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: obographs
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: A python data model for OBO Graphs
5
5
  Keywords: snekpack,cookiecutter
6
6
  Author: Charles Tapley Hoyt
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "obographs"
7
- version = "0.0.6"
7
+ version = "0.0.8"
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.6"
235
+ current_version = "0.0.8"
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}",
@@ -1,5 +1,6 @@
1
1
  """A python data model for OBO Graphs."""
2
2
 
3
+ from .contrib import guess_primary_graph
3
4
  from .model import (
4
5
  Definition,
5
6
  DomainRangeAxiom,
@@ -69,5 +70,6 @@ __all__ = [
69
70
  "StandardizedXref",
70
71
  "Synonym",
71
72
  "Xref",
73
+ "guess_primary_graph",
72
74
  "read",
73
75
  ]
@@ -0,0 +1,71 @@
1
+ """Extra functionality that isn't part of the core obographs package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import overload
6
+
7
+ from .model import Graph, GraphDocument
8
+ from .standardized import StandardizedGraph, StandardizedGraphDocument
9
+
10
+ __all__ = [
11
+ "guess_primary_graph",
12
+ ]
13
+
14
+ CANONICAL = {
15
+ "mamo": "http://identifiers.org/mamo",
16
+ "swo": "http://www.ebi.ac.uk/swo/swo.json",
17
+ "ito": "https://identifiers.org/ito:ontology",
18
+ "apollosv": "http://purl.obolibrary.org/obo/apollo_sv.owl",
19
+ "cheminf": "http://semanticchemistry.github.io/semanticchemistry/ontology/cheminf.owl",
20
+ "dideo": "http://purl.obolibrary.org/obo/dideo/release/2022-06-14/dideo.owl",
21
+ "micro": "http://purl.obolibrary.org/obo/MicrO.owl",
22
+ "ogsf": "http://purl.obolibrary.org/obo/ogsf-merged.owl",
23
+ "mfomd": "http://purl.obolibrary.org/obo/MF.owl",
24
+ "one": "http://purl.obolibrary.org/obo/ONE",
25
+ "ons": "https://raw.githubusercontent.com/enpadasi/Ontology-for-Nutritional-Studies/master/ons.owl",
26
+ "ontie": "https://ontology.iedb.org/ontology/ontie.owl",
27
+ }
28
+
29
+
30
+ # docstr-coverage:excused `overload`
31
+ @overload
32
+ def guess_primary_graph(
33
+ graph_document: GraphDocument,
34
+ prefix: str,
35
+ ) -> Graph: ...
36
+
37
+
38
+ # docstr-coverage:excused `overload`
39
+ @overload
40
+ def guess_primary_graph(
41
+ graph_document: StandardizedGraphDocument,
42
+ prefix: str,
43
+ ) -> StandardizedGraph: ...
44
+
45
+
46
+ def guess_primary_graph(
47
+ graph_document: GraphDocument | StandardizedGraphDocument,
48
+ prefix: str,
49
+ ) -> Graph | StandardizedGraph:
50
+ """Guess the primary graph from a graph document."""
51
+ if 0 == len(graph_document.graphs):
52
+ raise ValueError("Could not automatically identify the primary graph from empty list")
53
+ elif 1 == len(graph_document.graphs):
54
+ return graph_document.graphs[0]
55
+
56
+ id_to_graph = {graph.id: graph for graph in graph_document.graphs if graph.id}
57
+
58
+ # Check for standard construction of OBO PURLs
59
+ for suffix in ["owl", "obo", "json"]:
60
+ standard_id = f"http://purl.obolibrary.org/obo/{prefix.lower()}.{suffix}"
61
+ if standard_id in id_to_graph:
62
+ return id_to_graph[standard_id]
63
+
64
+ # Check if we've manually curated a mapping
65
+ if prefix in CANONICAL and CANONICAL[prefix] in id_to_graph:
66
+ return id_to_graph[CANONICAL[prefix]]
67
+
68
+ raise ValueError(
69
+ f"Could not automatically identify the primary graph for {prefix=} from "
70
+ f"{len(id_to_graph):,} graphs:\n\n{sorted(id_to_graph)}"
71
+ )
@@ -184,11 +184,30 @@ class Graph(BaseModel):
184
184
  domainRangeAxioms: list[DomainRangeAxiom] = Field(default_factory=list) # noqa:N815
185
185
  propertyChainAxioms: list[PropertyChainAxiom] = Field(default_factory=list) # noqa:N815
186
186
 
187
- def standardize(self, converter: curies.Converter) -> StandardizedGraph:
187
+ def _get_property(self, predicate: str) -> str | None:
188
+ if self.meta is not None:
189
+ for prop in self.meta.basicPropertyValues or []:
190
+ if prop.pred == predicate and prop.val:
191
+ return prop.val
192
+ return None
193
+
194
+ @property
195
+ def name(self) -> str | None:
196
+ """Get the title."""
197
+ return self._get_property("http://purl.org/dc/terms/title")
198
+
199
+ @property
200
+ def version(self) -> str | None:
201
+ """Get the version."""
202
+ return self._get_property("http://www.w3.org/2002/07/owl#versionInfo")
203
+
204
+ def standardize(
205
+ self, converter: curies.Converter, *, strict: bool = False
206
+ ) -> StandardizedGraph:
188
207
  """Standardize the graph."""
189
208
  from .standardized import StandardizedGraph
190
209
 
191
- return StandardizedGraph.from_obograph_raw(self, converter)
210
+ return StandardizedGraph.from_obograph_raw(self, converter, strict=strict)
192
211
 
193
212
 
194
213
  class GraphDocument(BaseModel):
@@ -8,7 +8,7 @@ from typing import Generic, TypeVar, cast
8
8
 
9
9
  import curies.preprocessing
10
10
  from curies import Converter, Reference, Triple, vocabulary
11
- from curies.vocabulary import SynonymScopeOIO
11
+ from curies.vocabulary import SynonymScopeOIO, has_title, owl_version_info
12
12
  from pydantic import BaseModel, Field
13
13
  from typing_extensions import Self
14
14
 
@@ -209,7 +209,7 @@ class StandardizedMeta(StandardizedBaseModel[Meta]):
209
209
  synonyms: list[StandardizedSynonym] | None = None
210
210
  comments: list[str] | None = None
211
211
  deprecated: bool = False
212
- version: str | None = None
212
+ version_iri: str | None = None
213
213
  properties: list[StandardizedProperty] | None = None
214
214
 
215
215
  @classmethod
@@ -272,7 +272,7 @@ class StandardizedMeta(StandardizedBaseModel[Meta]):
272
272
  xrefs=xrefs or None,
273
273
  synonyms=synonyms or None,
274
274
  comments=meta.comments,
275
- version=meta.version,
275
+ version_iri=meta.version,
276
276
  deprecated=meta.deprecated,
277
277
  properties=props or None,
278
278
  )
@@ -287,7 +287,7 @@ class StandardizedMeta(StandardizedBaseModel[Meta]):
287
287
  xrefs=[xref.to_raw(converter) for xref in self.xrefs] if self.xrefs else None,
288
288
  synonyms=[s.to_raw(converter) for s in self.synonyms] if self.synonyms else None,
289
289
  comments=self.comments,
290
- version=self.version, # TODO might need some kind of expansion?
290
+ version=self.version_iri,
291
291
  deprecated=self.deprecated,
292
292
  basicPropertyValues=[p.to_raw(converter) for p in self.properties]
293
293
  if self.properties
@@ -623,7 +623,15 @@ class StandardizedGraph(StandardizedBaseModel[Graph]):
623
623
  @property
624
624
  def name(self) -> str | None:
625
625
  """Look up the name of the graph."""
626
- r = self._get_property(Reference(prefix="dcterms", identifier="title"))
626
+ r = self._get_property(has_title)
627
+ if isinstance(r, Reference):
628
+ raise TypeError
629
+ return r
630
+
631
+ @property
632
+ def version(self) -> str | None:
633
+ """Get the version."""
634
+ r = self._get_property(owl_version_info)
627
635
  if isinstance(r, Reference):
628
636
  raise TypeError
629
637
  return r
@@ -12,7 +12,7 @@ __all__ = [
12
12
  "get_version",
13
13
  ]
14
14
 
15
- VERSION = "0.0.6"
15
+ VERSION = "0.0.8"
16
16
 
17
17
 
18
18
  def get_git_hash() -> str:
File without changes
File without changes