Skip to content

Commit

Permalink
Additional EFO xref context from axioms
Browse files Browse the repository at this point in the history
merges #19

Co-authored-by: Bartek Foltyn <[email protected]>
  • Loading branch information
bfoltyn and Bartek Foltyn authored Oct 5, 2023
1 parent c7b1429 commit f6a06d4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
45 changes: 45 additions & 0 deletions nxontology_data/efo/efo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any

import bioversions
import curies
import fsspec
import networkx as nx
import pandas as pd
Expand Down Expand Up @@ -142,6 +143,42 @@ def get_obsolete_df(self) -> pd.DataFrame:
def get_alt_id_df(self) -> pd.DataFrame:
return self.run_query("alt_id", cache=True)

def get_xref_sources_df(self) -> pd.DataFrame:
return self.run_query("xref_sources", cache=True)

def get_mapping_properties_df(self) -> pd.DataFrame:
converter = curies.get_bioregistry_converter()

converter.add_prefix(
"icd10cm-missing-prefix", "http://purl.bioontology.org/ontology/ICD10CM/"
)

df = (
self.run_query("mapping_properties", cache=True)
.assign(
xref_id=lambda df: df["xref_id"].apply(
lambda xref: converter.compress(xref)
)
)
.dropna()
.assign(
xref_id=lambda df: df["xref_id"]
.str.replace("icd10cm-missing-prefix:", "icd10cm:")
.str.replace("obo:Orphanet_", "Orphanet:")
.str.split(":", expand=True)
.apply(
lambda row: normalize_parsed_curie(
xref_prefix=row[0],
xref_accession=row[1],
collapse_orphanet=True,
),
axis="columns",
)
)
)

return df

def get_synonyms(self) -> dict[str, dict[str, str]]:
synonym_scopes = {
"hasExactSynonym": "exact",
Expand Down Expand Up @@ -272,6 +309,14 @@ def write_outputs(self) -> None:
write_dataframe(
self.get_obsolete_df(), output_dir.joinpath(f"{self.name}_obsolete.json.gz")
)
write_dataframe(
self.get_mapping_properties_df(),
output_dir.joinpath(f"{self.name}_mapping_properties.json.gz"),
)
write_dataframe(
self.get_xref_sources_df(),
output_dir.joinpath(f"{self.name}_xref_sources.json.gz"),
)
if nxo.name == "efo_otar_profile":
nxo_slim = self.create_slim_nxo(nxo)
write_ontology(nxo_slim, output_dir, compression_threshold_mb=30.0)
Expand Down
17 changes: 17 additions & 0 deletions nxontology_data/efo/queries/mapping_properties.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PREFIX mondo: <http://purl.obolibrary.org/obo/mondo#>
PREFIX efo: <http://www.ebi.ac.uk/efo/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?efo_id (?xref_uri as ?xref_id) ?mapping_property_id ?efo_uri ?xref_uri ?mapping_property_uri
WHERE {
VALUES ?mapping_property_uri {mondo:closeMatch mondo:exactMatch skos:mappingRelation skos:closeMatch skos:exactMatch skos:broadMatch skos:narrowMatch skos:relatedMatch}

?efo_uri rdf:type owl:Class .
?efo_uri ?mapping_property_uri ?xref_uri


BIND( REPLACE( STR(?efo_uri), "^http.+/([^:]+)_(.+)$", "$1:$2" ) AS ?efo_id )
BIND( REPLACE( STR(?mapping_property_uri), "^http://purl\\.obolibrary\\.org/obo/mondo#(.+)$", "mondo:$1" ) AS ?mapping_property_id )
BIND( REPLACE( STR(?mapping_property_id), "^http://www\\.w3\\.org/2004/02/skos/core#(.+)$", "skos:$1" ) AS ?mapping_property_id )
}
ORDER BY ?efo_id ?xref_id ?mapping_property_id
18 changes: 18 additions & 0 deletions nxontology_data/efo/queries/xref_sources.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oboInOwl: <http://www.geneontology.org/formats/oboInOwl#>

SELECT ?efo_id ?xref ?axiom_source
WHERE {
?axiom rdf:type owl:Axiom.
?axiom owl:annotatedSource ?source.
?axiom owl:annotatedProperty oboInOwl:hasDbXref.
?axiom owl:annotatedTarget ?xref.

OPTIONAL { ?axiom oboInOwl:source ?axiom_source }.

BIND( REPLACE( STR(?source), "^http.+/([^:]+)_(.+)$", "$1:$2" ) AS ?efo_id )
}

GROUP BY ?efo_id ?xref ?axiom_source
ORDER BY ?efo_id ?xref ?axiom_source

0 comments on commit f6a06d4

Please sign in to comment.