sparql-examples

A set of SPARQL examples that are used in different SIB resources

View the Project on GitHub sib-swiss/sparql-examples

51_Select_all_reactions_that_have_parents_and_children_reactions

rq turtle/ttl

Select all reactions that have parents and children reactions

Use at

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh: <http://rdf.rhea-db.org/>

SELECT
  (count(distinct ?reaction) as ?reactionCount)
WHERE {
  ?reaction rdfs:subClassOf rh:Reaction .
  ?reaction rh:status rh:Approved .

  ?childReaction rdfs:subClassOf rh:Reaction .
  ?childReaction rh:status rh:Approved .

  ?parentReaction rdfs:subClassOf rh:Reaction .
  ?parentReaction rh:status rh:Approved .

  ?reaction rdfs:subClassOf ?parentReaction .
  ?reaction ^rdfs:subClassOf ?childReaction .
}

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?childReaction")
  v3("?parentReaction")
  v1("?reaction"):::projected 
  v4("?reactionCount")
  c4(["rh:Approved"]):::iri 
  c2(["rh:Reaction"]):::iri 
  v1 --"rdfs:subClassOf"-->  c2
  v1 --"rh:status"-->  c4
  v2 --"rdfs:subClassOf"-->  c2
  v2 --"rh:status"-->  c4
  v3 --"rdfs:subClassOf"-->  c2
  v3 --"rh:status"-->  c4
  v1 --"rdfs:subClassOf"-->  v3
  v2 --"rdfs:subClassOf"-->  v1
  bind1[/"count(?reaction)"/]
  v1 --o bind1
  bind1 --as--o v4