Skip to content

Instantly share code, notes, and snippets.

@dosumis
Created June 2, 2020 08:45
Show Gist options
  • Save dosumis/416ca217958ec008861ca4ec0685ac69 to your computer and use it in GitHub Desktop.
Save dosumis/416ca217958ec008861ca4ec0685ac69 to your computer and use it in GitHub Desktop.
Validate ccf.owl partonomy against Uberon using renci uberongraph endpoint. (secondary checks for overlaps and subClassOf)
import rdflib
from SPARQLWrapper import SPARQLWrapper, JSON
import time
g = rdflib.Graph()
g.parse('http://purl.org/ccf/latest/ccf.owl')
ccf_po_query = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ccf: <https://purl.org/ccf/latest/ccf.owl#>
SELECT DISTINCT ?o ?s ?olabel ?slabel
WHERE { ?s ccf:ccf_part_of ?o .
?o rdfs:label ?olabel .
?s rdfs:label ?slabel .
FILTER(STRSTARTS(STR(?o), "http://purl.obolibrary.org/obo/UBERON_"))
FILTER(STRSTARTS(STR(?s), "http://purl.obolibrary.org/obo/UBERON_"))
}"""
ccf_po = g.query(ccf_po_query)
sparql = SPARQLWrapper('https://stars-app.renci.org/uberongraph/sparql')
sparql.setReturnFormat(JSON)
ask_uberon_po = """
PREFIX part_of: <http://purl.obolibrary.org/obo/BFO_0000050>
ASK
FROM <http://reasoner.renci.org/ontology>
FROM <http://reasoner.renci.org/redundant>
{ <%s> part_of: <%s> }"""
ask_uberon_overlaps = """
PREFIX overlaps: <http://purl.obolibrary.org/obo/RO_0002131>
ASK
FROM <http://reasoner.renci.org/ontology>
FROM <http://reasoner.renci.org/redundant>
{ <%s> overlaps: <%s> }"""
ask_uberon_subclassof = """
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
ASK FROM <http://reasoner.renci.org/ontology/closure>
{ <%s> rdfs:subClassOf <%s> }"""
def ask_uberon(r, q):
q = ask_uberon_po % (r['s'], r['o'])
sparql.setQuery(q)
results = sparql.query().convert()
return results['boolean']
passing = len(ccf_po)
for r in ccf_po:
fillers = (r['slabel'], r['s'], r['olabel'], r['o'])
if not ask_uberon(r, ask_uberon_po):
passing -= 1
if ask_uberon(r, ask_uberon_subclassof):
print(ask_uberon_subclassof)
print('Uberon supports (%s)[%s] subClassOf (%s)[%s], not part_of' % fillers)
elif ask_uberon(r, ask_uberon_overlaps):
print('Uberon supports (%s)[%s] overlaps (%s)[%s], but not part_of' % fillers)
else:
print('Uberon does not (currently) support (%s)[%s] part_of (%s)[%s].' % fillers)
time.sleep(0.02) # Seems the server doesn't like to be hit too often
print("%d ccf_part_of relationship validated by Uberon" % passing)
@dosumis
Copy link
Author

dosumis commented Jun 2, 2020

Current output:

Uberon does not (currently) support ureter part_of kidney.
Uberon does not (currently) support rectum part_of pelvic cavity.
Uberon does not (currently) support ileocecal valve part_of caecum.
Uberon does not (currently) support heart right ventricle part_of right cardiac chamber.
Uberon does not (currently) support heart part_of chest cavity.
Uberon does not (currently) support white pulp of spleen part_of spleen pulp.
Uberon does not (currently) support spleen primary B follicle part_of spleen lymphoid follicle.
Uberon does not (currently) support colon part_of abdominal cavity.
Uberon does not (currently) support renal tubule part_of nephron.
Uberon does not (currently) support small intestine part_of abdominal cavity.
Uberon does not (currently) support red pulp of spleen part_of spleen pulp.
Uberon does not (currently) support minor calyx part_of kidney calyx.
Uberon does not (currently) support heart left ventricle part_of left cardiac chamber.
Uberon does not (currently) support right cardiac chamber part_of cardiac chamber.
Uberon does not (currently) support right kidney part_of kidney.
Uberon does not (currently) support kidney part_of abdominal cavity.
Uberon does not (currently) support left kidney part_of kidney.
Uberon does not (currently) support spleen part_of abdominal cavity.
Uberon does not (currently) support major calyx part_of kidney calyx.
Uberon does not (currently) support left cardiac chamber part_of cardiac chamber.
Uberon does not (currently) support outer cortex of kidney part_of cortex of kidney.
Uberon does not (currently) support right cardiac atrium part_of right cardiac chamber.
Uberon does not (currently) support collecting duct of renal tubule part_of renal tubule.
Uberon does not (currently) support spleen secondary B follicle part_of spleen lymphoid follicle.
Uberon does not (currently) support left cardiac atrium part_of left cardiac chamber.

54 ccf_part_of relationship validated by Uberon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment