@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_00140 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Proteins that interact with viral proteins"@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#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
PREFIX up: <http://purl.uniprot.org/core/>

SELECT DISTINCT ?entry WHERE {
 ?entry :isoform ?iso.
 optional {?iso :interactionInfo ?itinfo .}
 {
 ?itinfo rdfs:comment ?txt.
 filter(contains(?txt,"viral") || contains(?txt,"virus")).
 } # refers to a virus in the free-text interactionInfo topic
UNION
 { ?iso :uniprotKeyword / :term nextprot_cv:KW-0945.} # host-virus interaction keyword
UNION
 {
 SERVICE <https://sparql.uniprot.org/sparql> {
 SELECT distinct ?viralinteractor WHERE # get viral proteins with an IntAct xref
 {
	?viralinteractor a up:Protein .
	?viralinteractor rdfs:seeAlso ?db .
	?db up:database <http://purl.uniprot.org/database/IntAct> .
 	?viralinteractor up:organism ?tax .
	?tax up:scientificName ?orgname.
	filter(contains(?orgname,"virus"))
 }
 }
 ?entry :isoform / :binaryInteraction ?it .
 ?it :interactant ?interactant; :quality :GOLD. # NeXtprot entries with a GOLD IntAct binary interaction
 ?interactant skos:exactMatch ?viralinteractor . # interactant must be in the uniprot service result set to select the entry
 }
UNION
 {
 SERVICE <https://sparql.uniprot.org/sparql> {
 SELECT distinct ?humprotein WHERE # get human proteins that share a PDB xref with a viral protein (same PDB id)
 {
	?humprotein a up:Protein .
 ?humprotein up:organism taxon:9606 .
	?humprotein rdfs:seeAlso ?db .
	?db up:database <http://purl.uniprot.org/database/PDB> .
	?viralprotein a up:Protein .
	?viralprotein rdfs:seeAlso ?db .
 ?viralprotein up:organism ?tax .
	?tax up:scientificName ?orgname.
	filter(contains(?orgname,"virus"))
 }
 }
 ?entry skos:exactMatch ?humprotein .
 }
}
order by ?entry""" ;
    schema:keywords "PPI",
        "federated query",
        "tutorial" ;
    schema:target <https://sparql.nextprot.org/sparql> ;
    spex:federatesWith <https://sparql.uniprot.org/sparql> .

