From d163c515ac634011084e9f67fe978f87e7303388 Mon Sep 17 00:00:00 2001 From: cmungall Date: Tue, 9 Nov 2021 13:19:57 -0800 Subject: [PATCH] Steps to get taxon exclusions from relation graph --- src/ontology/uberon.Makefile | 30 +++++++++--- .../taxon-violation-relation-graph.sparql | 47 +++++++++++++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 src/sparql/taxon-violation-relation-graph.sparql diff --git a/src/ontology/uberon.Makefile b/src/ontology/uberon.Makefile index 6fc46805c4..4def93b76e 100644 --- a/src/ontology/uberon.Makefile +++ b/src/ontology/uberon.Makefile @@ -111,7 +111,7 @@ core.owl: $(OWLSRC) # FIXED apparently our base does not contain phenoscape-ext!! (It does, through unreasoned) #$(TMPDIR)/phenoscape-ext-src.owl: $(SRC) # wget --no-check-certificate https://raw.githubusercontent.com/obophenotype/uberon-phenoscape-ext/master/phenoscape-ext.owl -O $@ && touch $@ - + # including the imports would lead to circularity, so we remove these here #$(COMPONENTSDIR)/phenoscape-ext.owl: $(TMPDIR)/phenoscape-ext-src.owl core.owl # owltools $(UCAT) $< --remove-imports-declarations -o -f functional $@ @@ -1702,8 +1702,8 @@ reports/robot_release_diff.md: $(TMPDIR)/$(ONT)-obo.obo $(TMPDIR)/$(ONT)-obo-mai .PHONY: feature_diff feature_diff: reports/robot_main_diff.md - - + + ######################## #### Utility commands ## @@ -1734,7 +1734,6 @@ clean: rm -rf ./uberon-base.* rm -f uberon.owl uberon.obo core.owl BUILDLOGUBERON.txt unsat_all_explanation.md rm -f ext.owl - explain: $(ROBOT) explain --input $(TMPDIR)/unreasoned-composite-metazoan.owl --reasoner ELK \ @@ -1745,13 +1744,13 @@ explain: # echo "skipping $@" unsat: $(TMPDIR)/bundled-metazoan.owl_unsat.ofn $(TMPDIR)/cl_mondo_merged.owl_unsat.ofn - + $(TMPDIR)/%_unsat.ofn: % $(ROBOT) merge --input $< explain --reasoner ELK \ -M unsatisfiability --unsatisfiable random:3 --explanation $@.md \ annotate --ontology-iri "$(ONTBASE)/$@" \ --output $@ - + cl_mondo_merged.owl: $(ROBOT) merge -i uberon.owl -I $(URIBASE)/cl.owl -o $@ @@ -1861,3 +1860,22 @@ docs/releases.md: uberon-odk.yaml # Amazing: only generate links to release artefacts if they truly exist: # if http://purl.obolibrary.org/obo/mondo/releases/2021-01-01/mondo.owl exists, include it in overview. # Use Github or obo purls (include switch that we can conficgue with ODK) + + +# ---------------------------------------- +# TAXON CONSTRAINTS VIA RELATION GRAPH +# ---------------------------------------- +# see https://github.com/obophenotype/uberon/issues/2137#issuecomment-963594082 + +# make a relationgraph ttl file (assumes RG 2.0 - may not be in ODK yet) +tmp/%.relationgraph.ttl: %.obo + relation-graph --ontology-file $< --equivalence-as-subclass true --output-subclasses true --reflexive-subclasses true --output-file $@ +.PRECIOUS: tmp/%.relationgraph.ttl + +tmp/%.rgmerged.ttl: tmp/%.relationgraph.ttl %.obo + robot merge -i $< -i $*.obo -o $@ +.PRECIOUS: tmp/%.rgmerged.ttl + +# This is currently hardcoded to a subset of species +tmp/class-taxon-exclusions.tsv: tmp/uberon-edit.rgmerged.ttl + robot query -i $< --tdb true --query ../sparql/taxon-violation-relation-graph.sparql $@ diff --git a/src/sparql/taxon-violation-relation-graph.sparql b/src/sparql/taxon-violation-relation-graph.sparql new file mode 100644 index 0000000000..ee5d8905d9 --- /dev/null +++ b/src/sparql/taxon-violation-relation-graph.sparql @@ -0,0 +1,47 @@ +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: + +PREFIX human: +PREFIX mammal: +PREFIX never_in_taxon: +PREFIX in_taxon: + +SELECT ?c ?cLabel ?p ?pLabel ?clsWithConstraint ?clsWithConstraintLabel ?taxonWithConstraint ?taxonWithConstraintLabel ?queryTaxon +WHERE { + + ?c ?p ?clsWithConstraint . + + # NEVER IN + { + ?clsWithConstraint never_in_taxon: ?taxonWithConstraint . + ?queryTaxon + rdfs:subClassOf ?taxonWithConstraint + } + UNION + # ONLY IN + { + ?clsWithConstraint in_taxon: ?taxonWithConstraint + FILTER NOT EXISTS { ?queryTaxon + rdfs:subClassOf ?taxonWithConstraint + } + } + + # add to this as required + VALUES ?queryTaxon { + human: mammal: + } + OPTIONAL + { ?c rdfs:label ?cLabel } + OPTIONAL + { ?p rdfs:label ?pLabel } + OPTIONAL + { ?clsWithConstraint rdfs:label ?clsWithConstraintLabel } + OPTIONAL + { ?taxonWithConstraint rdfs:label ?taxonWithConstraintLabel } + + + FILTER isIRI(?c) + + + }