Skip to content

Instantly share code, notes, and snippets.

@lindenb
Created April 28, 2023 12:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindenb/2b0239f2237ce835fe2d2ddfc9ebeb02 to your computer and use it in GitHub Desktop.
Save lindenb/2b0239f2237ce835fe2d2ddfc9ebeb02 to your computer and use it in GitHub Desktop.
Sparql PropertyPath #sparql #rdf #graph #go #geneontology recursive query of geneontology using rdfs:subClassOf

How find the children of a term in a rdf ontology using sparql.

query using jena

/path/to/apache-jena-4.8.0/bin/arq --data=path/to/go.owl --query query.sparql

without recursion

find all the children of GO:0045823 ( "positive regulation of heart contraction" )

The SPARQL query

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>


SELECT ?subClass ?label WHERE { 
        ?subClass rdfs:subClassOf <http://purl.obolibrary.org/obo/GO_0045823> . 
        ?subClass rdfs:label ?label . 
    }

Output

subClass label
http://purl.obolibrary.org/obo/GO_0001989 "positive regulation of the force of heart contraction involved in baroreceptor response to decreased systemic arterial blood pressure"
http://purl.obolibrary.org/obo/GO_0010460 "positive regulation of heart rate"
http://purl.obolibrary.org/obo/GO_0060452 "positive regulation of cardiac muscle contraction"
http://purl.obolibrary.org/obo/GO_0003099 "positive regulation of the force of heart contraction by chemical signal"

Using RECURSION

see https://www.w3.org/TR/sparql11-query/#propertypaths

find all the descendants of GO:0045823 ( "positive regulation of heart contraction" )

just add a star (*) after rdfs:subClassOf .

The SPARQL query

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>


SELECT ?subClass ?label WHERE { 
        ?subClass rdfs:subClassOf* <http://purl.obolibrary.org/obo/GO_0045823> . 
        ?subClass rdfs:label ?label . 
    }

Output

subClass label
http://purl.obolibrary.org/obo/GO_0045823 "positive regulation of heart contraction"
http://purl.obolibrary.org/obo/GO_0001989 "positive regulation of the force of heart contraction involved in baroreceptor response to decreased systemic arterial blood pressure"
http://purl.obolibrary.org/obo/GO_0010460 "positive regulation of heart rate"
http://purl.obolibrary.org/obo/GO_0001996 "positive regulation of heart rate by epinephrine-norepinephrine"
http://purl.obolibrary.org/obo/GO_0086024 "adenylate cyclase-activating adrenergic receptor signaling pathway involved in positive regulation of heart rate"
http://purl.obolibrary.org/obo/GO_0003065 "positive regulation of heart rate by epinephrine"
http://purl.obolibrary.org/obo/GO_0003112 "positive regulation of heart rate by neuronal epinephrine"
http://purl.obolibrary.org/obo/GO_0003111 "positive regulation of heart rate by circulating epinephrine"
http://purl.obolibrary.org/obo/GO_0003066 "positive regulation of heart rate by norepinephrine"
http://purl.obolibrary.org/obo/GO_0003114 "positive regulation of heart rate by circulating norepinephrine"
http://purl.obolibrary.org/obo/GO_0003113 "positive regulation of heart rate by neuronal norepinephrine"
http://purl.obolibrary.org/obo/GO_0001988 "positive regulation of heart rate involved in baroreceptor response to decreased systemic arterial blood pressure"
http://purl.obolibrary.org/obo/GO_0060452 "positive regulation of cardiac muscle contraction"
http://purl.obolibrary.org/obo/GO_0003099 "positive regulation of the force of heart contraction by chemical signal"
http://purl.obolibrary.org/obo/GO_0003061 "positive regulation of the force of heart contraction by norepinephrine"
http://purl.obolibrary.org/obo/GO_0003110 "positive regulation of the force of heart contraction by neuronal norepinephrine"
http://purl.obolibrary.org/obo/GO_0003109 "positive regulation of the force of heart contraction by circulating norepinephrine"
http://purl.obolibrary.org/obo/GO_0003059 "positive regulation of the force of heart contraction by epinephrine"
http://purl.obolibrary.org/obo/GO_0003087 "positive regulation of the force of heart contraction by neuronal epinephrine"
http://purl.obolibrary.org/obo/GO_0003088 "positive regulation of the force of heart contraction by circulating epinephrine"
http://purl.obolibrary.org/obo/GO_0001997 "positive regulation of the force of heart contraction by epinephrine-norepinephrine"
http://purl.obolibrary.org/obo/GO_0003090 "positive regulation of the force of heart contraction by neuronal epinephrine-norepinephrine"
http://purl.obolibrary.org/obo/GO_0003089 "positive regulation of the force of heart contraction by circulating epinephrine-norepinephrine"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment