@prefix ex: <https://sparql.uniprot.org/.well-known/sparql-examples/> .
@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:49 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:label "Where are the human genes encoding enzymes metabolizing cholesterol expressed? (double federated query)" ;
    rdfs:comment "Retrieve the UniProtKB proteins, their catalyzed Rhea reactions, their encoding genes (Ensembl) and the anatomic entities where the genes are expressed (UBERON anatomic entites from Bgee expression data resource)."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_>
PREFIX genex: <http://purl.org/genex#>
PREFIX lscr: <http://purl.org/lscr#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
PREFIX up: <http://purl.uniprot.org/core/>

SELECT DISTINCT ?protein ?ensemblGene ?reaction ?anatomicEntityLabel ?anatomicEntity
WHERE {
  # federated query to Rhea enadpoint
  {
    SELECT DISTINCT ?reaction WHERE {
      SERVICE <https://sparql.rhea-db.org/sparql> {
        ?reaction rdfs:subClassOf rh:Reaction ;
          rh:equation ?reactionEquation ;
          rh:side ?reactionSide .
        ?reactionSide rh:contains ?participant .
        ?participant rh:compound ?compound .
        # compound constraint (CHEBI:16113 == cholesterol)
        ?compound rh:chebi CHEBI:16113 .
      }
    }
  }
  # taxonomy constraint (taxon:9606 == Homo sapiens)
  ?protein up:organism taxon:9606 ;
    up:annotation ?a ;
    rdfs:seeAlso / up:transcribedFrom ?ensemblGene .
  ?a a up:Catalytic_Activity_Annotation ;
    up:catalyticActivity ?ca .
  ?ca up:catalyzedReaction ?reaction .
  # federated query to Bgee (expression data)
  BIND(IRI(REPLACE(STR(?ensemblGene), "\\\\.[0-9]+$", "")) AS ?ensemblGeneNoVersion)
  SERVICE <https://www.bgee.org/sparql/> {
    ?gene lscr:xrefEnsemblGene ?ensemblGeneNoVersion ;
      genex:isExpressedIn ?anatomicEntity .
    ?anatomicEntity rdfs:label ?anatomicEntityLabel .
  }
}""" ;
    schema:keywords "enzyme" , "tissue specificity" , "federated query" , "Ensembl" , "Bgee" , "Rhea" , "UBERON" ;
    schema:target <https://sparql.uniprot.org/sparql/> ;
    spex:federatesWith <https://sparql.rhea-db.org/sparql>, <https://www.bgee.org/sparql/> .

