sparql-examples

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

View the Project on GitHub sib-swiss/sparql-examples

17

Select all Rhea reactions that involve a lipid, i.e. children of CHEBI:18059 in the ChEBI hierarchy.

Use at

PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_>
PREFIX chebihash: <http://purl.obolibrary.org/obo/chebi#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX up: <http://purl.uniprot.org/core/>

# Query 17
# Select all Rhea reactions that involve a lipid, i.e. children of CHEBI:18059 in the ChEBI hierarchy.
# 
# This query corresponds to the Rhea website query:
# https://www.rhea-db.org/rhea?query=chebi:18059
#
SELECT distinct ?chebi ?name ?rhea ?equation
WHERE {
  ?rhea rdfs:subClassOf rh:Reaction .
  ?rhea rh:equation ?equation .
  ?rhea rh:side/rh:contains/rh:compound ?compound .
  #
  # the ChEBI can be used either as a small molecule, the reactive part of a macromolecule or as a polymer.
  #
  { 
    ?chebi rdfs:subClassOf* CHEBI:18059 . # lipid
    ?compound (rh:chebi|(rh:reactivePart/rh:chebi)|(rh:underlyingChebi/rh:chebi)) ?chebi .
  }
  UNION 
  { # add non-pH 7.3 species
    ?not7_3 rdfs:subClassOf* CHEBI:18059 . # lipid
    ?not7_3 rdfs:subClassOf ?chebiRestriction .
    ?chebiRestriction a owl:Restriction .
    ?chebiRestriction owl:onProperty chebihash:has_major_microspecies_at_pH_7_3 .
    ?chebiRestriction owl:someValuesFrom ?chebi .
    ?compound (rh:chebi|(rh:reactivePart/rh:chebi)|(rh:underlyingChebi/rh:chebi)) ?chebi .
  }
  ?chebi up:name ?name .
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?chebi"):::projected 
  v6("?chebiRestriction")
  v3("?compound")
  v2("?equation"):::projected 
  v7("?name"):::projected 
  v5("?not7_3")
  v1("?rhea"):::projected 
  a1((" "))
  a2((" "))
  a3((" "))
  a4((" "))
  a5((" "))
  a6((" "))
  c12(["owl:Restriction"]):::iri 
  c14(["chebihash:has_major_microspecies_at_pH_7_3"]):::iri 
  c2(["rh:Reaction"]):::iri 
  c7(["CHEBI:18059"]):::iri 
  v1 --"rdfs:subClassOf"-->  c2
  v1 --"rh:equation"-->  v2
  v1 --"rh:side"-->  a1
  a1 --"rh:contains"-->  a2
  a2 --"rh:compound"-->  v3
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    v5 --"rdfs:subClassOf"-->  c7
    v5 --"rdfs:subClassOf"-->  v6
    v6 --"a"-->  c12
    v6 --"owl:onProperty"-->  c14
    v6 --"owl:someValuesFrom"-->  v4
    subgraph union1[" Union "]
    subgraph union1l[" "]
      style union1l fill:#abf,stroke-dasharray: 3 3;
      subgraph union2[" Union "]
      subgraph union2l[" "]
        style union2l fill:#abf,stroke-dasharray: 3 3;
        v3 --"rh:underlyingChebi"-->  a6
        a6 --"rh:chebi"-->  v4
      end
      subgraph union2r[" "]
        style union2r fill:#abf,stroke-dasharray: 3 3;
        v3 --"rh:reactivePart"-->  a5
        a5 --"rh:chebi"-->  v4
      end
      union2r <== or ==> union2l
      end
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v3 --"rh:chebi"-->  v4
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v4 --"rdfs:subClassOf"-->  c7
    subgraph union3[" Union "]
    subgraph union3l[" "]
      style union3l fill:#abf,stroke-dasharray: 3 3;
      subgraph union4[" Union "]
      subgraph union4l[" "]
        style union4l fill:#abf,stroke-dasharray: 3 3;
        v3 --"rh:underlyingChebi"-->  a4
        a4 --"rh:chebi"-->  v4
      end
      subgraph union4r[" "]
        style union4r fill:#abf,stroke-dasharray: 3 3;
        v3 --"rh:reactivePart"-->  a3
        a3 --"rh:chebi"-->  v4
      end
      union4r <== or ==> union4l
      end
    end
    subgraph union3r[" "]
      style union3r fill:#abf,stroke-dasharray: 3 3;
      v3 --"rh:chebi"-->  v4
    end
    union3r <== or ==> union3l
    end
  end
  union0r <== or ==> union0l
  end
  v4 --"up:name"-->  v7