sparql-examples

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

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

15

Select all ChEBI compounds used in Rhea as reaction participant

Use at

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

# Query 15
# Select all ChEBI compounds used in Rhea as reaction participant
# 
# This query can not be expressed in the Rhea website
SELECT ?chebi ?name (count(?rhea) as ?countRhea)
WHERE {
  ?rhea rdfs:subClassOf rh:Reaction .
  ?rhea rh:side/rh:contains/rh:compound ?compound .
  #
  # the ChEBI can be used either as a small molecule, the reactive part of a macromolecule or as a polymer.
  #
  ?compound (rh:chebi|(rh:reactivePart/rh:chebi)|(rh:underlyingChebi/rh:chebi)) ?chebi .
  ?chebi up:name ?name .
}
GROUP BY ?chebi ?name
ORDER BY DESC(?countRhea)
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?chebi"):::projected 
  v3("?compound")
  v6("?countRhea")
  v5("?name"):::projected 
  v2("?rhea"):::projected 
  a1((" "))
  a2((" "))
  a3((" "))
  a4((" "))
  c2(["rh:Reaction"]):::iri 
  v2 --"rdfs:subClassOf"-->  c2
  v2 --"rh:side"-->  a1
  a1 --"rh:contains"-->  a2
  a2 --"rh:compound"-->  v3
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    subgraph union1[" Union "]
    subgraph union1l[" "]
      style union1l fill:#abf,stroke-dasharray: 3 3;
      v3 --"rh:underlyingChebi"-->  a4
      a4 --"rh:chebi"-->  v4
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v3 --"rh:reactivePart"-->  a3
      a3 --"rh:chebi"-->  v4
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v3 --"rh:chebi"-->  v4
  end
  union0r <== or ==> union0l
  end
  v4 --"up:name"-->  v5
  bind1[/"count(?rhea)"/]
  v2 --o bind1
  bind1 --as--o v6