@prefix ex: <https://sparql.uniprot.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#> .

ex:111_uniprot_make_chain_sequence_fasta a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Given an UniProt chain identifier, generate the matching sequence as a FASTA"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX faldo: <http://biohackathon.org/resource/faldo#>

SELECT (CONCAT('>', ?chainSeqId, '\\n', (SUBSTR(?iupacAA, ?begin, (?end-?begin+1))))  AS ?chainFasta)
WHERE {
  BIND("PRO_0000268053" AS ?chainSeqId) 
  BIND(IRI(CONCAT("http://purl.uniprot.org/annotation/", ?chainSeqId)) AS ?annId)
  ?annId up:range ?range .
  ?range faldo:begin [ faldo:reference ?reference ; faldo:position ?begin ] ;
     faldo:end [ faldo:position ?end ] .
  ?reference rdf:value ?iupacAA .
}""" ;
    schema:keywords "chain", "sequence", "fasta" ;
    schema:target <https://sparql.uniprot.org/sparql/> .

