@prefix ex: <https://sparql.rhea-db.org/.well-known/sparql-examples/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

ex:15 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Select all ChEBI compounds used in Rhea as reaction participant"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """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) ?chebi .
  ?chebi up:name ?name .
}
GROUP BY ?chebi ?name
ORDER BY DESC(?countRhea)""" ;
    schema:target <https://sparql.rhea-db.org/sparql> .

