sparql-examples

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

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

035

rq turtle/ttl

Finds structurally similar compounds for reaction sources and targets in a pathway by querying the IDSM structure search service for molecular similarity. May be slower due to external endpoint dependency.

Use at

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ebi: <http://ebi.rdf.ac.uk/dataset/>
PREFIX sachem: <http://bioinfo.uochb.cas.cz/rdf/v1.0/sachem#>
PREFIX idsm: <https://idsm.elixir-czech.cz/sparql/endpoint/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
PREFIX sso: <http://semanticscience.org/resource/>
PREFIX rh:<http://rdf.rhea-db.org/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>

SELECT distinct ?chebioSrc ?similarSrc ?chebioTgt ?similarTgt ?reaction WHERE {
  ?interaction dcterms:isPartOf ?pathway ; a wp:Conversion ;
      wp:source ?source ;
      wp:target ?target .
    ?source wp:bdbChEBI ?chebiSrc .
    ?target wp:bdbChEBI ?chebiTgt .
    ?pathway dcterms:identifier "WP4225".
    BIND(iri(concat("http://purl.obolibrary.org/obo/CHEBI_", substr(str(?chebiSrc),37))) AS ?chebioSrc)
    BIND(iri(concat("http://purl.obolibrary.org/obo/CHEBI_", substr(str(?chebiTgt),37))) AS ?chebioTgt)


#IDSM
SERVICE <https://idsm.elixir-czech.cz/sparql/endpoint/chebi> {
  
   ?chebioSrc ^sso:is-attribute-of / sso:has-value ?molfileSrc .
 ?chebioTgt ^sso:is-attribute-of / sso:has-value ?molfileTgt .
  [ sachem:compound ?similarSrc; sachem:score ?scoreSrc ]
    sachem:similaritySearch [
      sachem:query ?molfileSrc ;
#     sachem:cutoff "0.98"^^xsd:double
    ].
  [ sachem:compound ?similarTgt; sachem:score ?scoreTgt ]
    sachem:similaritySearch [
      sachem:query ?molfileTgt ;
#      sachem:cutoff "0.98"^^xsd:double
    ].
  }
  
#   SERVICE <https://sparql.rhea-db.org/sparql> {
#    ?reaction rh:side / rh:contains / rh:compound / rh:chebi ?similarSrc , ?similarTgt .
#    ?reaction rdfs:subClassOf rh:Reaction .
#  }  
  
 }
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?chebiSrc")
  v6("?chebiTgt")
  v7("?chebioSrc"):::projected 
  v8("?chebioTgt"):::projected 
  v1("?interaction")
  v9("?molfileSrc")
  v10("?molfileTgt")
  v2("?pathway")
  v12("?scoreSrc")
  v14("?scoreTgt")
  v11("?similarSrc"):::projected 
  v13("?similarTgt"):::projected 
  v3("?source")
  v4("?target")
  a1((" "))
  a2((" "))
  a3((" "))
  a4((" "))
  a5((" "))
  a6((" "))
  c8(["WP4225"]):::literal 
  c3(["wp:Conversion"]):::iri 
  v1 --"dcterms:isPartOf"-->  v2
  v1 --"a"-->  c3
  v1 --"wp:source"-->  v3
  v1 --"wp:target"-->  v4
  v3 --"wp:bdbChEBI"-->  v5
  v4 --"wp:bdbChEBI"-->  v6
  v2 --"dcterms:identifier"-->  c8
  bind0[/"concat('http://purl.obolibrary.org/obo/CHEBI_',substring(str(?chebiSrc),'37^^xsd:integer'))"/]
  v5 --o bind0
  bind0 --as--o v7
  bind1[/"concat('http://purl.obolibrary.org/obo/CHEBI_',substring(str(?chebiTgt),'37^^xsd:integer'))"/]
  v6 --o bind1
  bind1 --as--o v8
  subgraph s1["https://idsm.elixir-czech.cz/sparql/endpoint/chebi"]
    style s1 stroke-width:4px;
    a1 --http://semanticscience.org/resource/is-attribute-of-->  v7
    a1 --http://semanticscience.org/resource/has-value-->  v9
    a2 --http://semanticscience.org/resource/is-attribute-of-->  v8
    a2 --http://semanticscience.org/resource/has-value-->  v10
    a3 --"sachem:compound"-->  v11
    a3 --"sachem:score"-->  v12
    a4 --"sachem:query"-->  v9
    a3 --"sachem:similaritySearch"-->  a4
    a5 --"sachem:compound"-->  v13
    a5 --"sachem:score"-->  v14
    a6 --"sachem:query"-->  v10
    a5 --"sachem:similaritySearch"-->  a6
  end