sparql-examples

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

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

018

rq turtle/ttl

Counts the number of distinct entities of a selected type per species in WikiPathways, ordered by count descending. This example uses the default value (Entity Type "DataNode"); 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 wp: <http://vocabularies.wikipathways.org/wp#>

SELECT (COUNT(DISTINCT ?entity) AS ?count) (str(?label) AS ?species)
WHERE {
  ?entity a wp:DataNode ;
    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")
  v2("?entity"):::projected 
  v6("?label"):::projected 
  v5("?organism")
  v3("?pw")
  v7("?species")
  v4("?title")
  c2(["wp:DataNode"]):::iri 
  v2 --"a"-->  c2
  v2 --"dcterms:isPartOf"-->  v3
  v3 --"dc:title"-->  v4
  v3 --"wp:organism"-->  v5
  v3 --"wp:organismName"-->  v6
  bind1[/"count(?entity)"/]
  v2 --o bind1
  bind1 --as--o v7
  bind2[/"str(?label)"/]
  v6 --o bind2
  bind2 --as--o v7