sparql-examples

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

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

67_Select_all_compounds_and_count_their_occurrence_in_Rhea_reactions

rq turtle/ttl

Select all compounds and count their occurrence in Rhea reactions

Use at

PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT
  ?reactionParticipantAc
  ?chebi
  (count(distinct ?reaction) as ?reactionCount)
  ?reactionParticipantName
WHERE {
  ?reaction rdfs:subClassOf rh:Reaction .
  ?reaction rh:status rh:Approved .
  ?reaction rh:side ?reactionSide .
  ?reactionSide rh:contains ?participant .
  ?participant rh:compound ?compound .
  OPTIONAL {
    ?compound rh:chebi ?chebi .
  }
  ?compound rh:name ?reactionParticipantName .
  ?compound rh:accession ?reactionParticipantAc .
}
GROUP BY ?reactionParticipantAc ?chebi ?reactionParticipantName
ORDER BY DESC(?reactionCount)
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?chebi"):::projected 
  v5("?compound")
  v4("?participant")
  v2("?reaction"):::projected 
  v9("?reactionCount")
  v8("?reactionParticipantAc"):::projected 
  v7("?reactionParticipantName"):::projected 
  v3("?reactionSide")
  c4(["rh:Approved"]):::iri 
  c2(["rh:Reaction"]):::iri 
  v2 --"rdfs:subClassOf"-->  c2
  v2 --"rh:status"-->  c4
  v2 --"rh:side"-->  v3
  v3 --"rh:contains"-->  v4
  v4 --"rh:compound"-->  v5
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v5 -."rh:chebi".->  v6
  end
  v5 --"rh:name"-->  v7
  v5 --"rh:accession"-->  v8
  bind1[/"count(?reaction)"/]
  v2 --o bind1
  bind1 --as--o v9