@prefix ex: <https://sparql.uniprot.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:60 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Find human proteins that catalyze reactions where substrates or product have a <a href=\"https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:35516\">Cholestane skeleton</a>"^^rdf:HTML ;
    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 sachem: <http://bioinfo.uochb.cas.cz/rdf/v1.0/sachem#>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
PREFIX up: <http://purl.uniprot.org/core/>

SELECT
  DISTINCT
    ?protein
    ?disease
    ?rhea
    ?chebi
    ?omim
WHERE {
    # Find complete ChEBIs with a Cholestane skeleton, via the Czech Elixir node IDSM Sachem chemical substructure search.
    SERVICE <https://idsm.elixir-czech.cz/sparql/endpoint/chebi> {
      ?chebi sachem:substructureSearch [
        sachem:query
"[C@]12(CCC3CCCC[C@]3(C)[C@@]1([H])CC[C@]1(C)[C@@]([H])([C@@](C)([H])CCCC(C)C)CC[C@@]21[H])[H]"
].
   }
   # Use the fact that UniProt catalytic activities are annotated using Rhea 
   # Mapping the found ChEBIs to Rhea reactions
   SERVICE <https://sparql.rhea-db.org/sparql>{
     ?rhea rh:side/rh:contains/rh:compound/rdfs:subClassOf ?chebi .
   }
   # Match the found Rhea reactions with human UniProtKB proteins
   ?protein up:annotation/up:catalyticActivity/up:catalyzedReaction ?rhea .
   ?protein up:organism taxon:9606 .
   # Find only those human entries that have an annotated related disease, and optionaly map these to OMIM
   ?protein up:annotation/up:disease ?disease .
   OPTIONAL {
     ?disease rdfs:seeAlso ?omim .
     ?omim up:database <http://purl.uniprot.org/database/MIM>
   }
}""" ;
    schema:keywords "enzyme" , "substructure search" , "ChEBI" , "idsm" , "sachem" , "federated query" ;
    schema:target <https://sparql.uniprot.org/sparql/> ;
    spex:federatesWith <https://idsm.elixir-czech.cz/sparql/endpoint/chebi> ,  <https://sparql.rhea-db.org/sparql> .

