@prefix ex: <https://www.bgee.org/sparql/.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:020 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Which are the genes in Primates orthologous to a gene that is expressed in the fruit fly's eye?"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX genex: <http://purl.org/genex#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX orth: <http://purl.org/net/orth#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX sio: <http://semanticscience.org/resource/>

SELECT DISTINCT ?flyEnsemblGene ?orthologTaxon ?orthologEnsemblGene ?orthologOmaLink WHERE {
	{
        SELECT DISTINCT ?gene ?flyEnsemblGene {
        ?gene a orth:Gene ;
            genex:isExpressedIn/rdfs:label 'eye' ;
            orth:organism/obo:RO_0002162 ?taxon ;
            dcterms:identifier ?flyEnsemblGene .
        ?taxon up:commonName 'fruit fly' .
        } LIMIT 100
    }
    SERVICE <https://sparql.omabrowser.org/sparql> {
        ?protein2 a orth:Protein .
        ?protein1 a orth:Protein .
        ?clusterPrimates a orth:OrthologsCluster .
        ?cluster a orth:OrthologsCluster ;
            orth:hasHomologousMember ?node1 ;
            orth:hasHomologousMember ?node2 .
        ?node1 orth:hasHomologousMember* ?protein1 .
        ?node2 orth:hasHomologousMember* ?clusterPrimates .
        ?clusterPrimates orth:hasHomologousMember* ?protein2 .
        ?protein1 sio:SIO_010079 ?gene . # is encoded by
        ?protein2 rdfs:seeAlso ?orthologOmaLink ;
            orth:organism/obo:RO_0002162 ?orthologTaxonUri ;
            sio:SIO_010079 ?orthologGene . # is encoded by
        ?clusterPrimates orth:hasTaxonomicRange ?taxRange .
        ?taxRange orth:taxRange 'Primates' .
        FILTER ( ?node1 != ?node2 )
    }
    ?orthologTaxonUri up:commonName ?orthologTaxon .
    ?orthologGene dcterms:identifier ?orthologEnsemblGene .
}""" ;
    schema:target <https://www.bgee.org/sparql/> ;
    spex:federatesWith <https://sparql.omabrowser.org/sparql> .
