sparql-examples

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

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

034

rq turtle/ttl

Checks a subset of pathways for the presence of a specific MolMeDB compound by querying the MolMeDB SPARQL endpoint. Uses nested federation with both MolMeDB and WikiPathways endpoints. May be slower due to external endpoint dependency. This example uses the default value (Species "Homo sapiens"); the WikiPathways SNORQL UI lets you change it.

Use at

PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>

SELECT DISTINCT ?pathwayRes (str(?wpid) as ?pathway) (str(?title) as ?pathwayTitle) ((substr(str(?COMPOUND),46)) as ?PubChem) WHERE {
  SERVICE <https://idsm.elixir-czech.cz/sparql/endpoint/molmedb> {
    SERVICE <https://sparql.wikipathways.org/sparql> {
      VALUES ?wpid {"WP4224" "WP4225" "WP4571"}

    ?gene a wp:Metabolite ;
      dcterms:identifier ?id ;
      dcterms:isPartOf ?pathwayRes ;
      wp:bdbPubChem ?COMPOUND .

    ?pathwayRes a wp:Pathway ;
      wp:organismName "Homo sapiens" ;
      dcterms:identifier ?wpid ;
      dc:title ?title .
    }
    
    <http://identifiers.org/molmedb/MM00431> skos:exactMatch ?COMPOUND.
  }
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?COMPOUND"):::projected 
  v9("?PubChem")
  v2("?gene")
  v3("?id")
  v7("?pathway")
  v4("?pathwayRes"):::projected 
  v8("?pathwayTitle")
  v6("?title"):::projected 
  v1("?wpid"):::projected 
  c10(["Homo sapiens"]):::literal 
  c8(["wp:Pathway"]):::iri 
  c4(["wp:Metabolite"]):::iri 
  c12([http://identifiers.org/molmedb/MM00431]):::iri 
  subgraph s1["https://idsm.elixir-czech.cz/sparql/endpoint/molmedb"]
    style s1 stroke-width:4px;
    subgraph s2["https://sparql.wikipathways.org/sparql"]
      style s2 stroke-width:4px;
      bind0[/VALUES ?wpid/]
      bind0-->v1
      bind00(["WP4224"])
      bind00 --> bind0
      bind01(["WP4225"])
      bind01 --> bind0
      bind02(["WP4571"])
      bind02 --> bind0
      v2 --"a"-->  c4
      v2 --"dcterms:identifier"-->  v3
      v2 --"dcterms:isPartOf"-->  v4
      v2 --"wp:bdbPubChem"-->  v5
      v4 --"a"-->  c8
      v4 --"wp:organismName"-->  c10
      v4 --"dcterms:identifier"-->  v1
      v4 --"dc:title"-->  v6
    end
    c12 --"skos:exactMatch"-->  v5
  end
  bind1[/"str(?wpid)"/]
  v1 --o bind1
  bind1 --as--o v7
  bind2[/"str(?title)"/]
  v6 --o bind2
  bind2 --as--o v8
  bind3[/"substring(str(?COMPOUND),'46^^xsd:integer')"/]
  v5 --o bind3
  bind3 --as--o v9