@prefix dcterms: <http://purl.org/dc/terms/> .
@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:67_Select_all_compounds_and_count_their_occurrence_in_Rhea_reactions a sh:SPARQLExecutable,
    sh:SPARQLSelectExecutable;
  rdfs:comment "Select all compounds and count their occurrence in Rhea reactions"@en ;
  sh:select """PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT
  ?reactionParticipantAc
  ?chebi
  (count(distinct ?reaction) as ?reactionCount)
  ?reactionParticipantName
WHERE {
  ?reaction rdfs:subClassOf rh:Reaction .
  ?reaction rh:status rh:Approved .
  ?reaction rh:side ?reactionSide .
  ?reactionSide rh:contains ?participant .
  ?participant rh:compound ?compound .
  OPTIONAL {
    ?compound rh:chebi ?chebi .
  }
  ?compound rh:name ?reactionParticipantName .
  ?compound rh:accession ?reactionParticipantAc .
}
GROUP BY ?reactionParticipantAc ?chebi ?reactionParticipantName
ORDER BY DESC(?reactionCount)""";
  schema:target <https://sparql.rhea-db.org/sparql> .
