sparql-examples

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

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

070

rq turtle/ttl

Counts the metabolites per species. The RDF generation normalises identifiers, so metabolites with identifiers from different databases are not counted twice, but metabolites with different charge states are still counted separately.

Use at

PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>

SELECT (count(distinct ?metabolite) as ?count) (str(?label) as ?species) WHERE {
  ?metabolite a wp:Metabolite ;
    dcterms:isPartOf ?pw .
  ?pw dc:title ?title ;
    wp:organism ?organism ;
    wp:organismName ?label .
} GROUP BY ?label ORDER BY DESC(?count)
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v7("?count")
  v6("?label"):::projected 
  v2("?metabolite"):::projected 
  v5("?organism")
  v3("?pw")
  v7("?species")
  v4("?title")
  c2(["wp:Metabolite"]):::iri 
  v2 --"a"-->  c2
  v2 --"dcterms:isPartOf"-->  v3
  v3 --"dc:title"-->  v4
  v3 --"wp:organism"-->  v5
  v3 --"wp:organismName"-->  v6
  bind1[/"count(?metabolite)"/]
  v2 --o bind1
  bind1 --as--o v7
  bind2[/"str(?label)"/]
  v6 --o bind2
  bind2 --as--o v7