Skip to content

Commit

Permalink
Additional updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jul 5, 2023
1 parent 11fe1b7 commit af76b58
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
17 changes: 13 additions & 4 deletions mira/dkg/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def construct(
property_values="",
xref_types="", # TODO
synonym_types=";".join(
synonym.type or "skos:exactMatch" for synonym in term.synonyms or []
synonym.type.curie for synonym in term.synonyms or []
),
)
for parent in term.parents:
Expand Down Expand Up @@ -781,6 +781,16 @@ def _get_edge_name(curie_: str, strict: bool = False) -> str:
edge.pred for edge in graph.edges if edge.pred.startswith("http")
)

clean_edges = (
edge
for edge in graph.edges
if (
edge.subject is not None
and edge.predicate is not None
and edge.object is not None
and edge.object.curie not in OBSOLETE
)
)
edges.extend(
(
edge.sub,
Expand All @@ -792,9 +802,8 @@ def _get_edge_name(curie_: str, strict: bool = False) -> str:
version or "",
)
for edge in tqdm(
sorted(graph.edges, key=methodcaller("as_tuple")), unit="edge", unit_scale=True
sorted(clean_edges, key=methodcaller("as_tuple")), unit="edge", unit_scale=True
)
if edge.obj not in OBSOLETE
)

for sub, obj, pred_label, pred, *_ in edges:
Expand Down Expand Up @@ -970,7 +979,7 @@ def get_node_info(term: pyobo.Term, type: EntityType = "class"):
property_values="",
xref_types="",
synonym_types=";".join(
synonym.type or "skos:exactMatch" for synonym in term.synonyms or []
synonym.type.curie for synonym in term.synonyms or []
),
)

Expand Down
1 change: 0 additions & 1 deletion mira/dkg/construct_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import Optional, Set

import bioregistry
import bioregistry.app.impl
import click
from bioregistry import Manager
from tqdm import tqdm
Expand Down
10 changes: 8 additions & 2 deletions mira/dkg/resources/probonto.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import json
from collections import defaultdict
from pathlib import Path

import bioontologies
import rdflib

HERE = Path(__file__).parent.resolve()
PROBONTO_PATH = HERE.joinpath("probonto.json")

def get_data_properties(rdf_graph: rdflib.Graph, identifier):
return {
Expand All @@ -24,7 +27,10 @@ def get_instances(obo_graph, probonto_identifier: str):
]


def get_probonto_terms():
def get_probonto_terms(*, refresh: bool = False):
if PROBONTO_PATH.is_file() and not refresh:
return json.loads(PROBONTO_PATH.read_text())

obo_graph = (
bioontologies.get_obograph_by_prefix("probonto")
.guess("probonto")
Expand Down Expand Up @@ -96,7 +102,7 @@ def get_probonto_terms():

def main():
results = get_probonto_terms()
with open("probonto.json", "w") as file:
with open(PROBONTO_PATH, "w") as file:
json.dump(results, file, indent=2, ensure_ascii=False)


Expand Down

0 comments on commit af76b58

Please sign in to comment.