sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

032

rq turtle/ttl

Maps Rhea reaction IDs from a WikiPathways pathway to MetaNetX reaction identifiers by querying the MetaNetX SPARQL endpoint. May be slower due to external endpoint dependency.

Use at

PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX wp:      <http://vocabularies.wikipathways.org/wp#>
PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
#Prefixes for the MetaNetX RDF:
PREFIX mnx: <https://rdf.metanetx.org/schema/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rhea: <http://rdf.rhea-db.org/>

#Variable selection
SELECT DISTINCT (str(?title) as ?pathwayName) ?PWID ?interactionID ?reac

WHERE {
#Pathway Model IDs of interest
VALUES ?PWID {"WP5275"}
  
    ?pathway a wp:Pathway . #Define what a pathway is
    ?pathway dcterms:identifier ?PWID. #Obtain the ID
    ?pathway dc:title ?title . #Obtain the title
  
    ?interaction wp:bdbRhea ?interactionID . #Find interactions with a Rhea ID
    ?interaction dcterms:isPartOf ?pathway . #Only those part of PW
  
  ##The IRI for Rhea-IDs from WikiPathways starts with https://identifiers.org/rhea/, where the one from MetaNetX starts with "http://rdf.rhea-db.org/ , so we need to rewrite the IRI
    # Bind the created IRI into a new variable ?newIRI: take the Rhea IRI from WikiPathways as a string,
    # remove the first 29 characters and put "http://rdf.rhea-db.org/" in front of what is left.
    BIND(IRI(CONCAT("http://rdf.rhea-db.org/", SUBSTR(STR(?interactionID), 30))) AS ?newIRI)
   SERVICE <https://rdf.metanetx.org/sparql/>  {
     SELECT DISTINCT ?reac
                           WHERE{
    ?reac mnx:reacXref rhea:17658 .}
     }
  
} ORDER BY ASC(?pathway)
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?PWID"):::projected 
  v4("?interaction")
  v5("?interactionID"):::projected 
  v6("?newIRI")
  v1("?pathway")
  v8("?pathwayName")
  v7("?reac"):::projected 
  v3("?title"):::projected 
  c9([http://rdf.rhea-db.org/17658]):::iri 
  c2(["wp:Pathway"]):::iri 
  bind0[/VALUES ?PWID/]
  bind0-->v2
  bind00(["WP5275"])
  bind00 --> bind0
  v1 --"a"-->  c2
  v1 --"dcterms:identifier"-->  v2
  v1 --"dc:title"-->  v3
  v4 --"wp:bdbRhea"-->  v5
  v4 --"dcterms:isPartOf"-->  v1
  bind1[/"concat('http://rdf.rhea-db.org/',substring(str(?interactionID),'30^^xsd:integer'))"/]
  v5 --o bind1
  bind1 --as--o v6
  subgraph s1["https://rdf.metanetx.org/sparql/"]
    style s1 stroke-width:4px;
    v7 --"mnx:reacXref"-->  c9
  end
  bind2[/"str(?title)"/]
  v3 --o bind2
  bind2 --as--o v8