@prefix ex: <https://sparql.omabrowser.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:14 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Retrieve pairwise orthologous genes of the Cyanobacterium-aponinum psb27- gene that are found in the MBGD database but are not present in OMA"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX oma: <http://omabrowser.org/ontology/oma#>
PREFIX orth: <http://purl.org/net/orth#>
PREFIX sio: <http://semanticscience.org/resource/>
PREFIX lscr: <http://purl.org/lscr#>
PREFIX mbgd: <http://purl.jp/bio/11/mbgd#>

SELECT ?protein2 ?species WHERE {
  SERVICE <http://sparql.nibb.ac.jp/sparql> {
    SELECT ?protein2 ?species WHERE {
      ?cluster_mbgd a orth:OrthologsCluster ;
          orth:hasHomologous ?node1_mbgd ;
        orth:hasHomologous ?node2_mbgd .
      ?node1_mbgd orth:hasHomologous* ?gene1 .
      ?node2_mbgd orth:hasHomologous* ?gene2 .
      ?gene1 mbgd:uniprot <http://purl.uniprot.org/uniprot/K9Z723> .
      ?gene2 mbgd:uniprot ?protein2 ;
        mbgd:organism ?taxon .
      OPTIONAL {
        ?taxon mbgd:species ?species .
      }
      FILTER (?node1_mbgd != ?node2_mbgd)
    }
  }
  FILTER NOT EXISTS { # keep only those that do not exist in OMA
    ?cluster a orth:OrthologsCluster ;
      orth:hasHomologousMember ?node1 ;
      orth:hasHomologousMember ?node2 .
    ?node1 orth:hasHomologousMember* ?protein_OMA_1.
    ?node2 orth:hasHomologousMember* ?protein_OMA_2.
    ?protein_OMA_1 lscr:xrefUniprot <http://purl.uniprot.org/uniprot/K9Z723>.
    ?protein_OMA_2 lscr:xrefUniprot ?protein2.
    FILTER (?node1 != ?node2)
  }
}""" ;
    schema:target <https://sparql.omabrowser.org/sparql> ;
    spex:federatesWith <http://sparql.nibb.ac.jp/sparql> .

