@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#> .
@prefix spex:<https://purl.expasy.org/sparql-examples/ontology#> .

ex:11 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Distribution of reactions according to the first class of the enzyme classification (federated query)"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX ec: <http://purl.uniprot.org/enzyme/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

# Query 11
# Retrieve the count of reactions mapped to each level (main class) of the enzyme classification
#
# This query mimics the Filter section of the Rhea website (Browse all reactions)
# https://www.rhea-db.org/rhea?query=
SELECT ?ecClass (STR(?ecName) AS ?ecClassName) (COUNT(?rhea) AS ?rheaCount)
WHERE {
  SERVICE <https://sparql.uniprot.org/sparql> {
    VALUES (?ecClass) { (ec:1.-.-.-)(ec:2.-.-.-)(ec:3.-.-.-)(ec:4.-.-.-)(ec:5.-.-.-) (ec:6.-.-.-) (ec:7.-.-.-)}
    ?ecNumber rdfs:subClassOf ?ecClass .
    ?ecClass skos:prefLabel ?ecName .
  }
  ?rhea rdfs:subClassOf rh:Reaction .
  ?rhea rh:ec ?ecNumber .
} GROUP BY ?ecClass ?ecName""" ;
    schema:target <https://sparql.rhea-db.org/sparql> ;
    spex:federatesWith <https://sparql.uniprot.org/sparql> .

