@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:16 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Select all Rhea reactions that have a pair of ChEBI IDs as reaction participant and in opposite side"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_>
PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX up: <http://purl.uniprot.org/core/>

# Query 16
# Select all Rhea reactions that have a pair of ChEBI IDs as reaction participant and in opposite side
# Return Rhea reactions that have CHEBI:29985 (L-glutamate) as reaction participant in one side
# and CHEBI:58359 (L-glutamine) in the other side.
#
# This query cannot be expressed in the Rhea website.
#
# Reactions where both chemicals are present on both sides will be returned twice.
SELECT ?chebi1 ?name1 ?chebi2 ?name2 ?rhea ?equation
WHERE {
  VALUES (?chebi1) { (CHEBI:29985) }
  ?chebi1 up:name ?name1 .
  ?rhea rh:side ?reactionSide1 .
  ?reactionSide1  rh:contains / rh:compound / rh:chebi ?chebi1 .

  VALUES (?chebi2) { (CHEBI:58359) }
  ?chebi2 up:name ?name2 .

  ?rhea rh:side ?reactionSide2 .
  ?reactionSide2  rh:contains / rh:compound / rh:chebi ?chebi2 .
  
  ?reactionSide1 rh:transformableTo ?reactionSide2 .
  
  ?rhea rh:equation ?equation .
}""" ;
    schema:target <https://sparql.rhea-db.org/sparql> .

