@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#> .
@prefix spex:<https://purl.expasy.org/sparql-examples/ontology#> .

ex:NXQ_00260 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Proteins with high-frequency missense variants involved in bacterial infection, with dbSNP identifiers and position on the canonical isoform"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX : <http://nextprot.org/rdf/>
PREFIX db: <http://nextprot.org/rdf/db/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX ncit: <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sio: <http://semanticscience.org/resource/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX so: <http://purl.obolibrary.org/obo/SO_>

SELECT DISTINCT ?entry ?umlsTerm (str(?snpac) as ?varid) ?pos (str(?orgaa) as ?orgAA) (str(?varaa) as ?varAA) WHERE {
 SERVICE <https://rdf.disgenet.org/sparql> {
 SELECT DISTINCT ?protein ?variantTitle ?umlsTerm
 WHERE {
 ?vda sio:SIO_000628 ?umls, ?variant .
 ?umls dcterms:title ?umlsTerm ; skos:exactMatch ?doid .
 ?doid rdfs:subClassOf+ <http://purl.obolibrary.org/obo/DOID_104> . # DO id for bacterial infection
 ?variant a so:0001583 ; dcterms:title ?variantTitle . # Missense variant
 ?variant so:associated_with ?gene .
 ?variant sio:SIO_000223 ?altAl .
 ?altAl rdf:type <http://purl.obolibrary.org/obo/GENO_0000476>; sio:SIO_000900 ?altAlFreq .
 ?altAlFreq a sio:SIO_001367; sio:SIO_000300 ?altAlFreqVal .
 filter(?altAlFreqVal > 0.01) # freq > 1%
 ?gene a ncit:C16612; sio:SIO_010078 ?protein .
 }
 }

 BIND(IRI(replace(str(?protein),"purl","www")) AS ?unipage) .
 ?entry :swissprotPage ?unipage .
 ?entry :isoform ?iso .
 ?iso :swissprotDisplayed true .
 ?iso :variant ?var .
 ?var :evidence /:reference ?xref .
 ?xref :provenance db:dbSNP; :accession ?snpac .
 ?var :start ?pos ; :original ?orgaa; :variation ?varaa .
 filter(contains(?snpac,str(?variantTitle))) # matches the exact same variant Disgenet returned
} order by ?entry""" ;
    schema:keywords "disease",
        "federated query",
        "isoforms",
        "sequence",
        "tutorial",
        "variant" ;
    schema:target <https://sparql.nextprot.org/sparql> ;
    spex:federatesWith <https://rdf.disgenet.org/sparql> .

