@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_00264 a sh:SPARQLExecutable, sh:SPARQLSelectExecutable ;
  sh:prefixes _:sparql_examples_prefixes ;
  rdfs:comment '''Proteins with ENV polyprotein domains and matching viral species'''@en ;
  schema:keywords "federated query", "ortholog", "snorql-only" ;
  schema:target <https://sparql.nextprot.org/sparql> ;
  sh:select '''PREFIX : <http://nextprot.org/rdf/>
PREFIX cv: <http://nextprot.org/rdf/terminology/>
PREFIX db: <http://nextprot.org/rdf/db/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

PREFIX orth: <http://purl.orthodb.org/>
PREFIX interpro: <http://www.ebi.ac.uk/interpro/entry/>
PREFIX up: <http://purl.uniprot.org/core/>

select distinct ?entry (str(?ipac) AS ?ipacSTR) (group_concat(?taxlab ; SEPARATOR = ",") AS ?taxlab1) where {
  VALUES ?ipac {"IPR018154"^^xsd:string "IPR008981"^^xsd:string }. # Interpro patterns for TLV/ENV coat polyprotein
  bind (iri(CONCAT("http://www.ebi.ac.uk/interpro/entry/",str(?ipac))) as ?ipref) .
  SERVICE <https://sparql.orthodb.org/sparql/> {
   select distinct ?ipref ?taxlab where {
   ?taxon a orth:Species; rdfs:subClassOf+  ?clade.
   ?clade a orth:Clade; up:scientificName 'Viruses'.
   ?gene_v up:organism / a ?taxon; orth:xref [a orth:Xref; orth:xrefResource ?ipref].
   ?taxon up:scientificName ?taxlab .
   }
  }
  ?entry a :Entry .
  ?entry :reference ?ref .
  ?ref a :Xref ; :provenance db:InterPro; :accession ?ipac .
} group by ?entry ?ipac''' ;
  spex:federatesWith <https://sparql.orthodb.org/sparql/> .
