SPARQL example query
28_Select_all_reactions_with_Xrefs: Select all reactions with cross-references
PREFIX rh:<http://rdf.rhea-db.org/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?reaction WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:directionalReaction ?directionalReaction . ?reaction rh:bidirectionalReaction ?bidirectionalReaction . OPTIONAL { ?directionalReaction rdfs:seeAlso ?xref . } OPTIONAL { ?bidirectionalReaction rdfs:seeAlso ?xref . } FILTER (BOUND(?xref)) } ORDER BY ?reactionUse29_Select_all_approved_reactions_linked_to_PMID_X: Select all approved reactions linked to PMID:2460092
PREFIX rh:<http://rdf.rhea-db.org/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX pubmed:<http://rdf.ncbi.nlm.nih.gov/pubmed/> SELECT ?reaction ?reactionEquation WHERE { BIND(pubmed:2460092 AS ?cit) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?reactionEquation . ?reaction rh:citation ?cit . } ORDER BY ?reactionUse30_Select_all_approved_reactions_annotated_with_a_given_Pubmed_ID: Select all approved reactions annotated with a given Pubmed ID (2460092, and show the pubmed id in result as text, using strafter and BIND)
PREFIX rh:<http://rdf.rhea-db.org/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX pubmed:<http://rdf.ncbi.nlm.nih.gov/pubmed/> SELECT ?reaction ?pubMedID ?reactionEquation WHERE { BIND(pubmed:2460092 AS ?cit) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?reactionEquation . ?reaction rh:citation ?cit . BIND(strafter(str(?cit), str(pubmed:)) AS ?pubMedID ) }Use31_Select_the_average_number_of_citation_of_reactions_that_have_at_least_one_citation: Select the average number of citation of reactions that have at least one citation
PREFIX rh: <http://rdf.rhea-db.org/> SELECT (AVG(?linksToPubmedPerReaction) AS ?avgLinksToPubmedPerReaction) WHERE { SELECT ?reaction (COUNT(DISTINCT ?citation) AS ?linksToPubmedPerReaction) WHERE { ?reaction rh:citation ?citation . } GROUP BY ?reaction ORDER BY DESC(?linksToPubmedPerReaction) }Use32_Select_the_distribution_of_reactions_according_to_their_status: Select the distribution of reactions according to their status
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?status (count(?reaction) as ?reactionCount) WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status ?status . } GROUP BY ?statusUse33_Select_all_approved_transport_reactions: Select all approved transport reactions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction ?reactionEquation WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?reactionEquation . ?reaction rh:isTransport true } ORDER BY ?reactionUse34_Select_all_cross-references_for_a_given_reaction: Select all cross-references for a given reaction (RHEA:11680)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction ?xref WHERE { BIND (rh:11680 AS ?reaction) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:directionalReaction ?directionalReaction . OPTIONAL { ?directionalReaction rdfs:seeAlso ?xref . } ?reaction rh:bidirectionalReaction ?bidirectionalReaction . OPTIONAL { ?bidirectionalReaction rdfs:seeAlso ?xref . } }Use35_Select_all_cross-references_Kegg_MetaCyc_Macie_for_a_given_reaction: Select all cross-references (to KEGG, MetaCyc, Macie, ...) for a given reaction (RHEA:11932)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction ?xref WHERE { BIND (rh:11932 AS ?reaction) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:directionalReaction ?directionalReaction . OPTIONAL { ?directionalReaction rdfs:seeAlso ?xref . } ?reaction rh:bidirectionalReaction ?bidirectionalReaction . OPTIONAL { ?bidirectionalReaction rdfs:seeAlso ?xref . } }Use36_Select_the_number_of_reactions_with_cross-references_to_KEGG_resource: Select the number of reactions with cross-references to KEGG resource (via bidirectional rhea reactions)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> PREFIX kegg: <http://identifiers.org/kegg.reaction/> SELECT (count(?reaction) as ?reactionCount) WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:bidirectionalReaction ?bidirectionalReaction . ?bidirectionalReaction rdfs:seeAlso ?xref . FILTER (regex(?xref, str(kegg:))) }Use37_Select_the_number_of_reactions_with_cross-references_to_MetaCyc: Select the number of reactions with cross-references to MetaCyc
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> PREFIX CHEBI:<http://purl.obolibrary.org/obo/CHEBI_> PREFIX up:<http://purl.uniprot.org/core/> PREFIX keywords:<http://purl.uniprot.org/keywords/> PREFIX taxon:<http://purl.uniprot.org/taxonomy/> SELECT (count(distinct ?rhea) as ?rheaMetacycCount) (count(distinct ?xref) as ?metacycRheaCount) (count(?rhea) as ?rheaMetacycXrefCount) WHERE { ?rhea rdfs:subClassOf rh:Reaction . ?rhea rh:status rh:Approved . ?rhea rh:directionalReaction ?directionalReaction . ?rhea rh:bidirectionalReaction ?bidirectionalReaction . { ?directionalReaction rdfs:seeAlso ?xref . FILTER regex(str(?xref), "METACYC") . } UNION { ?bidirectionalReaction rdfs:seeAlso ?xref . FILTER regex(str(?xref), "METACYC") . } UNION { ?rhea rdfs:seeAlso ?xref . FILTER regex(str(?xref), "METACYC") . } }Use39_Select_all_reactions_annotated_with_a_given_Pubmed_ID: Select all reactions annotated with a given Pubmed ID
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> PREFIX pubmed:<http://rdf.ncbi.nlm.nih.gov/pubmed/> SELECT ?reaction ?pubMedID ?reactionEquation WHERE { BIND(pubmed:2460092 AS ?pubMedID) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?reactionEquation . ?reaction rh:citation ?pubMedID . }Use40_Select_all_citations_of_a_given_reaction: Select all citations of a given reaction
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> PREFIX pubmed:<http://rdf.ncbi.nlm.nih.gov/pubmed/> SELECT ?reaction ?citation WHERE { BIND(rh:11680 AS ?reaction) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:citation ?citation . }Use41_Select_all_reactions_with_citations_display_the_number_of_citations_and_order_by_reaction_ID: Select all reactions with citations, display the number of citations and ORDER BY reaction ID
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction (COUNT(DISTINCT ?citation) AS ?countPubmedPerReaction) WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:citation ?citation . } GROUP BY ?reaction ORDER BY DESC (COUNT(DISTINCT ?citation))Use42_Select_the_average_number_of_citation_of_reactions_that_have_at_least_one_citation: Select the average number of citation of reactions that have at least one citation
PREFIX rh: <http://rdf.rhea-db.org/> SELECT (AVG(?linksToPubmedPerReaction) AS ?avgLinksToPubmedPerReaction) WHERE { SELECT ?reaction (COUNT(DISTINCT ?citation) AS ?linksToPubmedPerReaction) WHERE { ?reaction rh:citation ?citation . } GROUP BY ?reaction ORDER BY DESC(?linksToPubmedPerReaction) }Use43_Select_the_child_reactions_of_a_given_reaction_in_the_Rhea_hierarchy: Select the child reaction(s) of a given reaction (RHEA:11628) in the Rhea hierarchy, (using rdfs:subClassOf)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction ?equation ?childReaction ?childEquation WHERE { BIND (rh:11628 AS ?reaction) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?equation . ?childReaction rdfs:subClassOf rh:Reaction . ?childReaction rh:status rh:Approved . ?childReaction rdfs:subClassOf ?reaction . ?childReaction rh:equation ?childEquation . }Use44_Select_the_descendant_reactions_of_a_given_reaction_in_the_Rhea_hierarchy: Select the descendant reaction(s) of a given reaction (RHEA:11628) in the Rhea hierarchy, (using rdfs:subClassOf+)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction ?equation ?descendantReaction ?descendantEquation WHERE { BIND(rh:11628 AS ?reaction) ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?equation . ?descendantReaction rdfs:subClassOf rh:Reaction . ?descendantReaction rh:status rh:Approved . ?descendantReaction rdfs:subClassOf+ ?reaction . ?descendantReaction rh:equation ?descendantEquation . }Use45_Select_the_parent_reactions_of_a_given_reaction: Select the parent reaction(s) of a given reaction
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reactionChild ?childEquation ?reactionParent ?parentEquation WHERE { BIND (rh:39155 AS ?reactionChild) ?reactionChild rdfs:subClassOf rh:Reaction . ?reactionChild rh:status rh:Approved . ?reactionChild rh:equation ?childEquation . ?reactionParent rdfs:subClassOf rh:Reaction . ?reactionParent rh:status rh:Approved . ?reactionParent rh:equation ?parentEquation . ?reactionChild rdfs:subClassOf ?reactionParent . }Use46_Number_of_IsA_relationships: Number of IsA relationships, distinct child reactions and distinct parent reactions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT (COUNT(?reactionChild) AS ?isARelationCount) (COUNT(distinct ?reactionChild) AS ?uniqueReactionChildCount) (COUNT(distinct ?reactionParent) AS ?uniqueReactionParentCount) WHERE { ?reactionChild rdfs:subClassOf rh:Reaction . ?reactionChild rh:status rh:Approved . ?reactionParent rdfs:subClassOf rh:Reaction . ?reactionParent rh:status rh:Approved . ?reactionChild rdfs:subClassOf ?reactionParent . }Use47_Select_all_children_reactions_and_give_the_number_of_parent_reactions: Select all children reactions and give the number of parent reactions.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT (count(?reactionChild) as ?isARelationCount) (count(distinct ?reactionChild) as ?uniqueReactionChildCount) (count(distinct ?reactionParent) as ?uniqueReactionParentCount) WHERE { ?reactionChild rdfs:subClassOf rh:Reaction . ?reactionChild rh:status rh:Approved . ?reactionParent rdfs:subClassOf rh:Reaction . ?reactionParent rh:status rh:Approved . ?reactionChild rdfs:subClassOf ?reactionParent . }Use48_Select_all_reactions_with_at_least_one_parent_reaction_and_give_the_number_ancestor_reactions: Select all reactions with at least one parent reaction and give the number ancestor reactions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> SELECT ?reaction (count(?parentReaction) as ?parentReactionCount) WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rdfs:subClassOf ?parentReaction . ?parentReaction rdfs:subClassOf rh:Reaction . ?parentReaction rh:status rh:Approved . } GROUP BY ?reaction ORDER BY DESC (?parentReactionCount) ?reactionUse49_Select_parent_reactions_give_the_number_of_child_and_descendant_reactions: Select parent reactions, give the number of child and descendant reactions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction (count(?ancestorReaction) as ?ancestorReactionCount) WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?ancestorReaction rdfs:subClassOf rh:Reaction . ?ancestorReaction rh:status rh:Approved . ?reaction rdfs:subClassOf+ ?ancestorReaction . } GROUP BY ?reaction ORDER BY (count(?ancestorReaction))Use50_Number_of_reactions_that_have_parent_and_child_reactions: Number of reactions that have parent and child reactions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh:<http://rdf.rhea-db.org/> SELECT ?reaction (count(distinct ?reactionChild) as ?reactionChildCount) (count(distinct ?reactionDescendant) as ?reactionDescendantCount) ?equation WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?reaction rh:equation ?equation . ?reactionChild rdfs:subClassOf rh:Reaction . ?reactionChild rh:status rh:Approved . ?reactionDescendant rdfs:subClassOf rh:Reaction . ?reactionDescendant rh:status rh:Approved . ?reaction ^rdfs:subClassOf ?reactionChild . ?reaction ^rdfs:subClassOf+ ?reactionDescendant . } GROUP BY ?reaction ?equation ORDER BY DESC (count(?reactionChild))Use51_Select_all_reactions_that_have_parents_and_children_reactions: Select all reactions that have parents and children reactions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> SELECT (count(distinct ?reaction) as ?reactionCount) WHERE { ?reaction rdfs:subClassOf rh:Reaction . ?reaction rh:status rh:Approved . ?childReaction rdfs:subClassOf rh:Reaction . ?childReaction rh:status rh:Approved . ?parentReaction rdfs:subClassOf rh:Reaction . ?parentReaction rh:status rh:Approved . ?reaction rdfs:subClassOf ?parentReaction . ?reaction ^rdfs:subClassOf ?childReaction . }Use52_List_all_small_molecules: List all small molecules
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> SELECT ?compound ?compoundName WHERE { ?compound rdfs:subClassOf rh:SmallMolecule . ?compound rh:name ?compoundName } ORDER BY (?compound)Use53_List_all_polymers: List all polymers
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> SELECT ?compound ?compoundName WHERE { ?compound rdfs:subClassOf rh:Polymer . ?compound rh:name ?compoundName } ORDER BY (?compound)Use54_List_all_generic_compounds: List all generic compounds
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> SELECT ?compound ?compoundName WHERE { ?compound rdfs:subClassOf rh:Polymer . ?compound rh:name ?compoundName . } ORDER BY (?compound)Use