203_cross_reference_url_reconstruction

rq turtle/ttl

For proteins cross-referenced to the AbasyAtlas database, reconstruct a working link to the external record by substituting the cross-reference's own identifier into that database's up:urlTemplate — exactly the kind of thing external tooling needs and currently has to hardcode per-database

Use at

PREFIX up: <http://purl.uniprot.org/core/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT
  ?protein
  ?xref
  ?identifier
  ?urlTemplate
  ?constructedUrl
WHERE {
  BIND(<http://purl.uniprot.org/database/AbasyAtlas> AS ?database)
  ?database up:linkIsExplicit true ;
    up:urlTemplate ?urlTemplate .
  ?protein a up:Protein ;
    rdfs:seeAlso ?xref .
  ?xref up:database ?database .
  BIND(REPLACE(STR(?xref), "^.*/", "") AS ?identifier)
  BIND(IRI(REPLACE(?urlTemplate, "%u", ?identifier)) AS ?constructedUrl)
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?constructedUrl"):::projected 
  v1("?database")
  v5("?identifier"):::projected 
  v3("?protein"):::projected 
  v2("?urlTemplate"):::projected 
  v4("?xref"):::projected 
  c2(["true^^xsd:boolean"]):::literal 
  c5(["up:Protein"]):::iri 
  bind0[/"http://purl.uniprot.org/database/AbasyAtlas"/]
  bind0 --as--o v1
  v1 --"up:linkIsExplicit"-->  c2
  v1 --"up:urlTemplate"-->  v2
  v3 --"a"-->  c5
  v3 --"rdfs:seeAlso"-->  v4
  v4 --"up:database"-->  v1
  bind1[/"replace(str(?xref),'^.*/','')"/]
  v4 --o bind1
  bind1 --as--o v5
  bind2[/"replace(?urlTemplate,'%u',?identifier)"/]
  v2 --o bind2
  v5 --o bind2
  bind2 --as--o v6