@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:17 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Select all Rhea reactions that involve a lipid, i.e. children of CHEBI:18059 in the ChEBI hierarchy."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_>
PREFIX chebihash: <http://purl.obolibrary.org/obo/chebi#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
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 17
# Select all Rhea reactions that involve a lipid, i.e. children of CHEBI:18059 in the ChEBI hierarchy.
# 
# This query corresponds to the Rhea website query:
# https://www.rhea-db.org/rhea?query=chebi:18059
#
SELECT distinct ?chebi ?name ?rhea ?equation
WHERE {
  ?rhea rdfs:subClassOf rh:Reaction .
  ?rhea rh:equation ?equation .
  ?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.
  #
  { 
    ?chebi rdfs:subClassOf* CHEBI:18059 . # lipid
    ?compound (rh:chebi|(rh:reactivePart/rh:chebi)|rh:underlyingChebi) ?chebi .
  }
  UNION 
  { # add non-pH 7.3 species
    ?not7_3 rdfs:subClassOf* CHEBI:18059 . # lipid
    ?not7_3 rdfs:subClassOf ?chebiRestriction .
    ?chebiRestriction a owl:Restriction .
    ?chebiRestriction owl:onProperty chebihash:has_major_microspecies_at_pH_7_3 .
    ?chebiRestriction owl:someValuesFrom ?chebi .
    ?compound (rh:chebi|(rh:reactivePart/rh:chebi)|rh:underlyingChebi) ?chebi .
  }
  ?chebi up:name ?name .
}""" ;
    schema:target <https://sparql.rhea-db.org/sparql> .

