sparql-examples

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

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

27_Select_the_number_of_reactions_that_have_Xrefs

rq turtle/ttl

Select the number of reactions that have cross-references

Use at

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

SELECT (count(distinct ?reaction) as ?distinctReactionCount) WHERE {
  ?reaction rdfs:subClassOf rh:Reaction .
  ?reaction rh:directionalReaction ?directionalReaction .
  ?reaction rh:bidirectionalReaction ?bidirectionalReaction .
  OPTIONAL { ?directionalReaction rdfs:seeAlso ?xref . }
  OPTIONAL { ?bidirectionalReaction rdfs:seeAlso ?xref . }
  FILTER (BOUND(?xref))
}

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?bidirectionalReaction")
  v3("?directionalReaction")
  v5("?distinctReactionCount")
  v2("?reaction"):::projected 
  v1("?xref")
  c2(["rh:Reaction"]):::iri 
  f0[["bound(?xref)"]]
  f0 --> v1
  v2 --"rdfs:subClassOf"-->  c2
  v2 --"rh:directionalReaction"-->  v3
  v2 --"rh:bidirectionalReaction"-->  v4
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v3 -."rdfs:seeAlso".->  v1
  end
  subgraph optional1["(optional)"]
  style optional1 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."rdfs:seeAlso".->  v1
  end
  bind2[/"count(?reaction)"/]
  v2 --o bind2
  bind2 --as--o v5