@prefix ex:<https://purl.expasy.org/sparql-examples/neXtProt/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

ex:NXQ_00058 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Proteins which are located on the genome next to a protein which is involved in spermatogenesis"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX : <http://nextprot.org/rdf/>
PREFIX nextprot_cv: <http://nextprot.org/rdf/terminology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT (?neighbour as ?entry) (str(?gen) as ?spergen) WHERE {
 {
 SELECT DISTINCT ?chr ?gen ?sperstart (MAX(?ldist) as ?lmin) (MIN(?rdist) as ?rmin) WHERE {
 ?entryx :isoform / :function ?func .
	 ?func :term / :childOf nextprot_cv:GO_0007283 . # Involvment in spermatogenesis
	 filter not exists {?func :negativeEvidence ?negev}
 ?entryx :gene ?gene.
 ?gene :begin ?sperstart; :end ?e; :chromosome ?chr; :recommendedName / rdfs:label ?gen.
 ?ngen :chromosome ?chr.
 ?ngen :begin ?n_begin; :end ?n_end .
 filter ( ?n_end > (?sperstart - 1000000) && ?n_begin <= (?sperstart + 1000000) && ?ngen != ?gene)
 bind(?sperstart - ?n_begin as ?dist)
 bind(if(?dist<0,?dist,-1000000) as ?ldist)
 bind(if(?dist>0,?dist,1000000) as ?rdist)
 } group by ?chr ?gen ?sperstart
 }
 bind(?sperstart - ?lmin as ?lchrpos)
 ?lgene :begin ?lchrpos; :chromosome ?chr.
 bind(?sperstart - ?rmin as ?rchrpos)
 ?rgene :begin ?rchrpos; :chromosome ?chr.
 { ?neighbour :gene ?lgene. } # left gene
	 union
 { ?neighbour :gene ?rgene. } # right gene
} order by ?gen""" ;
    schema:keywords "chromosomal location",
        "function",
        "tutorial" ;
    schema:target <https://sparql.nextprot.org/sparql> .

